gpt4 book ai didi

bash - zsh 或 bash 可以扩展引用目录的历史表达式吗?

转载 作者:行者123 更新时间:2023-11-29 09:49:22 24 4
gpt4 key购买 nike

例如,假设我刚刚复制了一些东西:

mv foo_file.txt ~/to/some/long/path/that/i/do/not/want/to/retype

我想像这样使用历史替换:

mv bar_file.txt !!:2

令我惊讶的是,当我点击 [tab] 时,zsh 没有为我扩展 !!:2。在更复杂的对历史论证的引用中,我可能真的希望在按下回车键之前进行扩展,这样我就可以确定我引用了正确的论证。有什么办法让它这样做吗? (我希望这是默认行为。这是默认行为吗,我不知何故无意中禁用或破坏了?)

如果 zsh 做不到,bash 可以吗?

更新:如果 zsh 引用文件而非目录,zsh 将扩展历史表达式:

mv foo_file.txt foo_bar_file.txt
mv bar_file.txt !!:2[TAB]

如果它只是一个任意字符串,它将扩展它:

echo one two three four
echo !!:1[TAB]

但如果您尝试将某些内容移动到目录中则不行。看起来越来越像这一定是一个错误。

最佳答案

我在 cygwin 中使用 zsh:

$ zsh --version
zsh 4.3.12 (i686-pc-cygwin)

$ setopt
interactive
monitor
shinstdin
zle

我刚刚尝试了以下方法:

$ touch foo_file.txt bar_file.txt
$ mkdir -p ~/to/some/long/path/that/i/do/not/want/to/retype
$ mv foo_file.txt ~/to/some/long/path/that/i/do/not/want/to/retype

然后我尝试了上面提到的制表符补全:

$ mv bar_file.txt !!:2[TAB]

它工作正常,最后一个参数被扩展如下:

$ mv bar_file.txt ~/to/some/long/path/that/i/do/not/want/to/retype

关于bash - zsh 或 bash 可以扩展引用目录的历史表达式吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7048327/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com