Merge pull request #107 from g5pw/master

Add ZSH completion support
This commit is contained in:
Nathan Broadbent
2013-10-17 15:15:23 -07:00
2 changed files with 68 additions and 31 deletions

View File

@@ -158,5 +158,7 @@ if [ $shell = "bash" ]; then
# If you know how to rewrite _git_index_tab_completion() for zsh, please send me a pull request! # 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
complete -o nospace -F _git_index_tab_completion $git_index_alias complete -o nospace -F _git_index_tab_completion $git_index_alias
else
compdef _git_index_tab_completion git_index $git_index_alias
fi fi

View File

@@ -281,8 +281,9 @@ function _git_index_batch_cmd() {
} }
# Bash tab completion function for git_index() if [ $shell = 'bash' ]; then
function _git_index_tab_completion() { # Bash tab completion function for git_index()
function _git_index_tab_completion() {
_check_git_index _check_git_index
local curw local curw
IFS=$'\n' IFS=$'\n'
@@ -300,13 +301,11 @@ function _git_index_tab_completion() {
COMPREPLY=($(compgen -d "$base_path$search_path" | \grep -v "/.git" | sed -e "s:$base_path:$project:" -e "s:$:/:" )) COMPREPLY=($(compgen -d "$base_path$search_path" | \grep -v "/.git" | sed -e "s:$base_path:$project:" -e "s:$:/:" ))
# If curr string starts with /, tab complete top-level directories in root project dir # If curr string starts with /, tab complete top-level directories in root project dir
elif ([ $shell = "bash" ] && [ "${curw:0:1}" = "/" ]) || \ elif [ "${curw:0:1}" = "/" ]; then
([ $shell = "zsh" ] && [ "${curw[1,1]}" = "/" ]); then
COMPREPLY=($(compgen -d "$GIT_REPO_DIR$curw" | sed -e "s:$GIT_REPO_DIR/::" -e "s:^:/:")) COMPREPLY=($(compgen -d "$GIT_REPO_DIR$curw" | sed -e "s:$GIT_REPO_DIR/::" -e "s:^:/:"))
# If curr string starts with --, tab complete commands # If curr string starts with --, tab complete commands
elif ([ $shell = "bash" ] && [ "${curw:0:2}" = "--" ]) || \ elif [ "${curw:0:2}" = "--" ]; then
([ $shell = "zsh" ] && [ "${curw[1,2]}" = "--" ]); then
local commands="--list\n--rebuild\n--update-all\n--batch-cmd\n--count-by-host" local commands="--list\n--rebuild\n--update-all\n--batch-cmd\n--count-by-host"
COMPREPLY=($(compgen -W '$(echo -e "\n"$commands)' -- $curw)) COMPREPLY=($(compgen -W '$(echo -e "\n"$commands)' -- $curw))
@@ -316,5 +315,41 @@ function _git_index_tab_completion() {
fi fi
IFS=$' \t\n' IFS=$' \t\n'
return 0 return 0
} }
else
function _git_index_tab_completion() {
typeset -A opt_args
local state state_descr context line
_arguments \
"--rebuild[Rebuild repository index]" \
"--update-all[Update all indexed repositories]" \
"--update-all-with-notifications[Update all indexed repositories with notifications]" \
"--list[List all repositories currently present in the index]" \
"--count-by-host[Count all repositories per host]" \
"--batch-cmd+[Run a command on all repositories]:command:->command" \
"1::Git projects:->projects" \
&& return 0
case "$state" in
projects)
# Only check and rebuild index if necessary
_check_git_index
if [[ $PREFIX == /* ]]; then
PREFIX=$PREFIX[2,-1]
_files -X "Files in project directory" -W $GIT_REPO_DIR
else
compadd -X "Git projects" $(sed -e 's:.*/::' -e 's:$:/:' "$GIT_REPO_DIR/.git_index") && return 0
fi
;;
command)
local ret=1
_call_function ret _command_names
return ret
;;
esac
return 1
}
fi