File: vips-completion.bash

package info (click to toggle)
vips 8.18.0-2
  • links: PTS
  • area: main
  • in suites: forky
  • size: 53,448 kB
  • sloc: ansic: 172,621; cpp: 12,257; python: 5,077; sh: 773; perl: 40; makefile: 25; javascript: 6
file content (45 lines) | stat: -rw-r--r-- 1,076 bytes parent folder | download | duplicates (4)
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
#/usr/bin/env bash

# bash completions for the "vips" command

# copy to /etc/bash_completion.d to install

_vips_compgen_f()
{
  COMPREPLY=($(compgen -f -- "${COMP_WORDS[-1]}"))

  if [ ${#COMPREPLY[@]} = 1 ]; then
    local LASTCHAR=
    if [ -d "$COMPREPLY" ]; then
      LASTCHAR=/
    fi

    COMPREPLY=$(printf %q%s "$COMPREPLY" "$LASTCHAR")
  else
    for ((i=0; i < ${#COMPREPLY[@]}; i++)); do
      if [ -d "${COMPREPLY[$i]}" ]; then
        COMPREPLY[$i]=${COMPREPLY[$i]}/
      fi
    done
  fi
}

_vips_completions()
{
  if [ ${#COMP_WORDS[@]} == "2" ]; then
    COMPREPLY=($(compgen -W "$(vips -c)" "${COMP_WORDS[1]}"))
  else
    local args=($(vips -c ${COMP_WORDS[1]}))
    local arg_type=${args[${#COMP_WORDS[@]}-3]}
    if [ x$arg_type == x"" ]; then
      COMPREPLY=
    elif [ $arg_type == "file" ]; then
      _vips_compgen_f
    elif [[ $arg_type = word:* ]]; then
      local options=$(echo $arg_type | sed 's/word://' | sed 's/|/ /g')
      COMPREPLY=($(compgen -W "${options[@]}" "${COMP_WORDS[-1]}"))
    fi
  fi
}

complete -F _vips_completions vips