From 1ad7408d054ee86232650532ab41f0514e5fb725 Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Sat, 17 Dec 2011 10:53:58 +0800 Subject: [PATCH] Took some inspiration from git tab completion, and separated the completion of '--' commands from project directories --- lib/git/repo_index.sh | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/git/repo_index.sh b/lib/git/repo_index.sh index 1253c91..7f663ad 100644 --- a/lib/git/repo_index.sh +++ b/lib/git/repo_index.sh @@ -239,20 +239,25 @@ function _git_index_tab_completion() { local project=$(echo "$curw" | cut -d "/" -f1) local base_path=$(grep "/$project$" "$GIT_REPO_DIR/.git_index" | sed 's/ /\\ /g') - # If matching path was found and curr string contains a /, then complete project sub-directories + # If matching project path was found and curr string contains a /, then complete project sub-directories if [[ -n "$base_path" && $curw == */* ]]; then local search_path=$(echo "$curw" | sed "s:^${project/\\/\\\\\\}::") 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 elif ([ $shell = "bash" ] && [ "${curw:0:1}" = "/" ]) || \ - ([ $shell = "zsh" ] && [ "${curw[1]}" = "/" ]); then + ([ $shell = "zsh" ] && [ "${curw[1,1]}" = "/" ]); then COMPREPLY=($(compgen -d "$GIT_REPO_DIR$curw" | sed -e "s:$GIT_REPO_DIR/::" -e "s:^:/:")) - # Else, tab complete the entries in .git_index, plus '--' commands - else + # If curr string starts with --, tab complete commands + elif ([ $shell = "bash" ] && [ "${curw:0:2}" = "--" ]) || \ + ([ $shell = "zsh" ] && [ "${curw[1,2]}" = "--" ]); then local commands="--list\n--rebuild\n--update-all\n--batch-cmd\n--count-by-host" - COMPREPLY=($(compgen -W '$(sed -e "s:.*/::" -e "s:$:/:" "$GIT_REPO_DIR/.git_index" | sort)$(echo -e "\n"$commands)' -- $curw)) + COMPREPLY=($(compgen -W '$(echo -e "\n"$commands)' -- $curw)) + + # Else, tab complete the entries in .git_index + else + COMPREPLY=($(compgen -W '$(sed -e "s:.*/::" -e "s:$:/:" "$GIT_REPO_DIR/.git_index" | sort)' -- $curw)) fi unset IFS return 0