Skip to content

Commit 7f37e41

Browse files
VorpalBladetavianator
authored andcommitted
Add basic zsh completion
Fixes #32.
1 parent f2cb221 commit 7f37e41

2 files changed

Lines changed: 175 additions & 0 deletions

File tree

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,10 +283,13 @@ install:
283283
$(INSTALL) -m644 bfs.1 $(DESTDIR)$(MANDIR)/man1/bfs.1
284284
$(MKDIR) $(DESTDIR)$(PREFIX)/share/bash-completion/completions
285285
$(INSTALL) -m644 completions/bfs.bash $(DESTDIR)$(PREFIX)/share/bash-completion/completions/bfs
286+
$(MKDIR) $(DESTDIR)$(PREFIX)/share/zsh/site-functions
287+
$(INSTALL) -m644 completions/bfs.zsh $(DESTDIR)$(PREFIX)/share/zsh/site-functions/_bfs
286288
.PHONY: install
287289

288290
uninstall:
289291
$(RM) $(DESTDIR)$(PREFIX)/share/bash-completion/completions/bfs
292+
$(RM) $(DESTDIR)$(PREFIX)/share/zsh/site-functions/_bfs
290293
$(RM) $(DESTDIR)$(MANDIR)/man1/bfs.1
291294
$(RM) $(DESTDIR)$(PREFIX)/bin/bfs
292295
.PHONY: uninstall

