我们在test.txt
中有一个文件my_directory
,我想将其重命名为yeah.txt
。
是否有办法zsh
(甚至只是bash
,只是知道)以避免重新输入my_directory
?
我发现以下内容有点长:
mv my_directory/test.txt my_directory/yeah.txt
感谢。
答案 0 :(得分:4)
我会用大括号扩展来做这件事:
mv my_directory/{test,yeah}.txt
答案 1 :(得分:2)
我已将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