LoginSignup
26
22

More than 5 years have passed since last update.

gitのaliasコマンドに引数を渡す方法

Posted at

gitのaliasコマンドに引数を渡す

引数の渡し方をいろいろ調べたのでメモ。
関数を使うやり方の方が分かりやすくて良さそう。

[alias]
        command1 = "!sh -c 'echo $1 $2' -"
        command2 = "!f(){ echo $1 $2;};f"
$ git command2 hoge fuga
hoge fuga

sh -c を使う

command1 = "!sh -c 'echo $1 $2' -"

最後のハイフンは$0を消すためのダミー。
ハイフン無しで'echo $0 $1'とすると、引数ありの時は一つ目が\$0に。無しの時は\$0にshが入る。

関数を使う

command2 = "!f(){ echo $1 $2;};f"

こちらは見ての通り。{の後のスペースを詰めると動かないので注意。

26
22
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
26
22