Is there any shortcut to reference the path of the first argument in a MV command?

后端 未结 5 562
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-16 01:07

I often find myself using mv to rename a file. E.g.

mv app/models/keywords_builder.rb app/models/keywords_generator.rb

Doing so I need to w

5条回答
  •  自闭症患者
    2020-12-16 01:35

    You can use history expansion like this:

    mv app/modules/keywords_builder.rb !#^:h/keywords_generator.rb
    
    1. ! introduces history expansion.
    2. # refers to the command currently being typed
    3. ^ means the first argument
    4. :h is a modifier to get the "head", i.e. the directory without the file part

    It's supported in bash and zsh.

    Docs:

    • bash history expansion
    • zsh history expansion

提交回复
热议问题