Finally sorted out tab completions for git aliases, works with all versions of git (1.7.5.4 up to 1.7.8) (#11)

This commit is contained in:
Nathan Broadbent
2011-12-15 00:32:27 +08:00
parent 993c9ee9fc
commit cb50656cf0

View File

@@ -22,14 +22,14 @@ _alias $git_alias='git'
__define_git_completion () { __define_git_completion () {
eval " eval "
_git_$1_shortcut () { _git_$1_shortcut () {
COMP_LINE=\"git $2\${COMP_LINE#$1}\" COMP_LINE=\"git $2 \${COMP_LINE/$1 }\"
let COMP_POINT+=$((4+${#2}-${#1})) let COMP_POINT+=$((4+${#2}-${#1}))
COMP_WORDS=(git $2 \"\${COMP_WORDS[@]:1}\") COMP_WORDS=(git $2 \"\${COMP_WORDS[@]:1}\")
let COMP_CWORD+=1 let COMP_CWORD+=1
local cur words cword prev local cur words cword prev
_get_comp_words_by_ref -n =: cur words cword prev _get_comp_words_by_ref -n =: cur words cword prev
_git_$2 _git
} }
" "
} }
@@ -98,7 +98,7 @@ _alias $git_branch_all_alias='git branch -a'
_alias $git_index_alias="git_index" _alias $git_index_alias="git_index"
# Tab completion for aliases # ZSH tab completion
if [[ $shell == "zsh" ]]; then if [[ $shell == "zsh" ]]; then
# Turn on support for bash completion # Turn on support for bash completion
autoload bashcompinit autoload bashcompinit
@@ -122,19 +122,7 @@ if [[ $shell == "zsh" ]]; then
compdef _git $git_add_shortcuts_alias=git-add compdef _git $git_add_shortcuts_alias=git-add
compdef _git $git_merge_alias=git-merge compdef _git $git_merge_alias=git-merge
else else
# -- bash
complete -o default -o nospace -F _git $git_alias complete -o default -o nospace -F _git $git_alias
complete -o default -o nospace -F _git_pull $git_pull_alias
complete -o default -o nospace -F _git_push $git_push_alias
complete -o default -o nospace -F _git_fetch $git_fetch_alias
complete -o default -o nospace -F _git_branch $git_branch_alias
complete -o default -o nospace -F _git_rebase $git_rebase_alias
complete -o default -o nospace -F _git_merge $git_merge_alias
complete -o default -o nospace -F _git_log $git_log_alias
complete -o default -o nospace -F _git_diff $git_diff_alias
complete -o default -o nospace -F _git_checkout $git_checkout_alias
complete -o default -o nospace -F _git_remote $git_remote_alias
complete -o default -o nospace -F _git_show $git_show_alias
fi fi
# Git repo management & aliases. # Git repo management & aliases.