假设我们有一个文件test.txt
,my_directory
我想将其重命名为yeah.txt
. 有没有办法zsh
(甚至只是bash
知道)避免重新输入my_directory
?
我发现以下内容有点长:
mv my_directory/test.txt my_directory/yeah.txt
谢谢。
我会用大括号扩展来做到这一点:
mv my_directory/{test,yeah}.txt
我已copy-prev-shell-word
分配给^P
% cp my_directory/test.txt [^P] # expands to....
% cp my_directory/test.txt my_directory/test.txt
然后我只是手动编辑最后一个参数。对我来说,这是一个比大括号扩展更好的解决方案,但我认为这只是一种偏好。
如果有兴趣,您应该查看以下函数之一 ( man zshzle
):
copy-prev-word (ESC-^_) (unbound) (unbound)
Duplicate the word to the left of the cursor.
copy-prev-shell-word
Like copy-prev-word, but the word is found by using shell parsing,
whereas copy-prev-word looks for blanks. This makes a difference when the
word is quoted and contains spaces.
我用它来绑定函数bindkey -M emacs "^p" copy-prev-shell-word