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.
This commit is contained in:
@@ -61,28 +61,25 @@ bindkey '^H' backward-kill-word # ctrl-backspace
|
|||||||
bindkey '^[[3;5~' kill-word # ctrl-delete
|
bindkey '^[[3;5~' kill-word # ctrl-delete
|
||||||
bindkey "$terminfo[kmous]" 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
|
# Modified version (end with a trailing slash) of:
|
||||||
function _expandDots {
|
# https://github.com/majutsushi/etc/blob/1d8a5aa28/zsh/zsh/func/rationalize-dots
|
||||||
#[[ $LBUFFER = *.. ]] && LBUFFER+=/.. || LBUFFER+=.
|
function rationalize_dots {
|
||||||
setopt localoptions nonomatch
|
# Rationalize dots at BOL or after a space or slash.
|
||||||
local MATCH dir split
|
if [[ "$LBUFFER" =~ "(^|[ /])\.\./$" ]]; then
|
||||||
split=(${(z)LBUFFER})
|
LBUFFER+=../
|
||||||
(( $#split > 1 )) && dir=$split[-1] || dir=$split
|
elif [[ "$LBUFFER" =~ "(^|[ /])\.$" ]]; then
|
||||||
if [[ $LBUFFER =~ '(^|/| | |'$'\n''|\||;|&)\.\.$' ]]; then
|
LBUFFER+=./
|
||||||
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}"
|
|
||||||
else
|
else
|
||||||
zle self-insert
|
LBUFFER+=.
|
||||||
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Print currently typed path as absolute path with "collapsed"/reversed
|
||||||
|
# filename expansion.
|
||||||
|
zle -M "${(D)${(z)LBUFFER}[-1]:a}"
|
||||||
}
|
}
|
||||||
#autoload _expandDots
|
zle -N rationalize_dots
|
||||||
zle -N _expandDots
|
bindkey . rationalize_dots
|
||||||
bindkey . _expandDots
|
|
||||||
|
|
||||||
function ls-on-enter {
|
function ls-on-enter {
|
||||||
# Execute `ls` when enter is pressed without a command entered.
|
# Execute `ls` when enter is pressed without a command entered.
|
||||||
|
|||||||
Reference in New Issue
Block a user