zsh:keys:ratio_dots: Fix preview of first word
Previously the path preview misbehaved when typing dots on the first shell word (e.g. executing a script in a parent directory). This happened as the `(z)` parameter expansion flag does not expand to an array rather a scalar. Because of that, `[-1]` returns the last character. Work around this issue by prepending LBUFFER with a dummy word, so that it always contains at least 2 words.
This commit is contained in:
@@ -100,9 +100,13 @@ function rationalize_dots {
|
|||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# NOTE: This is a hack to fix the (z) expansion flag if the path is the only
|
||||||
|
# word in LBUFFER, as then [:-1] treats the expansion as a scalar and
|
||||||
|
# returns the last character (i.e. always `/`).
|
||||||
|
local lbuffer_words="x $LBUFFER"
|
||||||
# Print currently typed path as absolute path with "collapsed"/reversed
|
# Print currently typed path as absolute path with "collapsed"/reversed
|
||||||
# filename expansion.
|
# filename expansion.
|
||||||
zle -M "${(D)${(z)LBUFFER}[-1]:a}"
|
zle -M "${(D)${(z)lbuffer_words}[-1]:a}"
|
||||||
}
|
}
|
||||||
zle -N rationalize_dots
|
zle -N rationalize_dots
|
||||||
bindkey . rationalize_dots
|
bindkey . rationalize_dots
|
||||||
|
|||||||
Reference in New Issue
Block a user