Skip to content

Commit

Permalink
feat: Add option to turn off setup of shell completion (#342)
Browse files Browse the repository at this point in the history
### Issue
- When I moved from Linux => Mac I didn't have bash completion package
installed and so got these errors (plus turns out I really prefer to
complete on filenames even though the branch complete is a nice feature)

Screenshot of errors I see:
![Screenshot 2024-12-11 at 1 32
14 PM](https://github.com/user-attachments/assets/56e4d8b4-cb00-481e-9e4b-2c1723a4f45f)

### Proposed Fix
- Add an option `git_skip_shell_completion` that is backward compatible
and will ignore any shell completion setup
  • Loading branch information
ghthor authored Dec 13, 2024
2 parents e606623 + 47e49f1 commit fa18af9
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 23 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
36 changes: 20 additions & 16 deletions lib/git/aliases.sh
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,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 +182,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 fa18af9

Please sign in to comment.