From e339c120c32896995bf25c528ac335582a0ea3f9 Mon Sep 17 00:00:00 2001 From: druckdev <63563978+druckdev@users.noreply.github.com> Date: Tue, 6 Oct 2020 03:02:55 +0200 Subject: [PATCH] zsh:keys: Rework rationalize_dots/_expandDots Restart from different implementation, since nicoulaj's dotfile repo seems to be offline and I prefer majutsushi's cleaner version. Add a slash after the dots since normally I continue on typing the path and it does not hurt if I don't. --- .config/zsh/plugins/keys.zsh | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/.config/zsh/plugins/keys.zsh b/.config/zsh/plugins/keys.zsh index 0cd2c18..7b1b14a 100644 --- a/.config/zsh/plugins/keys.zsh +++ b/.config/zsh/plugins/keys.zsh @@ -61,28 +61,25 @@ bindkey '^H' backward-kill-word # ctrl-backspace bindkey '^[[3;5~' kill-word # ctrl-delete bindkey "$terminfo[kmous]" kill-word # ctrl-delete -## From https://github.com/nicoulaj/dotfiles/blob/1c7dd1b621bc8bae895bafc438562482ea245d7e/.config/zsh/functions/widgets/rationalize-dots -function _expandDots { - #[[ $LBUFFER = *.. ]] && LBUFFER+=/.. || LBUFFER+=. - setopt localoptions nonomatch - local MATCH dir split - split=(${(z)LBUFFER}) - (( $#split > 1 )) && dir=$split[-1] || dir=$split - if [[ $LBUFFER =~ '(^|/| | |'$'\n''|\||;|&)\.\.$' ]]; then - LBUFFER+=/ - zle self-insert - zle self-insert - [[ -e $dir ]] && zle -M "${dir:a:h}" - elif [[ $LBUFFER[-1] == '.' ]]; then - zle self-insert - [[ -e $dir ]] && zle -M "${dir:a:h}" +# Modified version (end with a trailing slash) of: +# https://github.com/majutsushi/etc/blob/1d8a5aa28/zsh/zsh/func/rationalize-dots +function rationalize_dots { + # Rationalize dots at BOL or after a space or slash. + if [[ "$LBUFFER" =~ "(^|[ /])\.\./$" ]]; then + LBUFFER+=../ + elif [[ "$LBUFFER" =~ "(^|[ /])\.$" ]]; then + LBUFFER+=./ else - zle self-insert + LBUFFER+=. + return fi + + # Print currently typed path as absolute path with "collapsed"/reversed + # filename expansion. + zle -M "${(D)${(z)LBUFFER}[-1]:a}" } -#autoload _expandDots -zle -N _expandDots -bindkey . _expandDots +zle -N rationalize_dots +bindkey . rationalize_dots function ls-on-enter { # Execute `ls` when enter is pressed without a command entered.