File: kthresher.bash_completion

package info (click to toggle)
kthresher 1.4.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 172 kB
  • sloc: python: 408; makefile: 5; sh: 2
file content (62 lines) | stat: -rw-r--r-- 1,713 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
# bash completion for kthresher                            -*- shell-script -*-
#
# Copyright 2015-2018 Tony Garcia
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

containsElement()
{
  # 0 if string in $1 is in the array
  # 1 if not
  local e
  for e in "${@:2}"; do
    if [[ "${e}" == "${1}" ]]; then
        return 0
    fi
  done
  return 1
}

genOpts()
{
  local OLDIFS
  local IFS
  local not_used=""
  # options in pairs
  local opts="--help,-h --config,-c --dry-run,-d --headers,-H --keep,-k --purge,-p "
  opts+="--show-autoremoval,-s --verbose,-v --version,-V"
  for i in ${opts} ; do
    OLDIFS=${IFS}
    # set IFS to split our pairs
    IFS=","
    set -- ${i}``
    # reset IFS to original value
    IFS=${OLDIFS}
    if ! $( containsElement "${1}" "${COMP_WORDS[@]}" ) && \
       ! $( containsElement "${2}" "${COMP_WORDS[@]}" ); then
         not_used="${not_used} ${1}"
         not_used="${not_used} ${2}"
    fi
  done
  echo "${not_used}"
}

_kthresher()
{
    local cur=${COMP_WORDS[COMP_CWORD]}
    local prev=${COMP_WORDS[COMP_CWORD-1]}
    #echo "Genopts $(genOpts) COMP_WORDS ${COMP_WORDS[@]}"
    COMPREPLY=( $(compgen -W "$(genOpts)" -- ${cur} ) )
}

complete -F _kthresher kthresher