Skip to content

Commit

Permalink
Add option to turn off setup of shell completion
Browse files Browse the repository at this point in the history
  • Loading branch information
mmcrockett committed Dec 11, 2024
1 parent e606623 commit 5d2c107
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 37 deletions.
2 changes: 2 additions & 0 deletions git.scmbrc.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
# ----------------------------------------------
Expand Down
66 changes: 36 additions & 30 deletions lib/git/aliases.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 <alias> <command_prefix> <command>
Expand All @@ -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
}
Expand Down Expand Up @@ -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
12 changes: 7 additions & 5 deletions lib/git/branch_shortcuts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 4 additions & 2 deletions lib/git/tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

0 comments on commit 5d2c107

Please sign in to comment.