forked from RobSis/zsh-completion-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzsh-completion-generator.plugin.zsh
executable file
·61 lines (50 loc) · 1.34 KB
/
zsh-completion-generator.plugin.zsh
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
#!/usr/bin/env zsh
#date +%H:%M:%S.%N
# Parse getopt-style help texts for options
# and generate zsh(1) completion functions.
# http://github.com/RobSis/zsh-completion-generator
SCRIPT_SOURCE=${0:A:h}
if [ -z $GENCOMPL_FPATH ]; then
directory="$SCRIPT_SOURCE/completions"
else
directory="$GENCOMPL_FPATH"
fi
# don't overwrite existing functions
fpath=($fpath $directory)
# which python to use
if [ -z $GENCOMPL_PY ]; then
python=python
else
python=$GENCOMPL_PY
fi
mkdir -p $directory
# define default programs here:
programs=( "cat" "nl" "tr" "df --help" )
for prg in "${programs[@]}"; do
name=$prg
help=--help
if [[ $prg =~ " " ]]; then
i=( "${(s/ /)prg}" )
name=$i[1]
if [ -n "$i[2]" ]; then
help="$i[2]"
fi
fi
test -f $directory/_$name ||\
$name $help 2>&1 | $python $SCRIPT_SOURCE/help2comp.py $name > $directory/_$name || rm -f $directory/_$name
done
# or use function in shell:
gencomp() {
if [ -z "$1" ]; then
echo "Usage: gencomp program [--argument-for-help-text]"
echo
return 1
fi
help=--help
if [ -n "$2" ]; then
help=$2
fi
$1 $help 2>&1 | $python $SCRIPT_SOURCE/help2comp.py $1 > $directory/_$1 || ( rm -f $directory/_$1 &&\
echo "No options found for '$1'." )
}
#date +%H:%M:%S.%N # profiling info