zsh:keys:cmd-on-enter: Cycle between ls & gs too

This commit is contained in:
2021-03-08 01:10:09 +01:00
parent f0ebab3ca2
commit 93225e2d66

View File

@@ -98,17 +98,28 @@ function rationalize_dots {
zle -N rationalize_dots zle -N rationalize_dots
bindkey . rationalize_dots bindkey . rationalize_dots
function ls-on-enter { function cmd-on-enter {
# Execute `ls` when enter is pressed without a command entered. zle -M "$CMD_ON_ENTER"
[[ -n "$BUFFER" ]] || BUFFER=ls if [[ -z $BUFFER ]]; then
# Overwrite BUFFER and default to ls
BUFFER="${CMD_ON_ENTER:=ls}"
# Cycle through ls and git status
case "$CMD_ON_ENTER" in
ls)
! git rev-parse &>/dev/null || CMD_ON_ENTER='gs';;
gs)
CMD_ON_ENTER='ls';;
esac
fi
zle accept-line zle accept-line
# See fzf-hist below # See fzf-hist below
FZF_HIST_WENT_UP= FZF_HIST_WENT_UP=
} }
zle -N ls-on-enter zle -N cmd-on-enter
bindkey "^M" ls-on-enter bindkey "^M" cmd-on-enter
ZSH_AUTOSUGGEST_CLEAR_WIDGETS+=(ls-on-enter) ZSH_AUTOSUGGEST_CLEAR_WIDGETS+=(cmd-on-enter)
# "Scroll" through history if buffer was empty but use it as query for fzf over # "Scroll" through history if buffer was empty but use it as query for fzf over
# command line history if not (similar to substring-search but with fzf) # command line history if not (similar to substring-search but with fzf)