1

假设我们有一个文件test.txtmy_directory我想将其重命名为yeah.txt. 有没有办法zsh(甚至只是bash知道)避免重新输入my_directory

我发现以下内容有点长:

mv my_directory/test.txt my_directory/yeah.txt

谢谢。

4

2 回答 2

4

我会用大括号扩展来做到这一点:

mv my_directory/{test,yeah}.txt
于 2013-05-23T05:52:29.140 回答
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

于 2013-05-23T07:51:15.423 回答