[PATCH 11/11] completion: zsh: add proper file support
- From
Felipe Contreras <felipe.contreras@gmail.com>
- Date
- Apr 27, 2013, 10:19 UTC
- Message-ID
- <1367057994-19887-12-git-send-email-felipe.contreras@gmail.com>
- In-Reply-To
- <1367057994-19887-1-git-send-email-felipe.contreras@gmail.com>
So the files are completed and coloured nicely.
The code would be only a couple of lines if only _multi_parts or _path_files worked correctly, but alas, they don't.
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> --- contrib/completion/git-completion.zsh | 42 +++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+)
diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh index 4577502..8c6916a 100644 --- a/contrib/completion/git-completion.zsh +++ b/contrib/completion/git-completion.zsh @@ -60,6 +60,48 @@ __gitcomp_nl () compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0 } +# +# We need to remove the extra slash for directories, and we need to remove the +# spaces for files, otherwise zsh can't stat them and threat them as proper files. +# +__git_index_files () +{ + local dir="$(__gitdir)" root="${2-.}" file + + if [ -d "$dir" ]; then + local -a files + emulate ksh -c '__git_ls_files_helper "$root" "$1"' | + while read -r file; do + case "$file" in + ?*/*) + files+="${file%%/*}" + ;; + *) + files+="$file" + ;; + esac + done + compadd -Q -p "${2-}" -f -a files && _ret=0 + fi +} + +__git_complete_index_file () +{ + emulate -L zsh + + local pfx="" cur_="$cur" + + case "$cur_" in + ?*/*) + pfx="${cur_%/*}" + cur_="${cur_##*/}" + pfx="${pfx}/" + ;; + esac + + __git_index_files "$1" "$pfx" +} + _git () { local _ret=1
-- 1.8.2.1.1031.g2ee5873