aboutsummaryrefslogtreecommitdiff
path: root/completions/bash/swayidle
blob: a0cdc8b284d5d49885e3760f4f6d68337b0ea9a3 (plain)
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
# swaymsg(1) completion

_swayidle()
{
  local cur prev
  _get_comp_words_by_ref -n : cur prev
  local prev2=${COMP_WORDS[COMP_CWORD-2]}
  local prev3=${COMP_WORDS[COMP_CWORD-3]}

  events=(
    'timeout'
    'before-sleep'
  )

  short=(
    -h
    -d
  )

  if [ "$prev" = timeout ]; then
    # timeout <timeout>
    return
  elif [ "$prev2" = timeout ]; then
    # timeout <timeout> <timeout command>
    COMPREPLY=($(compgen -c -- "$cur"))
    return
  elif [ "$prev3" = timeout ]; then
    # timeout <timeout> <timeout command> [resume <resume command>]
    COMPREPLY=(resume)
    # optional argument; no return here as user may skip 'resume'
  fi

  case "$prev" in
    resume)
      COMPREPLY=($(compgen -c -- "$cur"))
      return
      ;;
    before-sleep)
      COMPREPLY=($(compgen -c -- "$cur"))
      return
      ;;
  esac

  COMPREPLY+=($(compgen -W "${events[*]}" -- "$cur"))
  COMPREPLY+=($(compgen -W "${short[*]}" -- "$cur"))

} &&
complete -F _swayidle swayidle