completions/bfs.zsh

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
#compdef bfs
2+
# Based on standard zsh find completion and bfs bash completion.
3+
4+
local curcontext="$curcontext" state_descr variant default ret=1
5+
local -a state line args alts disp smatch
6+
7+
args=(
8+
# Flags
9+
'(-depth)-d[search in post-order (descendents first)]'
10+
'-D[print diagnostics]:debug option:(cost exec opt rates search stat time tree all help)'
11+
'-E[use extended regular expressions with -regex/-iregex]'
12+
'-f[specify file hierarchy to traverse]:path:_directories'
13+
'-O+[enable query optimisation]:level:(1 2 3)'
14+
'-s[traverse directories in sorted order]'
15+
'-X[warn if filename contains characters special to xargs]'
16+
"-x[don't span filesystems]"
17+
'(-H -L)-P[never follow symlinks]'
18+
'(-H -P)-L[follow symlinks]'
19+
'(-L -P)-H[only follow symlinks when resolving command-line arguments]'
20+
"-S[select search method]:value:(bfs dfs ids eds)"
21+
'-f[treat path as path to search]:path:_files -/'
22+
23+
# Operators
24+
'*-and'
25+
'*-not'
26+
'*-or'
27+
'*-a' '*-o'
28+
29+
# Special forms
30+
'*-exclude[exclude paths matching EXPRESSION from search]'
31+
32+
# Options
33+
'(-nocolor)-color[turn on colors]'
34+
'(-color)-nocolor[turn off colors]'
35+
'*-daystart[measure times relative to start of today]'
36+
'(-d)*-depth[search in post-order (descendents first)]'
37+
'-files0-from[search NUL separated paths from FILE]:file:_files'
38+
'*-follow[follow all symbolic links (same as -L)]'
39+
'*-ignore_readdir_race[report an error if bfs detects file tree is modified during search]'
40+
'*-noignore_readdir_race[do not report an error if bfs detects file tree is modified during search]'
41+
'*-maxdepth[ignore files deeper than N]:maximum search depth'
42+
'*-mindepth[ignore files shallower than N]:minimum search depth'
43+
"*-mount[don't descend into other mount points]"
44+
'*-nohidden[exclude hidden files]'
45+
'*-noleaf[ignored, for compatibility with GNU find]'
46+
'-regextype[type of regex to use, default posix-basic]:regexp syntax:(help posix-basic posix-extended ed emacs grep sed)'
47+
'*-status[display a status bar while searching]'
48+
'-unique[skip any files that have already been seen]'
49+
'*-warn[turn on warnings about the command line]'
50+
'*-nowarn[turn off warnings about the command line]'
51+
"*-xdev[don't descend into other mount points]"
52+
53+
# Tests
54+
'*-acl[find files with a non-trivial Access Control List]'
55+
'*-amin[find files accessed N minutes ago]:access time (minutes):'
56+
'*-anewer[find files accessed more recently than FILE was modified]:file to compare (access time):_files'
57+
'*-asince[find files accessed more recently than TIME]:time:'
58+
'*-atime[find files accessed N days ago]:access time (days):->times'
59+
60+
'*-Bmin[find files birthed N minutes ago]:birth time (minutes):'
61+
'*-Bnewer[find files birthed more recently than FILE was modified]:file to compare (birth time):_files'
62+
'*-Bsince[find files birthed more recently than TIME]:time:'
63+
'*-Btime[find files birthed N days ago]:birth time (days):->times'
64+
65+
'*-cmin[find files changed N minutes ago]:inode change time (minutes):'
66+
'*-cnewer[find files changed more recently than FILE was modified]:file to compare (inode change time):_files'
67+
'*-csince[find files changed more recently than TIME]:time:'
68+
'*-ctime[find files changed N days ago]:inode change time (days):->times'
69+
70+
'*-mmin[find files modified N minutes ago]:modification time (minutes):'
71+
'*-mnewer[find files modified more recently than FILE was modified]:file to compare (modification time):_files'
72+
'*-msince[find files modified more recently than TIME]:time:'
73+
'*-mtime[find files modified N days ago]:modification time (days):->times'
74+
75+
'*-capable[find files with POSIX.1e capabilities set]'
76+
# -depth without parameters exist above. I don't know how to handle this gracefully
77+
'*-empty[find empty files/directories]'
78+
'*-executable[find files the current user can execute]'
79+
'*-readable[find files the current user can read]'
80+
'*-writable[find files the current user can write]'
81+
'*-false[always false]'
82+
'*-true[always true]'
83+
'*-fstype[find files on file systems with the given type]:file system type:_file_systems'
84+
85+
'*-gid[find files owned by group ID N]:numeric group ID:'
86+
'*-group[find files owned by group NAME]:group:_groups'
87+
'*-uid[find files owned by user ID N]:numeric user ID'
88+
'*-user[find files owned by user NAME]:user:_users'
89+
'*-hidden[find hidden files (those beginning with .)]'
90+
91+
'*-ilname[find symbolic links whose target matches GLOB (case insensitve)]:link pattern to search (case insensitive):'
92+
'*-iname[find files whose name matches GLOB (case insensitive)]:name pattern to match (case insensitive):'
93+
'*-inum[find files with inode number N]:inode number:'
94+
'*-ipath[find files whose entire path matches GLOB (case insenstive)]:path pattern to search (case insensitive):'
95+
'*-iregex[find files whose entire path matches REGEX (case insenstive)]:regular expression to search (case insensitive):'
96+
'*-iwholename[find files whose entire path matches GLOB (case insensitive)]:full path pattern to search (case insensitive):'
97+
98+
'*-links[find files with N hard links]:number of links:'
99+
'*-lname[find symbolic links whose target matches GLOB]:link pattern to search'
100+
'*-name[find files whose name matches GLOB]:name pattern'
101+
'*-newer[find files newer than FILE]:file to compare (modification time):_files'
102+
'*-newer'{a,B,c,m}{a,B,c,m}'[find files where timestamp 1 is newer than timestamp 2 of reference FILE]:reference file:_files'
103+
'*-newer'{a,B,c,m}t'[find files where timestamp is newer than timestamp given as parameter]:timestamp:'
104+
'*-nogroup[find files with nonexistent owning group]'
105+
'*-nouser[find files with nonexistent owning user]'
106+
'*-path[find files whose entire path matches GLOB]:path pattern to search:'
107+
'*-wholename[find files whose entire path matches GLOB]:full path pattern to search:'
108+
109+
'*-perm[find files with a matching mode]: :_file_modes'
110+
'*-regex[find files whose entire path matches REGEX]:regular expression to search:'
111+
'*-samefile[find hard links to FILE]:file to compare inode:_files'
112+
'*-since[files modified since TIME]:time:'
113+
'*-size[find files with the given size]:file size (blocks):'
114+
'*-sparse[find files that occupy fewer disk blocks than expected]'
115+
'*-type[find files of the given type]:file type:((b\:block\ device c\:character\ device d\:directory p\:named\ pipe f\:normal\ file l\:symbolic\ link s\:socket w\:whiteout D\:Door))'
116+
'*-used[find files last accessed N days after they were changed]:access after inode change (days)'
117+
'*-xattr[find files with extended attributes]'
118+
'*-xattrname[find files with extended attribute NAME]:name:'
119+
'*-xtype[find files of the given type following links when -type would not, and vice versa]:file type:((b\:block\ device c\:character\ device d\:directory p\:named\ pipe f\:normal\ file l\:symbolic\ link s\:socket w\:whiteout D\:Door))'
120+
121+
# Actions
122+
'*-delete[delete any found files (-implies -depth)]'
123+
'*-rm[delete any found files (-implies -depth)]'
124+
125+
'*-exec[execute a command]:program: _command_names -e:*(\;|+)::program arguments: _normal'
126+
'*-execdir[execute a command in the same directory as the found files]:program: _command_names -e:*(\;|+)::program arguments: _normal'
127+
'*-ok[prompt the user whether to execute a command]:program: _command_names -e:*(\;|+)::program arguments: _normal'
128+
'*-okdir[prompt the user whether to execute a command in the same directory as the found files]:program: _command_names -e:*(\;|+)::program arguments: _normal'
129+
130+
'-exit[exit with status if found, default 0]'
131+
'*-fls[list files like ls -dils, but write to FILE instead of standard output]:output file:_files'
132+
'*-fprint[print the path to the found file, but write to FILE instead of standard output]:output file:_files'
133+
'*-fprint0[print the path to the found file using null character as separator, but write to FILE instead of standard output]:output file:_files'
134+
'*-fprintf[print according to format string, but write to FILE instead of standard output]:output file:_files:output format'
135+
136+
'*-ls[list files like ls -dils]'
137+
'*-print[print the path to the found file]'
138+
'*-print0[print the path to the found file using null character as separator]'
139+
'*-printf[print according to format string]:output format'
140+
'*-printx[like -print but escapes whitespace and quotation marks]'
141+
"*-prune[don't descend into this directory]"
142+
143+
'*-quit[quit immediately]'
144+
'(- *)-help[print usage information]'
145+
'(-)--help[print usage information]'
146+
'(- *)-version[print version information]'
147+
'(-)--version[print version information]'
148+
149+
'(--help --version)*:other:{_alternative "directories:directory:_files -/" "logic:logic:(, ! \( \) )"}'
150+
)
151+
152+
_arguments -C $args && ret=0
153+
154+
if [[ $state = times ]]; then
155+
if ! compset -P '[+-]' || [[ -prefix '[0-9]' ]]; then
156+
compstate[list]+=' packed'
157+
if zstyle -t ":completion:${curcontext}:senses" verbose; then
158+
zstyle -s ":completion:${curcontext}:senses" list-separator sep || sep=--
159+
default=" [default exactly]"
160+
disp=( "- $sep before" "+ $sep since" )
161+
smatch=( - + )
162+
else
163+
disp=( before exactly since )
164+
smatch=( - '' + )
165+
fi
166+
alts=( "senses:sense${default}:compadd -V times -S '' -d disp -a smatch" )
167+
fi
168+
alts+=( "times:${state_descr}:_dates -f d" )
169+
_alternative $alts && ret=0
170+
fi
171+
172+
return ret

0 commit comments

Comments
 (0)