首选报价与转义ZSH完成

ZSH是一个很棒的外壳,所有为此编写的出色的自动完成脚本使学习和使用起来轻而易举。

但是,我不喜欢自动填充功能将使用foo\ bar而不是'foo bar'

有什么办法可以改变这种行为?

cahdj123 回答:首选报价与转义ZSH完成

更多评论,但需要更好的格式,所以这里是

我相信这在ZLE中应该是可能的,但是我不知道是否已经有用于此目的的代码,而且自从我上次编写较低级别的ZLE以来已经有一段时间了,所以我没有时间来整理然后自己编写代码...

但是,这已经可以使用库存功能了。我说的是quote-and-complete-word

# This widget uses the completion system to double-quote the current word
# if it is not already quoted,then attempts to complete normally.  If the
# normal completion fails,the quotes are removed again.
#
# To use it:
#   autoload -Uz quote-and-complete-word
#   zle -N quote-and-complete-word
#   bindkey '\t' quote-and-complete-word

由于它无条件地引用了单词,因此将tab绑定到它显然不是一个好主意,但是您可以绑定其他内容,例如alt tab:

autoload -Uz quote-and-complete-word
zle -N quote-and-complete-word
bindkey '^[^I' quote-and-complete-word

(或将^[[Z用于移位标签。)

当需要完成引用的内容时,请按Alt键。请注意,完成后,光标将位于引号内,您需要向右移动一个字符以将引号留在后面,因此不幸的是,即使作为变体,它也不理想。

本文链接:https://www.f2er.com/3101041.html

大家都在问