Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zsh completion fixes #1047

Merged
merged 3 commits into from
Dec 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
--
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, why did you reve these two lines? They are valid completion options :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because they confuse __gitcomp. Well, at least the -- one.

Most commands do have the -- option, but none that I'm aware of actually add it to the completion.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, then that sounds fine to me too.

+
"
__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
}