-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtinyurl.bash.in
More file actions
44 lines (37 loc) · 1.06 KB
/
tinyurl.bash.in
File metadata and controls
44 lines (37 loc) · 1.06 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
# ----------------------------------------------------------------------------
# "THE BEER-WARE LICENSE" (Revision 42):
# <josh@slashdev.ca> wrote this file. As long as you retain this notice you
# can do whatever you want with this stuff. If we meet some day, and you think
# this stuff is worth it, you can buy me a beer in return Josh Kropf
# ----------------------------------------------------------------------------
DATA_DIR=@DATA_DIR@
_tinyurl() {
local cur prev cmds
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
cmds="help del rm add list ls"
if [ ${#COMP_WORDS[@]} -gt 3 ]; then
return 1
fi
case "${prev}" in
help|list)
;;
del|rm)
links=$(ls ${DATA_DIR})
COMPREPLY=($(compgen -W "${links}" -- ${cur}))
;;
add)
if [[ ${cur} != "http://*" ]]; then
COMPREPLY=("http://")
fi
;;
*)
COMPREPLY=($(compgen -W "${cmds}" -- ${cur}))
# append space to each command
COMPREPLY=("${COMPREPLY[@]/%/ }")
;;
esac
return 0
}
complete -o nospace -F _tinyurl tinyurl