summaryrefslogtreecommitdiff
path: root/etc
diff options
context:
space:
mode:
authorDaniel Friesel <derf@derf.homelinux.org>2008-12-22 01:23:48 +0100
committerDaniel Friesel <derf@derf.homelinux.org>2008-12-22 01:23:48 +0100
commitde99d797adc385f2870303431313bf236fed1b1f (patch)
treece319aaa1b679f34eee7ba9f96c26867c237b6eb /etc
parent95bd45a0883383de5cccab0bd34da0cbbf54a558 (diff)
Added __git_files completion
This adds the handling of ../, currently with at least these problems: - ../ only completes to ../.. if ../.git does not exist (until ..../.git does exist) - if etc/foo/bar was modified, and pwd is etc, git add will *only* complete to ../etc/foo/bar
Diffstat (limited to 'etc')
-rw-r--r--etc/completions/__git_files30
1 files changed, 30 insertions, 0 deletions
diff --git a/etc/completions/__git_files b/etc/completions/__git_files
new file mode 100644
index 0000000..6b8c1dd
--- /dev/null
+++ b/etc/completions/__git_files
@@ -0,0 +1,30 @@
+#autoload +X
+local expl files ls_opts opts gitdir dirdiff i tmp
+
+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 [[ ! -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/}
+ }
+ }
+}
+
+_wanted files expl 'index file' _multi_parts $@ - / files