diff options
author | Daniel Friesel <derf@derf.homelinux.org> | 2009-02-01 16:19:29 +0100 |
---|---|---|
committer | Daniel Friesel <derf@derf.homelinux.org> | 2009-02-01 16:19:29 +0100 |
commit | 630b03f911531691f4f5cf0834ffb060c6c3f076 (patch) | |
tree | 69c47c845ff8a531d9f86fe4d7e244445c3736b4 | |
parent | 9e313ffadacf7290645b153fd799b86ab4498e9e (diff) | |
parent | c7ab8229523525dc101a8fb6619bae4f6fbd7896 (diff) |
Merge branch 'experimental'
-rw-r--r-- | etc/completions/__git_files | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/etc/completions/__git_files b/etc/completions/__git_files new file mode 100644 index 0000000..88e9d1b --- /dev/null +++ b/etc/completions/__git_files @@ -0,0 +1,41 @@ +#autoload +X +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 + +gitdir=$(_call_program gitdir git rev-parse --git-dir 2>/dev/null) +__git_command_successful || return + +ls_opts=("--exclude-per-directory=.gitignore") +[[ -f "$gitdir/info/exclude" ]] && ls_opts+="--exclude-from=$gitdir/info/exclude" + +files=(${(ps:\0:)"$(cd $gitdir/..; _call_program files git ls-files -z $ls_opts $opts 2>/dev/null)"}) +__git_command_successful || return + +if [[ -z $gitdir ]] { + echo "wtf: $gitdir" + return +} + +if [[ ! -d .git ]] { + dirdiff=${PWD#${gitdir%/.git}/} + for ((i = 1; i <= $#files; i++)) { + prefix='' + item=(${(s:/:)files[$i]}) + self=(${(s:/:)dirdiff}) + for ((j = 1; j <= ${#self}; j++)) { + if [[ $item[$j] == $self[$j] ]] { + item[$j]='' + } else { + prefix+='../' + } + } + files[$i]=${prefix} + for j in $item; { + [[ -n $j ]] && files[$i]+="$j/" + } + files[$i]=${files[$i]%/} + echo $files[$i] >> /tmp/bar + } +} +_wanted files expl 'index file' _multi_parts $@ - / files |