summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2020-10-03 14:48:57 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2020-10-03 14:55:02 +0900
commit9dfca77c36d15df321e7f13b0afc72af77a03cd5 (patch)
tree7ef901ac4c134c0519a7dffe64752e422e89d2c8
parent82c4af29028d6035832cf3ab58bafb4fd9605f60 (diff)
[zsh] Keep current $BUFFER on ALT-C
Ideally, we could only use `print -sr` to update the command history. However, the "cd" command by ALT-C is added to the history only after we finalize the current command by pressing an additional enter key. i.e. The cd command from ALT-C is not visible when you hit Up arrow. But it appears once you hit enter key. So when the current buffer is empty, we use `zle accept-line` so that the command history is immediately updated. Close #2200
-rw-r--r--shell/key-bindings.zsh11
1 files changed, 8 insertions, 3 deletions
diff --git a/shell/key-bindings.zsh b/shell/key-bindings.zsh
index 2433d988..63306142 100644
--- a/shell/key-bindings.zsh
+++ b/shell/key-bindings.zsh
@@ -87,10 +87,15 @@ fzf-cd-widget() {
zle redisplay
return 0
fi
- BUFFER="cd ${(q)dir}"
- unset dir # ensure this doesn't end up appearing in prompt expansion
- zle accept-line
+ if [ -z "$BUFFER" ]; then
+ BUFFER="cd ${(q)dir}"
+ zle accept-line
+ else
+ print -sr "cd ${(q)dir}"
+ cd "$dir"
+ fi
local ret=$?
+ unset dir # ensure this doesn't end up appearing in prompt expansion
zle fzf-redraw-prompt
return $ret
}