
git commit
クリック時にオートコンプリート機能を追加しようとしていますTabTab。
私が開発しているオートコンプリート機能は、四半期命名規則に基づいています。慣例は、ブランチ名の末尾にPivotalTracker Id番号を追加することであるため、一般的なブランチは次のとおりですfoo-bar-baz-1449242
。
[#1449242]
コミットメッセージの先頭にプレフィックスを追加して、コミットをPivotalTrackerカードに関連付けることができます。git commit
この内容を入力し、ユーザーがクリックすると自動的に挿入されるようにしたいと思いますTabTab。
私はここでこれをしました。https://github.com/tlehman/dotfiles/blob/master/ptid_git_complete
(便宜上、ソースコードは次のとおりです。)
function _ptid_git_complete_()
{
local line="${COMP_LINE}" # the entire line that is being completed
# check that the commit option was passed to git
if [[ "$line" == "git commit" ]]; then
# get the PivotalTracker Id from the branch name
ptid=`git branch | grep -e "^\*" | sed 's/^\* //g' | sed 's/\-/ /g' | awk '{ print $(NF) }'`
nodigits=$(echo $ptid | sed 's/[[:digit:]]//g')
if [ ! -z $nodigits ]; then
: # do nothing
else
COMPREPLY=("commit -m \"[#$ptid]")
fi
else
reply=()
fi
}
complete -F _ptid_git_complete_ git
問題は、これが定義されたgitオートコンプリート機能を損なうことです。git-autocomplete.bash
この機能をgit-autocompletion.bashと互換性を持たせるにはどうすればよいですか?
答え1
__git_complete
(で定義)を使用して独自の関数をインストールし、関数git-autocompletion.bash
を元の関数に置き換えることができます。次のように見えます。
function _ptid_git_complete_()
{
local line="${COMP_LINE}" # the entire line that is being completed
# check that the commit option was passed to git
if [[ "$line" == "git commit " ]]; then
# get the PivotalTracker Id from the branch name
ptid=`git branch | grep -e "^\*" | sed 's/^\* //g' | sed 's/\-/ /g' | awk '{ print $(NF) }'`
nodigits=$(echo $ptid | sed 's/[[:digit:]]//g')
if [ ! -z $nodigits ]; then
: # do nothing
else
COMPREPLY=("-m \"[#$ptid]")
fi
else
__git_main
fi
}
__git_complete git _ptid_git_complete_