独自のバージョンの git-extras を実装しようとしていgit delete-branch
ます。
#!/usr/bin/env bash
# Assert there is at least one branch provided
test -z $1 && echo "branch required." 1>&2 && exit 1
for branch in "$@"
do
remote=$(git config branch.$branch.remote)
test -z $remote && remote="origin"
ref=$(git config branch.$branch.merge)
test -z $ref && ref="refs/heads/$branch"
git branch -D $branch
git branch -d -r $remote/$branch
git push $remote :$ref
done
ここからの抜粋: https://github.com/tj/git-extras/blob/master/bin/git-delete-branch
もちろん、次のコードで表される分岐の補完がなければ、それほど意味がありません。
_git_delete_branch(){
__gitcomp "$(__git_heads)"
}
ここからの抜粋: https://github.com/tj/git-extras/blob/master#L_51/etc/bash_completion.sh
stable
そのコードを試すためにgit-extrasをインストールした後、それはかなりうまくいきましたが、質問で述べたように、ブランチが削除される前にブランチが統合されているかどうかを確認したいので、独自の方法を実装したいと思います。
bash_completion.d
スクリプトをフォルダーに入れたくないので、次のスクリプトを作成しました。
#!/ビン/バッシュ
_delete_git_branch(){
__gitcomp "$(__git_heads)"
}
complete -o bashdefault -o default -o nospace -F _delete_git_branch delete_git_branch
source
私の中に含まれてい~/.bash_profile
ます。ここで端末に入力delete_git_branch [TAB][TAB]
すると、ブランチが表示されます。しかし、入力して補完の結果を制限しようとするとdelete_git_branch 1[TAB][TAB]
、最初の結果とまったく同じ結果が得られます。
ここで渡されたパラメーターが欠落していると思いますが、よくわかりません。
私が見逃したことは何か思いつきますか?bash_completion.d
コマンドの代わりにフォルダーを使用することを除いて、私のスクリプトと git-extras が使用するスクリプトの違いはわかりませんcomplete
。