Debian Codegraph @

kthresher.bash_completion

raw
1 # bash completion for kthresher -*- shell-script -*-
2 #
3 # Copyright 2015-2018 Tony Garcia
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 containsElement()
18 {
19 # 0 if string in $1 is in the array
20 # 1 if not
21 local e
22 for e in "${@:2}"; do
23 if [[ "${e}" == "${1}" ]]; then
24 return 0
25 fi
26 done
27 return 1
28 }
29
30 genOpts()
31 {
32 local OLDIFS
33 local IFS
34 local not_used=""
35 # options in pairs
36 local opts="--help,-h --config,-c --dry-run,-d --headers,-H --keep,-k --purge,-p "
37 opts+="--show-autoremoval,-s --verbose,-v --version,-V"
38 for i in ${opts} ; do
39 OLDIFS=${IFS}
40 # set IFS to split our pairs
41 IFS=","
42 set -- ${i}``
43 # reset IFS to original value
44 IFS=${OLDIFS}
45 if ! $( containsElement "${1}" "${COMP_WORDS[@]}" ) && \
46 ! $( containsElement "${2}" "${COMP_WORDS[@]}" ); then
47 not_used="${not_used} ${1}"
48 not_used="${not_used} ${2}"
49 fi
50 done
51 echo "${not_used}"
52 }
53
54 _kthresher()
55 {
56 local cur=${COMP_WORDS[COMP_CWORD]}
57 local prev=${COMP_WORDS[COMP_CWORD-1]}
58 #echo "Genopts $(genOpts) COMP_WORDS ${COMP_WORDS[@]}"
59 COMPREPLY=( $(compgen -W "$(genOpts)" -- ${cur} ) )
60 }
61
62 complete -F _kthresher kthresher