summary refs log tree commit diff
diff options
context:
space:
mode:
authorChristian Neukirchen <chneukirchen@gmail.com>2016-02-28 19:03:17 +0100
committerChristian Neukirchen <chneukirchen@gmail.com>2016-02-28 19:03:17 +0100
commit989d3f1ce42f98e64b6740e7c9b94bab5fb8ae13 (patch)
tree54c87a59a1bc8134a8308d07e71bc7be5ff12141
parent7a8402622c25d043b1a535ad018288352547e3a9 (diff)
downloadlr-989d3f1ce42f98e64b6740e7c9b94bab5fb8ae13.tar.gz
lr-989d3f1ce42f98e64b6740e7c9b94bab5fb8ae13.tar.xz
lr-989d3f1ce42f98e64b6740e7c9b94bab5fb8ae13.zip
add zsh completion
-rw-r--r--ChangeLog.md1
-rw-r--r--Makefile5
-rw-r--r--_lr102
3 files changed, 107 insertions, 1 deletions
diff --git a/ChangeLog.md b/ChangeLog.md
index b8dc2af..89c4143 100644
--- a/ChangeLog.md
+++ b/ChangeLog.md
@@ -5,4 +5,5 @@
 * Colorize symlink targets
 * Show broken links
 * On Linux: Display of capabilities, ACL and xattrs in `-l`
+* zsh completion
 * Some small things in contrib/
diff --git a/Makefile b/Makefile
index 124dcd0..5ef6fcd 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,5 @@
 ALL=lr
+ZSHCOMP=_lr
 
 CFLAGS=-g -O2 -Wall -Wno-switch -Wextra -Wwrite-strings
 
@@ -6,6 +7,7 @@ DESTDIR=
 PREFIX=/usr/local
 BINDIR=$(PREFIX)/bin
 MANDIR=$(PREFIX)/share/man
+ZSHCOMPDIR=$(PREFIX)/share/zsh/site-functions
 
 all: $(ALL)
 
@@ -13,8 +15,9 @@ clean: FRC
 	rm -f lr
 
 install: FRC all
-	mkdir -p $(DESTDIR)$(BINDIR) $(DESTDIR)$(MANDIR)/man1
+	mkdir -p $(DESTDIR)$(BINDIR) $(DESTDIR)$(MANDIR)/man1 $(DESTDIR)$(ZSHCOMPDIR)
 	install -m0755 $(ALL) $(DESTDIR)$(BINDIR)
 	install -m0644 $(ALL:=.1) $(DESTDIR)$(MANDIR)/man1
+	install -m0644 $(ZSHCOMP) $(DESTDIR)$(ZSHCOMPDIR)
 
 FRC:
diff --git a/_lr b/_lr
new file mode 100644
index 0000000..a6f483c
--- /dev/null
+++ b/_lr
@@ -0,0 +1,102 @@
+#compdef lr
+
+_lr_format() {
+	if [[ ${(Q)PREFIX} = *% ]]; then
+		local -a specs
+		specs=(
+			'%:percent sign'
+			's:file size in bytes'
+			'S:file size, with human readable unit'
+			'b:file size in 512-byte blocks'
+			'k:file size in 1024-byte blocks'
+			'd:path depth'
+			'D:device number'
+			'R:device ID for special files'
+			'i:inode number'
+			'I:one space character for every depth level'
+			'p:full path'
+			'P:full path without command line argument prefix'
+			'l:symlink target'
+			'n:number of hardlinks'
+			'F:file indicator type'
+			'f:file basename'
+			'A:atime prefix'
+			'C:ctime prefix'
+			'T:mtime prefix'
+			'm:octal file permissions'
+			'M:ls-style symbolic file permissions'
+			'y:ls-style symbolic file type'
+			'g:group name'
+			'G:numeric gid'
+			'u:user name'
+			'U:numeric uid'
+			'e:number of entries in directories'
+			't:total size used by accepted files'
+			'Y:file system type'
+			'x:extended attributes'
+		)
+		compset -P "*"
+		_describe -t lr-format-specifiers 'format specifier' specs -S ''
+	else
+		_wanted lr-format-specifiers expl 'format specifier' compadd -S '' %
+	fi
+	return 0
+}
+
+_lr_order() {
+	local -a specs
+	specs=(
+		'a:atime'
+		'c:ctime'
+		'd:path depth'
+		'e:file extension'
+		'i:inode number'
+		'm:mtime'
+		'n:file name'
+		'p:directory name'
+		's:file size'
+		't:file type'
+		'v:file name as version number'
+		'A:atime (reversed)'
+		'C:ctime (reversed)'
+		'D:path depth (reversed)'
+		'E:file extension (reversed)'
+		'I:inode number (reversed)'
+		'M:mtime (reversed)'
+		'N:file name (reversed)'
+		'P:directory name (reversed)'
+		'S:file size (reversed)'
+		'T:file type (reversed)'
+		'V:file name as version number (reversed)'
+	)
+	compset -P "*"
+	_describe -t lr-order-specifiers 'order specifier' specs -S ''
+	return 0
+}
+
+if (( words[(I)-l] )); then
+	local timeopt='-T+[show time]:time:((A\:access\ time C\:inode\ change\ time M\:file\ modification\ time))'
+fi
+
+_arguments -S : \
+	'(-F -l -S -f)-0[output filenames NUL-separated]' \
+	'(-0 -l -S -f)-F[output filenames with type indicator]' \
+	'(-0 -F -S -f)-l[long output]' \
+	'(-0 -F -l -f)-S[stat(1)-like output]' \
+	'(-0 -F -l -S)-f[output with custom format]:format:_lr_format' \
+	$timeopt \
+	'-D[use depth-first traversal]' \
+	'(-L)-H[only follow symlinks on command line]' \
+	'(-H)-L[follow all symlinks]' \
+	'-1[don'\''t go below one level of directories]' \
+	'-A[don'\''t list files starting with a dot]' \
+	'-Q[don'\''t shell quote file names]' \
+	'-d[don'\''t enter directories]' \
+	'-G[colorize output]' \
+	'-h[print human readable size]' \
+	'-s[strip directory prefix passed on command line]' \
+	'-x[don'\''t enter other filesystems]' \
+	'(-o)-U[don'\''t sort results]' \
+	'(-U)-o[sort order]:order:_lr_order' \
+	'*-t[test expression]:test: ' \
+	'*:files:_files'