From 5d2c107199872f7dfe24b2ee84ff87732e89aa29 Mon Sep 17 00:00:00 2001 From: mike crockett Date: Wed, 11 Dec 2024 13:36:39 -0600 Subject: [PATCH 1/2] Add option to turn off setup of shell completion --- git.scmbrc.example | 2 ++ lib/git/aliases.sh | 66 ++++++++++++++++++++----------------- lib/git/branch_shortcuts.sh | 12 ++++--- lib/git/tools.sh | 6 ++-- 4 files changed, 49 insertions(+), 37 deletions(-) diff --git a/git.scmbrc.example b/git.scmbrc.example index c97789b5..3c078979 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 2d6a6b87..80dd3fb5 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 0a195f2a..1cd240b4 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 c158a772..eb4b7433 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 From 47e49f12121c29e5e54a07165d8645b007ab9f79 Mon Sep 17 00:00:00 2001 From: mike crockett Date: Fri, 13 Dec 2024 08:04:31 -0600 Subject: [PATCH 2/2] PR Feedback. --- lib/git/aliases.sh | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/lib/git/aliases.sh b/lib/git/aliases.sh index 80dd3fb5..7062dd8d 100644 --- a/lib/git/aliases.sh +++ b/lib/git/aliases.sh @@ -47,22 +47,20 @@ _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) -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_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 +} +" +} # Define git alias with tab completion # Usage: __git_alias