summaryrefslogtreecommitdiff
path: root/etc/completions/__git_files
diff options
context:
space:
mode:
authorDaniel Friesel <derf@derf.homelinux.org>2009-01-02 21:34:53 +0100
committerDaniel Friesel <derf@derf.homelinux.org>2009-01-02 21:34:53 +0100
commitb01d636d4e5ea11a15ebdbc6144a746a4ca80713 (patch)
tree762cd4dc816dc717cffeb0b1123fb190053d547c /etc/completions/__git_files
parenta008a5e057445c05709f827d7ee01ddccad24026 (diff)
__git_files: Another partially working, but more promising approach
Diffstat (limited to 'etc/completions/__git_files')
-rw-r--r--etc/completions/__git_files28
1 files changed, 16 insertions, 12 deletions
diff --git a/etc/completions/__git_files b/etc/completions/__git_files
index ef14c31..808fe8e 100644
--- a/etc/completions/__git_files
+++ b/etc/completions/__git_files
@@ -1,5 +1,5 @@
#autoload +X
-local expl files ls_opts opts gitdir dirdiff i tmp
+local expl files ls_opts opts gitdir dirdiff i j prefix item self
zparseopts -D -E -a opts -- -cached -deleted -modified -others -ignored -unmerged -killed
@@ -12,21 +12,25 @@ ls_opts=("--exclude-per-directory=.gitignore")
files=(${(ps:\0:)"$(cd $gitdir/..; _call_program files git ls-files -z $ls_opts $opts 2>/dev/null)"})
__git_command_successful || return
-[[ -n $gitdir ]] || return
+if [[ -z $gitdir ]] {
+ echo "wtf: $gitdir"
+ return
+}
if [[ ! -d .git ]] {
dirdiff=${PWD#${gitdir%/.git}}
- repeat ${#${(s:/:)dirdiff}}; do
- tmp+='../'
- done
- dirdiff=${dirdiff#/}
- for (( i=1; i <= $#files; i++)) {
- if [[ $files[$i] == $dirdiff/* ]] {
- files[$i]=${files[$i]#$dirdiff/}
- } else {
- files[$i]=$tmp${files[$i]#$dirdiff/}
+ for ((i = 1; i <= $#files; i++)) {
+ prefix=''
+ item=(${(s:/:)files[$i]})
+ self=(${(s:/:)dirdiff})
+ for ((j = 1; j <= ${#item} && j <= ${#self}; j++)) {
+ if [[ $item[$j] == $self[$j] ]] {
+ item[$j]=''
+ } else {
+ prefix+='../'
+ }
}
+ files[$i]=${prefix}${(j:/:)item}
}
}
-
_wanted files expl 'index file' _multi_parts $@ - / files