有没有什么快捷方式引用一个mv命令的第一个参数的路径? [英] Is there any shortcut to reference the path of the first argument in a MV command?

查看:81
本文介绍了有没有什么快捷方式引用一个mv命令的第一个参数的路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经常用mv重命名文件发现自己。例如。

  MV应用程序/模型/ keywords_builder.rb应用程序/模型/ keywords_generator.rb

这样做我需要写(好吧,标签完成)第二个参数的路径。在这个例子是不是太糟糕,但有时路径深度嵌套,这似乎是相当多的额外的输入的。

有没有更有效的方法来做到这一点?


解决方案

您可以使用历史扩展是这样的:

  MV应用程序/模块/ keywords_builder.rb#^:H / keywords_generator.rb


  1. 引入历史扩展。

  2. 是指当前正在输入的命令

  3. ^ 表示第一个参数

  4. :小时是一个修改器获得头,即没有文件的部分目录

它在庆典支持和的zsh

文件:

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 write (ok, tab complete) the path for the second parameter. In this example it isn't too bad but sometimes the path is deeply nested and it seems like quite a bit of extra typing.

Is there a more efficient way to do this?

解决方案

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:

这篇关于有没有什么快捷方式引用一个mv命令的第一个参数的路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