Restrict atuin to 4th up key

This commit is contained in:
Tobias Reisinger 2024-02-28 04:16:57 +01:00
parent b958ac678d
commit a705b3d1ff
Signed by: serguzim
GPG key ID: 13AD60C237A28DFE
2 changed files with 43 additions and 1 deletions

View file

@ -80,6 +80,7 @@ fpath=(
# Example format: plugins=(rails git textmate ruby lighthouse) # Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup. # Add wisely, as too many plugins slow down shell startup.
plugins=( plugins=(
'atuin'
'colored-man-pages' 'colored-man-pages'
'docker' 'docker'
'docker-compose' 'docker-compose'
@ -117,6 +118,6 @@ source source-remote-file \
"https://raw.githubusercontent.com/dracula/zsh-syntax-highlighting/master/zsh-syntax-highlighting.sh" \ "https://raw.githubusercontent.com/dracula/zsh-syntax-highlighting/master/zsh-syntax-highlighting.sh" \
"dracula-syntax-highlighting" "dracula-syntax-highlighting"
[ -x "$(command -v atuin)" ] && eval "$(atuin init zsh)" [ -x "$(command -v atuin)" ] && eval "$(atuin init zsh --disable-up-arrow --disable-ctrl-r)"
[ -x "$(command -v direnv)" ] && eval "$(direnv hook zsh)" [ -x "$(command -v direnv)" ] && eval "$(direnv hook zsh)"
[ -x "$(command -v starship)" ] && eval "$(starship init zsh)" [ -x "$(command -v starship)" ] && eval "$(starship init zsh)"

View file

@ -0,0 +1,41 @@
autoload -U add-zsh-hook
# Reset up count on new command
ATUIN_UP_COUNT=0
_atuin_reset_up_count() {
ATUIN_UP_COUNT=0
}
add-zsh-hook precmd _atuin_reset_up_count
# Define functions
_atuin_up_cond() { # first arg is mode (viins or vicmd)
ATUIN_UP_COUNT=$(( ATUIN_UP_COUNT + 1 ))
if [ $ATUIN_UP_COUNT -gt 3 ]
then
zle "atuin-up-search$1"
else
zle up-line-or-beginning-search
fi
}
_atuin_up_cond_vicmd() {
_atuin_up_cond "-vicmd"
}
_atuin_up_cond_viins() {
_atuin_up_cond "-viins"
}
# Add functions to zle
zle -N atuin-up-cond _atuin_up_cond
zle -N atuin-up-cond-vicmd _atuin_up_cond_vicmd
zle -N atuin-up-cond-viins _atuin_up_cond_viins
# Bind keys
bindkey -M emacs '^[[A' atuin-up-cond
bindkey -M vicmd '^[[A' atuin-up-cond-vicmd
bindkey -M viins '^[[A' atuin-up-cond-viins
bindkey -M emacs '^[OA' atuin-up-cond
bindkey -M vicmd '^[OA' atuin-up-cond-vicmd
bindkey -M viins '^[OA' atuin-up-cond-viins
bindkey -M vicmd 'k' atuin-up-cond-vicmd