diff --git a/git.scmbrc.example b/git.scmbrc.example index c97789b..3c07897 100644 --- a/git.scmbrc.example +++ b/git.scmbrc.example @@ -14,6 +14,8 @@ export ga_auto_remove="yes" # Note: Bash tab completion will not be automatically set up for your aliases if you disable this option. export git_setup_aliases="yes" +# - Set the following option to 'yes' if you want to turn off shell completion setup +# export git_skip_shell_completion="yes" # Git Index Config # ---------------------------------------------- diff --git a/lib/git/aliases.sh b/lib/git/aliases.sh index 2d6a6b8..80dd3fb 100644 --- a/lib/git/aliases.sh +++ b/lib/git/aliases.sh @@ -47,20 +47,22 @@ _alias "$git_alias" "git" # which I've altered slightly to be more flexible. # https://github.com/bronson/dotfiles/blob/731bfd951be68f395247982ba1fb745fbed2455c/.bashrc#L81 # (only works for bash) -__define_git_completion () { -eval " -_git_$1_shortcut () { -COMP_LINE=\"git $2 \${COMP_LINE/$1 }\" -let COMP_POINT+=$((4+${#2}-${#1})) -COMP_WORDS=(git $2 \"\${COMP_WORDS[@]:1}\") -let COMP_CWORD+=1 - -local cur words cword prev -_get_comp_words_by_ref -n =: cur words cword prev -__git_wrap__git_main -} -" -} +if [ "$git_skip_shell_completion" != "yes" ]; then + __define_git_completion () { + eval " + _git_$1_shortcut () { + COMP_LINE=\"git $2 \${COMP_LINE/$1 }\" + let COMP_POINT+=$((4+${#2}-${#1})) + COMP_WORDS=(git $2 \"\${COMP_WORDS[@]:1}\") + let COMP_CWORD+=1 + + local cur words cword prev + _get_comp_words_by_ref -n =: cur words cword prev + __git_wrap__git_main + } + " + } +fi # Define git alias with tab completion # Usage: __git_alias @@ -75,9 +77,11 @@ __git_alias () { fi alias $alias_str="$cmd_prefix $cmd${cmd_args:+ }${cmd_args[*]}" - if [ "$shell" = "bash" ]; then - __define_git_completion "$alias_str" "$cmd" - complete -o default -o nospace -F _git_"$alias_str"_shortcut "$alias_str" + if [ "$git_skip_shell_completion" != "yes" ]; then + if [ "$shell" = "bash" ]; then + __define_git_completion "$alias_str" "$cmd" + complete -o default -o nospace -F _git_"$alias_str"_shortcut "$alias_str" + fi fi fi } @@ -180,17 +184,19 @@ fi # Tab completion -if [ $shell = "bash" ]; then - # Fix to preload Arch bash completion for git - [[ -s "/usr/share/git/completion/git-completion.bash" ]] && source "/usr/share/git/completion/git-completion.bash" - # new path in Ubuntu 13.04 - [[ -s "/usr/share/bash-completion/completions/git" ]] && source "/usr/share/bash-completion/completions/git" - complete -o default -o nospace -F __git_wrap__git_main $git_alias - - # Git repo management & aliases. - # If you know how to rewrite _git_index_tab_completion() for zsh, please send me a pull request! - complete -o nospace -F _git_index_tab_completion git_index - complete -o nospace -F _git_index_tab_completion $git_index_alias -else - compdef _git_index_tab_completion git_index $git_index_alias +if [ "$git_skip_shell_completion" != "yes" ]; then + if [ $shell = "bash" ]; then + # Fix to preload Arch bash completion for git + [[ -s "/usr/share/git/completion/git-completion.bash" ]] && source "/usr/share/git/completion/git-completion.bash" + # new path in Ubuntu 13.04 + [[ -s "/usr/share/bash-completion/completions/git" ]] && source "/usr/share/bash-completion/completions/git" + complete -o default -o nospace -F __git_wrap__git_main $git_alias + + # Git repo management & aliases. + # If you know how to rewrite _git_index_tab_completion() for zsh, please send me a pull request! + complete -o nospace -F _git_index_tab_completion git_index + complete -o nospace -F _git_index_tab_completion $git_index_alias + else + compdef _git_index_tab_completion git_index $git_index_alias + fi fi diff --git a/lib/git/branch_shortcuts.sh b/lib/git/branch_shortcuts.sh index 0a195f2..1cd240b 100644 --- a/lib/git/branch_shortcuts.sh +++ b/lib/git/branch_shortcuts.sh @@ -47,9 +47,11 @@ __git_alias "$git_branch_delete_alias" "_scmb_git_branch_shortcuts" "-d" __git_alias "$git_branch_delete_force_alias" "_scmb_git_branch_shortcuts" "-D" # Define completions for git branch shortcuts -if [ "$shell" = "bash" ]; then - for alias_str in $git_branch_alias $git_branch_all_alias $git_branch_move_alias $git_branch_delete_alias; do - __define_git_completion $alias_str branch - complete -o default -o nospace -F _git_"$alias_str"_shortcut $alias_str - done +if [ "$git_skip_shell_completion" != "yes" ]; then + if [ "$shell" = "bash" ]; then + for alias_str in $git_branch_alias $git_branch_all_alias $git_branch_move_alias $git_branch_delete_alias; do + __define_git_completion $alias_str branch + complete -o default -o nospace -F _git_"$alias_str"_shortcut $alias_str + done + fi fi diff --git a/lib/git/tools.sh b/lib/git/tools.sh index c158a77..eb4b743 100644 --- a/lib/git/tools.sh +++ b/lib/git/tools.sh @@ -122,8 +122,10 @@ git_swap_remotes() { echo "Swapped $1 <-> $2" } # (use git fetch tab completion) -if [ "$shell" = "bash" ]; then - complete -o default -o nospace -F _git_fetch git_swap_remotes +if [ "$git_skip_shell_completion" != "yes" ]; then + if [ "$shell" = "bash" ]; then + complete -o default -o nospace -F _git_fetch git_swap_remotes + fi fi