LoginSignup
9
4

More than 5 years have passed since last update.

gitのサブコマンドとしてfishの関数を呼び出す

Posted at

git-subcommandという名前の実行ファイルをパスの通ったディレクトリに置いておくと

$ git subcommand

のようにハイフンなしで実行できるらしい.

参考
- 便利な「git-サブコマンド」を作成する
- オレオレ Git サブコマンドを作る
- gitのサブコマンドを自分で作る

でもfish shellだと,スクリプトファイルを作るよりも関数を書いて済ましてしまうことが多い.

なので,git-で始まる関数を書いたとき,それをgitのサブコマンドとして実行するようなラッパーを書いてみました.

git.fish
function git
    set -l subcommand "git-$argv[1]"

    if functions -q $subcommand
        set -e argv[1]
        eval $subcommand $argv
    else
        command git $argv
    end
end

これで例えばgit-packageというfish関数を定義するとgit packageのようにサブコマンドとして呼び出せます.便利!

9
4
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
9
4