File: projinfo-bash-completion.sh

package info (click to toggle)
proj 9.7.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 43,800 kB
  • sloc: sh: 218,851; cpp: 171,440; sql: 83,614; python: 8,422; ansic: 6,254; yacc: 1,349; makefile: 33
file content (51 lines) | stat: -rw-r--r-- 1,621 bytes parent folder | download | duplicates (2)
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
# Hashbang deliberately missing because this file should be sourced, not executed

function_exists() {
    declare -f -F "$1" > /dev/null
    return $?
}

# Checks that bash-completion is recent enough
function_exists _get_comp_words_by_ref || return 0

_projinfo()
{
  local cur prev
  COMPREPLY=()
  _get_comp_words_by_ref cur prev
  choices=$(projinfo completion ${COMP_LINE})
  if [[ "$cur" == "=" ]]; then
    mapfile -t COMPREPLY < <(compgen -W "$choices" --)
  elif [[ "$cur" == ":" ]]; then
    mapfile -t COMPREPLY < <(compgen -W "$choices" --)
  elif [[ "${cur: -1}" == "/" ]]; then
    mapfile -t COMPREPLY < <(compgen -W "$choices" --)
  elif [[ "${cur: -2}" == "/ " ]]; then
    mapfile -t COMPREPLY < <(compgen -W "$choices" --)
  elif [[ "${cur: -1}" == "+" ]]; then
    mapfile -t COMPREPLY < <(compgen -W "$choices" --)
  elif [[ "${cur: -2}" == "+ " ]]; then
    mapfile -t COMPREPLY < <(compgen -W "$choices" --)
  elif [[ "$cur" == "!" ]]; then
    mapfile -t COMPREPLY < <(compgen -W "$choices" -P "! " --)
  else
    mapfile -t COMPREPLY < <(compgen -W "$choices" -- "$cur")
  fi
  for element in "${COMPREPLY[@]}"; do
    if [[ $element == */ ]]; then
      # Do not add a space if one of the suggestion ends with slash
      compopt -o nospace
      break
    elif [[ $element == *= ]]; then
      # Do not add a space if one of the suggestion ends with equal
      compopt -o nospace
      break
    elif [[ $element == *: ]]; then
      # Do not add a space if one of the suggestion ends with colon
      compopt -o nospace
      break
    fi
  done
}
complete -o default -F _projinfo projinfo