[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Feature request for PS0
From: |
Koichi Murase |
Subject: |
Re: Feature request for PS0 |
Date: |
Tue, 8 Feb 2022 16:53:26 +0900 |
2022年2月8日(火) 11:44 Chet Ramey <chet.ramey@case.edu>:
> On 2/7/22 6:58 PM, Koichi Murase wrote:
> > 2022年2月8日(火) 4:14 Akbarkhon Variskhanov <akbarkhon.variskhanov@gmail.com>:
> >> of it, so that the whole command line looks like this after having been
> >> read:
> >> ~ echo "Hello, Wo # not finished typing
> >> ~ echo "Hello, World!" # finished typing, pressing Enter
> >> 21:39:44 ~ echo "Hello, World!"
> >> Hello, World!
> >
> > Maybe this is just another hack that has some corner cases, but how about
> > this?
> >
> > bind -x '"\xC0\a":printf "%(%T)T "'
> > bind '"\xC0\r":accept-line'
> > bind '"\r":"\xC0\a\xC0\r"'
Let me leave an improved version here. I think we can improve it by
setting READLINE_POINT=${#READLINE_LINE} in the keybinding.
In addition to \r and \n, \C-o and \C-x\C-e can also be overridden for
completeness. However, I now noticed that the bindable function
`vi_edit_and_execute_command (bashline.c:1017)', which "v" is bound to
by default in vi-command keymap, is not given a name and thus cannot
be directly bound by the user. Instead, the user needs to properly set
`EDITOR' or `VISUAL' and use the bindable function
`edit-and-execute-command'.
The most comprehensive version at the moment would be the following:
----------
_rl_ps1_final() {
printf '%(%T)T '
# adjust the cursor position to avoid redundant empty lines in corner cases
((BASH_VERSINFO[0] >= 5)) || local LC_ALL= LC_CTYPE=C
READLINE_POINT=${#READLINE_LINE}
}
_rl_ps1_final_initialize() {
local keymap
for keymap in emacs vi-insert vi-command; do
bind -m "$keymap" -x '"\xC0\a": _rl_ps1_final'
# \r (RET, C-m), \n (C-j)
bind -m "$keymap" '"\xC0\r": accept-line'
bind -m "$keymap" '"\r": "\xC0\a\xC0\r"'
bind -m "$keymap" '"\n":"\xC0\a\xC0\r"'
done
# C-o (emacs)
bind -m emacs '"\xC0\C-o": operate-and-get-next'
bind -m emacs '"\C-o": "\xC0\a\xC0\C-o"'
# C-x C-e (emacs)
bind -m emacs '"\xC0\C-e": edit-and-execute-command'
bind -m emacs '"\C-x\C-e": "\xC0\a\xC0\C-e"'
# v (vi-command) ???how to bind to `vi_edit_and_execute_command'???
# Note: One needs to properly set up VISUAL or EDITOR to "vi", etc.
bind -m vi-command '"\xC0\C-e": edit-and-execute-command'
bind -m vi-command '"\C-x\C-e": "\xC0\a\xC0\C-e"'
}
_rl_ps1_final_initialize
unset -f _rl_ps1_final_initialize
----------
Koichi