-
-
Notifications
You must be signed in to change notification settings - Fork 74
/
Copy pathtldr
88 lines (78 loc) · 1.49 KB
/
tldr
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
#!/bin/bash
BUILTIN_THEMES="single base16 ocean"
PLATFORM_TYPES="android linux osx sunos windows"
OPTIONS='-v
--version
-l
--list
-a
--list-all
-1
--single-column
-r
--random
-e
--random-example
-f
--render
-m
--markdown
-p
--android
--linux
--osx
--sunos
--windows
-t
--theme
-s
--search
-u
--update
-c
--clear-cache
-h
--help'
function _tldr_autocomplete {
OPTS_NOT_USED=$( comm -23 <( echo "$OPTIONS" | sort ) <( printf '%s\n' "${COMP_WORDS[@]}" | sort ) )
cur="${COMP_WORDS[$COMP_CWORD]}"
COMPREPLY=()
if [[ "$cur" =~ ^-.* ]]
then
COMPREPLY=(`compgen -W "$OPTS_NOT_USED" -- $cur`)
else
if [[ $COMP_CWORD -eq 0 ]]
then
prev=""
else
prev=${COMP_WORDS[$COMP_CWORD-1]}
fi
case "$prev" in
-f|--render)
COMPREPLY=(`compgen -f $cur`)
;;
-p|--platform)
COMPREPLY=(`compgen -W "$PLATFORM_TYPES" $cur`)
;;
-t|--theme)
# No suggestions for these, they take arbitrary values
SUGGESTED_BUILTINS=(`compgen -W "$BUILTIN_THEMES" $cur`)
if [[ ${#SUGGESTED_BUILTINS[@]} -eq 0 ]]
then
COMPREPLY=()
else
COMPREPLY=("<custom theme name>" "${SUGGESTED_BUILTINS[@]}")
fi
;;
-s|--search)
# No suggestions for these, they take arbitrary values
COMPREPLY=("")
;;
*)
sheets=$(tldr -l -1)
COMPREPLY=(`compgen -W "$sheets $OPTS_NOT_USED" -- $cur`)
;;
esac
fi
}
complete -F _tldr_autocomplete tldr