-
Notifications
You must be signed in to change notification settings - Fork 0
/
swap_completion.bash
48 lines (46 loc) · 1.02 KB
/
swap_completion.bash
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
_swap() {
CUR="${COMP_WORDS[COMP_CWORD]}"
PREV="${COMP_WORDS[COMP_CWORD-1]}"
case "$PREV" in
-s | --socket)
# list the names of all sockets that are not just <pid>.sock
COMPREPLY=( \
$(compgen -W "$( \
\ls -1 /run/user/$UID/swapify 2>/dev/null \
| grep -Ev "^[0-9]+\.sock" \
)" -- "$CUR" ) \
)
return 0
;;
-a | --action)
COMPREPLY=( $(compgen -W "swap unswap exit" -- "$CUR") )
return 0
;;
-p | --pid)
# list the pids that we can find sockets for
COMPREPLY=( $(compgen -W "$( \
\ls -1 /run/user/$UID/swapify 2>/dev/null \
| grep -E "^[0-9]+\.sock" \
| cut -d '.' -f 1 \
)" -- "$CUR") )
return 0
;;
-P | --socket-path)
_filedir
return 0
;;
*)
COMPREPLY=( $(compgen \
-W "-h -a -p -s -P -f --help --action --pid --socket --socket-path --force
$(
\ls -1 /run/user/$UID/swapify 2>/dev/null \
| grep -E "^[0-9]+\.sock" \
| cut -d '.' -f 1)" \
-- "$CUR" ) \
)
return 0
;;
esac
}
complete -F _swap swap
complete -c swapify