File: fapolicyd.bash_completion

package info (click to toggle)
fapolicyd 1.4.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,328 kB
  • sloc: ansic: 15,255; makefile: 268; sh: 132; python: 26
file content (167 lines) | stat: -rw-r--r-- 4,258 bytes parent folder | download
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# fapolicyd-cli (8) completion                             -*- shell-script -*-

_fapolicydcli()
{
	local cur prev opts
	local word i
	COMPREPLY=()
	cur="${COMP_WORDS[COMP_CWORD]}"
	prev="${COMP_WORDS[COMP_CWORD-1]}"
	opts="--check-config --check-path --check-status --check-trustdb \
		--check-watch_fs --check-ignore_mounts --delete-db --dump-db \
		--file --filter --ftype --help --list --update --reload-rules \
		--test-filter --trust-file --verbose -h -d -D -f -t -l -u -r"

	# Handle file management subcommands specially so we can complete file paths
	local file_mode=false subcmd="" have_path=0 filter_used=0 trust_used=0
	for word in "${COMP_WORDS[@]}"; do
		if [[ ${word} == --file || ${word} == -f ]]; then
			file_mode=true
		fi
	done

	if ${file_mode}; then
		for ((i = 1; i < ${#COMP_WORDS[@]}; i++)); do
			word=${COMP_WORDS[$i]}
			if [[ ${word} == --filter ]]; then
				filter_used=1
				continue
			fi
			if [[ ${word} == --trust-file ]]; then
				trust_used=1
				i=$((i+1))
				continue
			fi
			if [[ -z ${subcmd} && ( ${word} == add || ${word} == delete || ${word} == update ) ]]; then
				subcmd=${word}
				continue
			fi
			if [[ -n ${subcmd} && ${word} != -* && ${word} != add && ${word} != delete && ${word} != update ]]; then
				have_path=1
			fi
		done

		if [[ ${prev} == --trust-file ]]; then
			if [ -e /usr/share/bash-completion/bash_completion ] ; then
				_filedir
			else
				compopt -o filenames 2>/dev/null
				COMPREPLY=( $(compgen -f -- ${cur}) )
			fi
			return 0
		fi

		if [[ -z ${subcmd} ]]; then
			COMPREPLY=($(compgen -W 'add delete update' -- "${cur}"))
			return 0
		fi

		if [[ ${prev} == ${subcmd} || ( ${have_path} -eq 0 && ${cur} != -* && ${prev} != --filter ) ]]; then
			if [ -e /usr/share/bash-completion/bash_completion ] ; then
				_filedir
			else
				compopt -o filenames 2>/dev/null
				COMPREPLY=( $(compgen -f -- ${cur}) )
			fi
			return 0
		fi

		local file_opts=""
		[[ ${filter_used} -eq 0 ]] && file_opts="${file_opts} --filter"
		[[ ${trust_used} -eq 0 ]] && file_opts="${file_opts} --trust-file"
		if [[ -n ${file_opts} && ( -z ${cur} || ${cur} == -* ) ]]; then
			COMPREPLY=($(compgen -W "${file_opts}" -- "${cur}"))
			[[ ${COMPREPLY-} == *= ]] && compopt -o nospace
			return 0
		fi
	fi

	case $prev in
		--ftype|-t|--test-filter)
			# If bash completions is installed, use it
			if [ -e /usr/share/bash-completion/bash_completion ] ; then
				_filedir
				return 0
			else	# this is almost as good
				compopt -o filenames 2>/dev/null
				COMPREPLY=( $(compgen -f -- ${cur}) )
				return 0
			fi
		;;
		--check-ignore_mounts)
			if [ -e /usr/share/bash-completion/bash_completion ] ; then
				_filedir -d
				return 0
			else
				compopt -o dirnames 2>/dev/null
				COMPREPLY=( $(compgen -d -- ${cur}) )
				return 0
			fi
		;;
		--file|-f)
			COMPREPLY=($(compgen -W 'add delete update' -- "$cur"))
			return 0
		;;
		add|update|delete)
			COMPREPLY=($(compgen -W '--filter --trust-file' -- "$cur"))
			[[ ${COMPREPLY-} == *= ]] && compopt -o nospace
			return 0
		;;
		--filter)
			if [ -e /usr/share/bash-completion/bash_completion ] ; then
				_filedir
			else
				compopt -o filenames 2>/dev/null
				COMPREPLY=( $(compgen -f -- ${cur}) )
			fi
			return 0
		;;
		--trust-file)
			if [ -e /usr/share/bash-completion/bash_completion ] ; then
				_filedir
			else
				compopt -o filenames 2>/dev/null
				COMPREPLY=( $(compgen -f -- ${cur}) )
			fi
			return 0
		;;
	esac

	if [[ $cur == -* ]]; then
		COMPREPLY=($(compgen -W "${opts}" -- "$cur"))
		[[ ${COMPREPLY-} == *= ]] && compopt -o nospace
		return 0
	fi
}

_fapolicyd()
{
	local cur prev opts
	COMPREPLY=()
	cur="${COMP_WORDS[COMP_CWORD]}"
	prev="${COMP_WORDS[COMP_CWORD-1]}"
	opts="--debug --debug-deny --help --mounts --no-details --permissive --version"

	case ${prev} in
		--mounts)
			if [ -e /usr/share/bash-completion/bash_completion ] ; then
				_filedir
			else
				compopt -o filenames 2>/dev/null
				COMPREPLY=( $(compgen -f -- ${cur}) )
			fi
			return 0
		;;
	esac

	if [[ ${cur} == -* ]] ; then
		COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
		[[ ${COMPREPLY-} == *= ]] && compopt -o nospace
		return 0
	fi
}

complete -F _fapolicydcli fapolicyd-cli
complete -F _fapolicyd fapolicyd

# ex: filetype=sh