-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Various bash improvements #3448
Conversation
btw: There's also one further difference in the 3: Line 111 in 0080990
and Line 132 in 0080990
use:
while: Line 116 in 0080990
uses
So no extra leading |
@junegunn … any ideas on these? :-D |
When just checking whether a function is already defined or not, it’s not necessary to print out it’s definition (should it be defined). bash’s `declare` provides the `-F`-option (which implies `-f`), which should give a minor performance improvement Signed-off-by: Christoph Anton Mitterer <[email protected]>
Added another minor improvement. |
Yes, because macOS ships with bash 3. https://apple.stackexchange.com/a/208405/125495 The code is short and it has been stable for quite a while. And considering that I have no plans to extend the feature set, I don't see much benefit in pruning a few lines of code and breaking backward compatibility for some, albeit small, number of users. |
827ac13
to
cc681f0
Compare
Funny... did you ever find out, why they behave different there?
Thx.
Sigh ^^... but okay for me. I've rebased my branch onto current master and dropped the now obsolete commit that touched command substitution. Could you please review the remaining commits? :-) |
Yes, if you put
Will do. I'm kind of busy with other stuff now. |
shell/key-bindings.bash
Outdated
# ALT-C - cd into the selected directory | ||
bind -m emacs-standard '"\ec": " \C-b\C-k \C-u`__fzf_cd__`\e\C-e\er\C-m\C-y\C-h\e \C-y\ey\C-x\C-x\C-d"' | ||
bind -m vi-command '"\ec": "\C-z\ec\C-z"' | ||
bind -m vi-insert '"\ec": "\C-z\ec\C-z"' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We decided to keep the pre-bash4 implementation for ALT-C because of a critical UX issue. See #2674.
Also, your version doesn't work and the test cases are failing. Have you tested it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooops... I hadn't noticed that this didn’t change the CWD, and worked on other branches since then and not looked back.
As for the tests, I've seen failures and flaky tests even when working on master
, see #3449 (comment).
Not sure what I'm doing wrong there.
Okay, using bind -x
seems indeed not so easy. redraw-current-line
only re-draws the line, but does not re-evaluate PS1
, so while the CWD has in fact changed, the old one is still shown in the prompt.
Anything that causes enter to be printed wouldn’t be much better than the current solution (and cause the current line to be executed.
While searching for solutions, I stumbled over ${PS1@P}
- not sure if that could somehow be used to re-draw the prompt manually.
Some people suggested sending SIGWINCH
to the shell, but that didn’t work for me.
https://superuser.com/a/1662149 worked for me, but it would also require us override more bindings, and needs more shell vars. Same with https://stackoverflow.com/a/40426702.
The current implementation still seems fragile to me (in case anyone has chanced the meaning of any of those keybindings, which I for example actually have for C-h
).
Maybe we could somehow save the current keybindings, remove them (to be sure defaults are used), and restore them afters wards?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@junegunn, I've removed all commits except the minor fa6b43f.
As for switching Alt-C
to use bind -x
:
I still think there is some value in doing this, namely to get it working for any systems where the user has reassigned the keyseqs you use in:
Lines 132 to 134 in 4fdc082
bind -m emacs-standard '"\ec": " \C-b\C-k \C-u`__fzf_cd__`\e\C-e\er\C-m\C-y\C-h\e \C-y\ey\C-x\C-x\C-d"' | |
bind -m vi-command '"\ec": "\C-z\ec\C-z"' | |
bind -m vi-insert '"\ec": "\C-z\ec\C-z"' |
and also to avoid having to set up helper bindings as in:
Lines 102 to 107 in 4fdc082
# Required to refresh the prompt after fzf | |
bind -m emacs-standard '"\er": redraw-current-line' | |
bind -m vi-command '"\C-z": emacs-editing-mode' | |
bind -m vi-insert '"\C-z": emacs-editing-mode' | |
bind -m emacs-standard '"\C-z": vi-editing-mode' |
which may overwrite the user’s own bindings.
I think I may have found a working solution, at least for bash versions that already have bind -x
.
It's not yet perfect and I'm not enough of a bash/readline expert to determine whether it really works properly and in all cases, so I wrote mails to help-bash, asking for their advice:
- https://lists.gnu.org/archive/html/help-bash/2023-10/msg00000.html
- https://lists.gnu.org/archive/html/help-bash/2023-10/msg00001.html
if you're curious, you can already look there, how I think we could perhaps do it.
At least this time I actually did some testing O:-) ... and it looked good, except for the open points mentioned in the mail to help-bash.
I think we should handle any possible improvements to Alt-C
in a separate issue, so if you're fine with the remaining minor commit of this PR, please merge it.
At least the tests seem to ran through this time.
cc681f0
to
fa6b43f
Compare
Merged, thanks.
Ideally yes, but we need to evaluate whether the added complexity is really worth it. Users can make all sorts of unconventional choices and our bindings are not immune to them. But I have maintained this code for many years, yet no one has ever complained that ALT-C does not work because of their creative bindings. I think that says something. |
I've opened #3461
Well, I for example, have already assigned Seriously, I think the added complexity is still manageable, and IMO we should at least try our best to avoid extreme cases, where accidental execution of a binding who was assigned a non-default action may cause damage. It doesn't immediately have to be the: |
Oh and thanks for merging. |
Can you tell me what you are binding it to, and how it makes ALT-C behave? |
As far as I can see, the effect is by coincidence the same as the example in the end of the main post of #3461, i.e. if I have a readline buffer with |
Again... someone should thoroughly double check these, especially I have no
bash
versions from the primordial times of the universe around. ;-)Speaking of which... does it really make sense to keep code for
bash
versions < 4? I mean bash 4 was something like early 2009.I'd just drop all code for those ancient versions, especially as all the use of
\C-b\C-k
, etc. may anyway easily break, if a user has re-assigned them to something else.