diff options
Diffstat (limited to 'src/bash_completion/firejail.bash_completion.in')
-rw-r--r-- | src/bash_completion/firejail.bash_completion.in | 118 |
1 files changed, 118 insertions, 0 deletions
diff --git a/src/bash_completion/firejail.bash_completion.in b/src/bash_completion/firejail.bash_completion.in new file mode 100644 index 000000000..f68edf380 --- /dev/null +++ b/src/bash_completion/firejail.bash_completion.in | |||
@@ -0,0 +1,118 @@ | |||
1 | # bash completion for firejail -*- shell-script -*- | ||
2 | #******************************************************************** | ||
3 | # Script based on completions/configure script in bash-completion package in | ||
4 | # Debian. The original package is release under GPL v2 license, the webpage is | ||
5 | # http://bash-completion.alioth.debian.org | ||
6 | #******************************************************************* | ||
7 | |||
8 | __interfaces(){ | ||
9 | cut -f 1 -d ':' /proc/net/dev | tail -n +3 | grep -v lo | xargs | ||
10 | } | ||
11 | |||
12 | _profiles() { | ||
13 | if [[ -d "$1" ]] ; then | ||
14 | ls -1 $1/*.profile 2>/dev/null | sed -E 's;^.*\/;;g' | ||
15 | fi | ||
16 | } | ||
17 | _all_profiles() { | ||
18 | local sys_profiles=$(_profiles _SYSCONFDIR_/firejail) | ||
19 | local user_profiles=$(_profiles $HOME/.config/firejail) | ||
20 | COMPREPLY=($(compgen -W "${sys_profiles} ${user_profiles}" -- "$cur")) | ||
21 | } | ||
22 | |||
23 | |||
24 | _firejail() | ||
25 | { | ||
26 | local cur prev words cword split | ||
27 | _init_completion -s || return | ||
28 | |||
29 | case $prev in | ||
30 | --help|--version|-debug-caps|--debug-syscalls|--debug-syscalls32|--list|--tree|--top|--join|--shutdown) | ||
31 | return 0 | ||
32 | ;; | ||
33 | --profile) | ||
34 | _all_profiles | ||
35 | return 0 | ||
36 | ;; | ||
37 | --hosts-file) | ||
38 | _filedir | ||
39 | return 0 | ||
40 | ;; | ||
41 | --chroot) | ||
42 | _filedir -d | ||
43 | return 0 | ||
44 | ;; | ||
45 | --cgroup) | ||
46 | _filedir -d | ||
47 | return 0 | ||
48 | ;; | ||
49 | --tmpfs) | ||
50 | _filedir | ||
51 | return 0 | ||
52 | ;; | ||
53 | --blacklist) | ||
54 | _filedir | ||
55 | return 0 | ||
56 | ;; | ||
57 | --noblacklist) | ||
58 | _filedir | ||
59 | return 0 | ||
60 | ;; | ||
61 | --whitelist) | ||
62 | _filedir | ||
63 | return 0 | ||
64 | ;; | ||
65 | --nowhitelist) | ||
66 | _filedir | ||
67 | return 0 | ||
68 | ;; | ||
69 | --read-only) | ||
70 | _filedir | ||
71 | return 0 | ||
72 | ;; | ||
73 | --read-write) | ||
74 | _filedir | ||
75 | return 0 | ||
76 | ;; | ||
77 | --bind) | ||
78 | _filedir | ||
79 | return 0 | ||
80 | ;; | ||
81 | --private) | ||
82 | _filedir | ||
83 | return 0 | ||
84 | ;; | ||
85 | --netfilter) | ||
86 | _filedir | ||
87 | return 0 | ||
88 | ;; | ||
89 | --shell) | ||
90 | _filedir | ||
91 | return 0 | ||
92 | ;; | ||
93 | --net) | ||
94 | comps=$(__interfaces) | ||
95 | COMPREPLY=( $(compgen -W '$comps' -- "$cur") ) | ||
96 | return 0 | ||
97 | ;; | ||
98 | esac | ||
99 | |||
100 | $split && return 0 | ||
101 | |||
102 | # if $COMP_CONFIGURE_HINTS is not null, then completions of the form | ||
103 | # --option=SETTING will include 'SETTING' as a contextual hint | ||
104 | [[ "$cur" != -* ]] && _command && return 0 | ||
105 | |||
106 | if [[ -n $COMP_CONFIGURE_HINTS ]]; then | ||
107 | COMPREPLY=( $( compgen -W "$( $1 --help 2>&1 | \ | ||
108 | awk '/^ --[A-Za-z]/ { print $1; \ | ||
109 | if ($2 ~ /--[A-Za-z]/) print $2 }' | sed -e 's/[[,].*//g' )" \ | ||
110 | -- "$cur" ) ) | ||
111 | [[ $COMPREPLY == *=* ]] && compopt -o nospace | ||
112 | else | ||
113 | COMPREPLY=( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) ) | ||
114 | [[ $COMPREPLY == *= ]] && compopt -o nospace | ||
115 | fi | ||
116 | |||
117 | } && | ||
118 | complete -F _firejail firejail | ||