Skip to content

Commit

Permalink
Merge pull request #1047 from felipec/fc/fixes
Browse files Browse the repository at this point in the history
Zsh completion fixes

Fixes #940
  • Loading branch information
koutcher committed Dec 13, 2020
2 parents e0fc1f4 + e073f1b commit 04cc156
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 26 deletions.
28 changes: 6 additions & 22 deletions contrib/tig-completion.bash
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ __tig_options="
-v --version
-h --help
-C
--
+
"
__tig_commands="
blame
Expand All @@ -47,59 +45,45 @@ __tig_commands="
show
"

_tig() {
__tig_main () {
# parse already existing parameters
local i c=1 command
while [ $c -lt $cword ]; do
i="${words[c]}"
case "$i" in
--) command="log"; break;;
-C) return;;
-*) ;;
*) command="$i"; break ;;
esac
c=$((++c))
done

# options -- only before command
case "$command$cur" in
-C*)
COMPREPLY=( $(compgen -d -P '-C' -- ${cur##-C}) )
return
;;
esac

# commands
case "$command" in
refs|status|stash)
COMPREPLY=( $(compgen -W "$__tig_options" -- "$cur") )
__gitcomp "$__tig_options"
;;
reflog)
__git_complete_command log
;;
"")
__git_complete_command log
__gitcompappend "$(compgen -W "$__tig_options $__tig_commands" -- "$cur")"
__gitcomp "$__tig_options $__tig_commands"
;;
*)
__git_complete_command $command
;;
esac
}

# Detect if current shell is ZSH, and if so, load this file in bash
# compatibility mode.
if [ -n "$ZSH_VERSION" ]; then
autoload bashcompinit
bashcompinit
fi

# we use internal git-completion functions, so wrap _tig for all necessary
# variables (like cword and prev) to be defined
__git_complete tig _tig
__git_complete tig __tig_main

# The following are necessary only for Cygwin, and only are needed
# when the user has tab-completed the executable name and consequently
# included the '.exe' suffix.
if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
__git_complete tig.exe _tig
__git_complete tig.exe __tig_main
fi
15 changes: 11 additions & 4 deletions contrib/tig-completion.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,23 @@
# then add following to your ~/.zshrc file:
#
# fpath=(~/.zsh $fpath)
#
# You also need Git's Zsh completion installed:
#
# https://github.com/felipec/git-completion/blob/master/git-completion.zsh


_tig () {
local e
e=$(dirname ${funcsourcetrace[1]%:*})/git-completion.bash
if [ -f $e ]; then
GIT_SOURCING_ZSH_COMPLETION=y . $e
fi

compdef _git tig

e=$(dirname ${funcsourcetrace[1]%:*})/tig-completion.bash
if [ -f $e ]; then
# Temporarily override __git_complete so the bash script doesn't complain
local old="$functions[__git_complete]"
functions[__git_complete]=:
. $e
functions[__git_complete]="$old"
fi
}

0 comments on commit 04cc156

Please sign in to comment.