-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompdefs
More file actions
90 lines (81 loc) · 2.1 KB
/
Copy pathcompdefs
File metadata and controls
90 lines (81 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env zsh
#
# Utility functions and aliases for zsh completion definitions
# This file should be sourced (in .zshrc, for example).
# https://github.com/roadkell/script-fu
# Print '_comps' associative array in human-readable form
# https://stackoverflow.com/a/40014760/4773752
comps() {
for command completion in ${(kv)_comps:#-*(-|-,*)}; do
printf "%-32s %s\n" $command $completion
done | sort
}
# The following function is similar to the 'where' builtin, but looks for files
# in $FPATH. It finds functions that are loadable from a file of the same name.
# https://unix.stackexchange.com/a/726854/303129
# https://unix.stackexchange.com/a/421326/303129
whfpath() {
emulate -L zsh
local name locations ret=0
for name; do
locations=($^fpath/$name(N))
if (($#locations != 0)); then
print -Dl -- "${locations[@]}"
else
ret=1
fi
done
return $ret
}
# Same for $PATH
whpath() {
emulate -L zsh
local name locations ret=0
for name; do
locations=($^path/$name(N))
if (($#locations != 0)); then
print -Dl -- "${locations[@]}"
else
ret=1
fi
done
return $ret
}
# Find the compdef file associated with given command
# https://unix.stackexchange.com/a/509944/303129
whcomp() {
whfpath $_comps[$1]
}
# List all compdef files - those in $FPATH, which are named like '_filename'
compdefl() {
emulate -L zsh
local locations
locations=($^fpath/_[^_]*(N))
print -l -- "${locations[@]}" | sort
}
# TODO: add version with filtered out OS-preinstalled compdefs
# Same, but sorted by filename (instead of fullpath) & beautified with 'eza'
compdefs() {
compdefl | xargs eza -laho -F --group-directories-first --color=always --color-scale --icons --hyperlink
}
# Print $FPATH dirs one-by-line
fpaths() {
emulate -L zsh
local locations
locations=($^fpath)
print -l -- "${locations[@]}" | sort
}
# Same for $PATH
paths() {
emulate -L zsh
local locations
locations=($^path)
print -l -- "${locations[@]}" | sort
}
# For colon-separated arrays that don't have zsh-style array counterparts
# https://stackoverflow.com/a/44524309/4773752
colons2newlines() {
while read -rd ':' p; do
echo "$p"
done <<< "$1:"
}