.bash_completion
author Oleksandr Gavenko <gavenkoa@gmail.com>
Thu, 22 Dec 2022 16:47:44 +0200
changeset 1009 3f4f94c38069
parent 1007 0077617b0deb
child 1011 48975083716e
permissions -rw-r--r--
Defined completion for mygradle8 mygradle11 mygradle17.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
318
68363fe03ae4 Add setting for Emacs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 317
diff changeset
     1
# -*- mode: shell-script -*-
150
18b75d04721b Add Completion.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 127
diff changeset
     2
885
bfbd7fdc89f8 https://superuser.com/questions/1247541/make-bash-completion-to-ignore-exe-extention-in-cygwin
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 770
diff changeset
     3
[[ "$OSTYPE" = cygwin ]] && shopt -s completion_strip_exe
bfbd7fdc89f8 https://superuser.com/questions/1247541/make-bash-completion-to-ignore-exe-extention-in-cygwin
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 770
diff changeset
     4
150
18b75d04721b Add Completion.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 127
diff changeset
     5
# user commands see only users
18b75d04721b Add Completion.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 127
diff changeset
     6
complete -u su passwd write chfn groups slay w sux
18b75d04721b Add Completion.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 127
diff changeset
     7
18b75d04721b Add Completion.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 127
diff changeset
     8
# bg completes with stopped jobs
18b75d04721b Add Completion.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 127
diff changeset
     9
complete -A stopped -P '"%' -S '"' bg
18b75d04721b Add Completion.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 127
diff changeset
    10
18b75d04721b Add Completion.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 127
diff changeset
    11
# other job commands
18b75d04721b Add Completion.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 127
diff changeset
    12
complete -j -P '"%' -S '"' fg jobs disown
18b75d04721b Add Completion.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 127
diff changeset
    13
18b75d04721b Add Completion.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 127
diff changeset
    14
# readonly and unset complete with shell variables
18b75d04721b Add Completion.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 127
diff changeset
    15
complete -v readonly unset
18b75d04721b Add Completion.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 127
diff changeset
    16
18b75d04721b Add Completion.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 127
diff changeset
    17
# set completes with set options
18b75d04721b Add Completion.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 127
diff changeset
    18
complete -A setopt set
18b75d04721b Add Completion.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 127
diff changeset
    19
18b75d04721b Add Completion.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 127
diff changeset
    20
# shopt completes with shopt options
18b75d04721b Add Completion.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 127
diff changeset
    21
complete -A shopt shopt
18b75d04721b Add Completion.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 127
diff changeset
    22
18b75d04721b Add Completion.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 127
diff changeset
    23
# helptopics
18b75d04721b Add Completion.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 127
diff changeset
    24
complete -A helptopic help
18b75d04721b Add Completion.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 127
diff changeset
    25
18b75d04721b Add Completion.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 127
diff changeset
    26
# unalias completes with aliases
18b75d04721b Add Completion.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 127
diff changeset
    27
complete -a unalias
18b75d04721b Add Completion.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 127
diff changeset
    28
18b75d04721b Add Completion.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 127
diff changeset
    29
# bind completes with readline bindings (make this more intelligent)
18b75d04721b Add Completion.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 127
diff changeset
    30
complete -A binding bind
18b75d04721b Add Completion.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 127
diff changeset
    31
18b75d04721b Add Completion.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 127
diff changeset
    32
# type and which complete on commands
18b75d04721b Add Completion.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 127
diff changeset
    33
complete -c command type which
18b75d04721b Add Completion.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 127
diff changeset
    34
18b75d04721b Add Completion.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 127
diff changeset
    35
# builtin completes on builtins
18b75d04721b Add Completion.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 127
diff changeset
    36
complete -b builtin
18b75d04721b Add Completion.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 127
diff changeset
    37
235
3c0d218db7a3 Add completion for hgsyncew.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 231
diff changeset
    38
_hgsyncew() {
239
8f3d4826aec2 Remove '$' sign from arithmetic contexts.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 237
diff changeset
    39
  local cur=${COMP_WORDS[COMP_CWORD]}
770
7bd2639fafaf Add option to _hgsyncew.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 736
diff changeset
    40
  COMPREPLY=( $(compgen -W "--push --modified" -- $cur) )
235
3c0d218db7a3 Add completion for hgsyncew.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 231
diff changeset
    41
  return 0
3c0d218db7a3 Add completion for hgsyncew.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 231
diff changeset
    42
}
3c0d218db7a3 Add completion for hgsyncew.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 231
diff changeset
    43
complete -F _hgsyncew -o nospace hgsyncew
3c0d218db7a3 Add completion for hgsyncew.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 231
diff changeset
    44
1007
0077617b0deb Added completion for hgsync.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 972
diff changeset
    45
_hgsync() {
0077617b0deb Added completion for hgsync.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 972
diff changeset
    46
  local cur=${COMP_WORDS[COMP_CWORD]}
0077617b0deb Added completion for hgsync.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 972
diff changeset
    47
  case $COMP_CWORD in
0077617b0deb Added completion for hgsync.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 972
diff changeset
    48
    0|1)
0077617b0deb Added completion for hgsync.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 972
diff changeset
    49
      COMPREPLY=( $(compgen -W "local remote pull push info --help" -- $cur) )
0077617b0deb Added completion for hgsync.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 972
diff changeset
    50
      compopt +o nospace
0077617b0deb Added completion for hgsync.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 972
diff changeset
    51
      return ;;
0077617b0deb Added completion for hgsync.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 972
diff changeset
    52
    2)
0077617b0deb Added completion for hgsync.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 972
diff changeset
    53
      COMPREPLY=( $(compgen -d -S / -- "$cur") )
0077617b0deb Added completion for hgsync.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 972
diff changeset
    54
      return ;;
0077617b0deb Added completion for hgsync.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 972
diff changeset
    55
    *)
0077617b0deb Added completion for hgsync.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 972
diff changeset
    56
      COMPREPLY=( )
0077617b0deb Added completion for hgsync.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 972
diff changeset
    57
      return ;;
0077617b0deb Added completion for hgsync.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 972
diff changeset
    58
  esac
0077617b0deb Added completion for hgsync.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 972
diff changeset
    59
}
0077617b0deb Added completion for hgsync.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 972
diff changeset
    60
complete -F _hgsync -o nospace hgsync
0077617b0deb Added completion for hgsync.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 972
diff changeset
    61
236
8469af3b5d40 Add completion for 'pathsearch'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 235
diff changeset
    62
_pathsearch() {
239
8f3d4826aec2 Remove '$' sign from arithmetic contexts.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 237
diff changeset
    63
  local prev cur=${COMP_WORDS[COMP_CWORD]}
8f3d4826aec2 Remove '$' sign from arithmetic contexts.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 237
diff changeset
    64
  [[ $COMP_CWORD > 0 ]] && prev=${COMP_WORDS[COMP_CWORD-1]}
236
8469af3b5d40 Add completion for 'pathsearch'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 235
diff changeset
    65
  if [[ $prev = -d ]]; then
8469af3b5d40 Add completion for 'pathsearch'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 235
diff changeset
    66
    COMPREPLY=()
8469af3b5d40 Add completion for 'pathsearch'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 235
diff changeset
    67
    return 0
8469af3b5d40 Add completion for 'pathsearch'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 235
diff changeset
    68
  fi
8469af3b5d40 Add completion for 'pathsearch'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 235
diff changeset
    69
  case "$cur" in
8469af3b5d40 Add completion for 'pathsearch'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 235
diff changeset
    70
    -*) COMPREPLY=( $(compgen -W "-d --delimiter= -h --help" -- $cur ) ) ;;
8469af3b5d40 Add completion for 'pathsearch'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 235
diff changeset
    71
    *) COMPREPLY=() ;;
8469af3b5d40 Add completion for 'pathsearch'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 235
diff changeset
    72
  esac
8469af3b5d40 Add completion for 'pathsearch'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 235
diff changeset
    73
  return 0
8469af3b5d40 Add completion for 'pathsearch'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 235
diff changeset
    74
}
8469af3b5d40 Add completion for 'pathsearch'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 235
diff changeset
    75
complete -F _pathsearch -o nospace pathsearch
8469af3b5d40 Add completion for 'pathsearch'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 235
diff changeset
    76
241
e1e0eeee8d51 Enable completion for man pages and CDPATH.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 240
diff changeset
    77
_mycd() {
e1e0eeee8d51 Enable completion for man pages and CDPATH.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 240
diff changeset
    78
  local cur
972
27754771cbb6 Fixed handling of spaces in path for completion for Bash command "cd".
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 885
diff changeset
    79
  local IFS=$'\n'
241
e1e0eeee8d51 Enable completion for man pages and CDPATH.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 240
diff changeset
    80
  cur=${COMP_WORDS[COMP_CWORD]}
577
50e17493c476 Fix condition syntax and add special case of '~/' path.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 553
diff changeset
    81
  if [[ -z "${CDPATH:-}" ]] || [[ $cur == ?(.)?(.)/* ]] || [[ $cur == '~'/* ]]; then
736
73748dd9a563 Fallback to Readline built-in dir completion implementation to handle
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 638
diff changeset
    82
    compopt -o dirnames; COMPREPLY=()
241
e1e0eeee8d51 Enable completion for man pages and CDPATH.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 240
diff changeset
    83
    return 0
e1e0eeee8d51 Enable completion for man pages and CDPATH.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 240
diff changeset
    84
  fi
253
70b18b0b9e53 Mark variable as local to avoid overwriting global values.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 252
diff changeset
    85
  local i j k
241
e1e0eeee8d51 Enable completion for man pages and CDPATH.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 240
diff changeset
    86
  for i in ${CDPATH//:/$'\n'}; do
255
dc8e50b55c7e Small command usage improvement.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 254
diff changeset
    87
    for j in $( compgen -d -- $i/$cur ); do
638
19faaf3d9d32 Use compound assignment to array instead of manual index updating.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 637
diff changeset
    88
      COMPREPLY+=(${j#$i/}/)
241
e1e0eeee8d51 Enable completion for man pages and CDPATH.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 240
diff changeset
    89
    done
e1e0eeee8d51 Enable completion for man pages and CDPATH.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 240
diff changeset
    90
  done
e1e0eeee8d51 Enable completion for man pages and CDPATH.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 240
diff changeset
    91
  return 0
e1e0eeee8d51 Enable completion for man pages and CDPATH.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 240
diff changeset
    92
}
e1e0eeee8d51 Enable completion for man pages and CDPATH.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 240
diff changeset
    93
complete -F _mycd -o nospace cd
e1e0eeee8d51 Enable completion for man pages and CDPATH.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 240
diff changeset
    94
e1e0eeee8d51 Enable completion for man pages and CDPATH.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 240
diff changeset
    95
_man() {
266
c3dc97f8c1d2 Look in all dirs from $MANPATH when complete man page.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 265
diff changeset
    96
  local p
241
e1e0eeee8d51 Enable completion for man pages and CDPATH.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 240
diff changeset
    97
  local cur=${COMP_WORDS[COMP_CWORD]}
267
180d2b4f3253 Proper handle absolute and local path to man page.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 266
diff changeset
    98
  if [[ $cur = /* || $cur = ./* ]]; then
180d2b4f3253 Proper handle absolute and local path to man page.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 266
diff changeset
    99
    COMPREPLY=( $(compgen -f -- $cur) )
180d2b4f3253 Proper handle absolute and local path to man page.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 266
diff changeset
   100
  fi
266
c3dc97f8c1d2 Look in all dirs from $MANPATH when complete man page.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 265
diff changeset
   101
  local IFS=':
c3dc97f8c1d2 Look in all dirs from $MANPATH when complete man page.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 265
diff changeset
   102
'
c3dc97f8c1d2 Look in all dirs from $MANPATH when complete man page.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 265
diff changeset
   103
  for p in /usr/share/man $MANPATH; do
268
445d013283e6 Proper handle '::' sequences in MANPATH.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 267
diff changeset
   104
    [[ -n $p ]] || continue
266
c3dc97f8c1d2 Look in all dirs from $MANPATH when complete man page.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 265
diff changeset
   105
    p=( $p/man*/* )
c3dc97f8c1d2 Look in all dirs from $MANPATH when complete man page.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 265
diff changeset
   106
    p=( ${p[@]##*/} )
c3dc97f8c1d2 Look in all dirs from $MANPATH when complete man page.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 265
diff changeset
   107
    p=( ${p[@]%.gz} )
c3dc97f8c1d2 Look in all dirs from $MANPATH when complete man page.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 265
diff changeset
   108
    p=( ${p[@]%.*} )
c3dc97f8c1d2 Look in all dirs from $MANPATH when complete man page.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 265
diff changeset
   109
    p=( $(compgen -W '${p[@]}' -- $cur ) )
c3dc97f8c1d2 Look in all dirs from $MANPATH when complete man page.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 265
diff changeset
   110
    COMPREPLY=( ${COMPREPLY[@]} ${p[@]} )
c3dc97f8c1d2 Look in all dirs from $MANPATH when complete man page.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 265
diff changeset
   111
  done
241
e1e0eeee8d51 Enable completion for man pages and CDPATH.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 240
diff changeset
   112
}
e1e0eeee8d51 Enable completion for man pages and CDPATH.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 240
diff changeset
   113
complete -F _man man
e1e0eeee8d51 Enable completion for man pages and CDPATH.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 240
diff changeset
   114
242
a13e9cd16022 Add completion for 'make'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 241
diff changeset
   115
_make() {
253
70b18b0b9e53 Mark variable as local to avoid overwriting global values.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 252
diff changeset
   116
  local i mk
263
9a0fc755c9f9 Make '-C' and '-f' option work together.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 262
diff changeset
   117
  local dir=.
242
a13e9cd16022 Add completion for 'make'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 241
diff changeset
   118
  local cur=${COMP_WORDS[COMP_CWORD]}
263
9a0fc755c9f9 Make '-C' and '-f' option work together.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 262
diff changeset
   119
  if [[ $cur = -* ]]; then
9a0fc755c9f9 Make '-C' and '-f' option work together.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 262
diff changeset
   120
    COMPREPLY=( $(compgen -W "-C -f" -- "$cur") )
242
a13e9cd16022 Add completion for 'make'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 241
diff changeset
   121
    return 0
a13e9cd16022 Add completion for 'make'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 241
diff changeset
   122
  fi
263
9a0fc755c9f9 Make '-C' and '-f' option work together.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 262
diff changeset
   123
  [[ $COMP_CWORD > 0 ]] && prev=${COMP_WORDS[COMP_CWORD-1]}
9a0fc755c9f9 Make '-C' and '-f' option work together.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 262
diff changeset
   124
  for (( i=1; i < ${#COMP_WORDS[@]}-1; i++ )); do
9a0fc755c9f9 Make '-C' and '-f' option work together.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 262
diff changeset
   125
    case ${COMP_WORDS[i]} in
9a0fc755c9f9 Make '-C' and '-f' option work together.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 262
diff changeset
   126
      -f) mk=${COMP_WORDS[i+1]} ;;
9a0fc755c9f9 Make '-C' and '-f' option work together.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 262
diff changeset
   127
      -C) dir=${COMP_WORDS[i+1]} ;;
9a0fc755c9f9 Make '-C' and '-f' option work together.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 262
diff changeset
   128
    esac
9a0fc755c9f9 Make '-C' and '-f' option work together.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 262
diff changeset
   129
  done
262
fd0adcd27f18 Complete dirs for '-C' for make.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 258
diff changeset
   130
  if [[ $prev = -C ]]; then
fd0adcd27f18 Complete dirs for '-C' for make.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 258
diff changeset
   131
    COMPREPLY=( $(compgen -d -- "$cur") )
fd0adcd27f18 Complete dirs for '-C' for make.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 258
diff changeset
   132
    return 0
fd0adcd27f18 Complete dirs for '-C' for make.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 258
diff changeset
   133
  fi
263
9a0fc755c9f9 Make '-C' and '-f' option work together.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 262
diff changeset
   134
  if [[ $prev = -f ]]; then
9a0fc755c9f9 Make '-C' and '-f' option work together.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 262
diff changeset
   135
    COMPREPLY=( $(cd $dir >/dev/null 2>&1; compgen -f -- "$cur") )
9a0fc755c9f9 Make '-C' and '-f' option work together.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 262
diff changeset
   136
    return 0
9a0fc755c9f9 Make '-C' and '-f' option work together.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 262
diff changeset
   137
  fi
9a0fc755c9f9 Make '-C' and '-f' option work together.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 262
diff changeset
   138
  mk=$dir/$mk
9a0fc755c9f9 Make '-C' and '-f' option work together.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 262
diff changeset
   139
  [[ -f $mk ]] || mk=$(eval echo $dir/[Mm]akefile)
9a0fc755c9f9 Make '-C' and '-f' option work together.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 262
diff changeset
   140
  [[ -f $mk ]] || return 1
242
a13e9cd16022 Add completion for 'make'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 241
diff changeset
   141
  COMPREPLY=( $(compgen -W "$(sed -n -e '/^[[:alnum:]_-]*:/{s=^\([^:]*\):.*=\1=;p;}' $mk)" -- $cur) )
a13e9cd16022 Add completion for 'make'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 241
diff changeset
   142
  return 0
a13e9cd16022 Add completion for 'make'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 241
diff changeset
   143
}
a13e9cd16022 Add completion for 'make'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 241
diff changeset
   144
complete -F _make make gmake pmake
a13e9cd16022 Add completion for 'make'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 241
diff changeset
   145
264
ba2b44143421 Add completion for cygcheck.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 263
diff changeset
   146
_cygcheck() {
ba2b44143421 Add completion for cygcheck.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 263
diff changeset
   147
  local opt
ba2b44143421 Add completion for cygcheck.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 263
diff changeset
   148
  local cur=${COMP_WORDS[COMP_CWORD]}
ba2b44143421 Add completion for cygcheck.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 263
diff changeset
   149
  case $COMP_CWORD in
ba2b44143421 Add completion for cygcheck.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 263
diff changeset
   150
    1)
ba2b44143421 Add completion for cygcheck.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 263
diff changeset
   151
      case $cur in
ba2b44143421 Add completion for cygcheck.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 263
diff changeset
   152
        -*)
ba2b44143421 Add completion for cygcheck.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 263
diff changeset
   153
          COMPREPLY=( $(compgen -W "-v --verbose -h --help -V --version -c --check-setup -s --sysinfo
ba2b44143421 Add completion for cygcheck.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 263
diff changeset
   154
            -k --keycheck -f --find-package -l --list-package -p --package-query" -- "$cur") )
ba2b44143421 Add completion for cygcheck.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 263
diff changeset
   155
          return 0 ;;
ba2b44143421 Add completion for cygcheck.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 263
diff changeset
   156
        *)
ba2b44143421 Add completion for cygcheck.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 263
diff changeset
   157
          COMPREPLY=( $(compgen -c -- "$cur") )
ba2b44143421 Add completion for cygcheck.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 263
diff changeset
   158
          return 0 ;;
ba2b44143421 Add completion for cygcheck.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 263
diff changeset
   159
      esac
ba2b44143421 Add completion for cygcheck.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 263
diff changeset
   160
      ;;
ba2b44143421 Add completion for cygcheck.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 263
diff changeset
   161
    2)
ba2b44143421 Add completion for cygcheck.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 263
diff changeset
   162
      opt=${COMP_WORDS[1]}
ba2b44143421 Add completion for cygcheck.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 263
diff changeset
   163
      case $opt in
ba2b44143421 Add completion for cygcheck.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 263
diff changeset
   164
        -c|--check-setup|-l|--list-package)
552
1f489f80b389 Fix variable scope.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 318
diff changeset
   165
          local pkgs=( /etc/setup/*.lst.gz )
264
ba2b44143421 Add completion for cygcheck.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 263
diff changeset
   166
          pkgs=( ${pkgs[@]##*/} )
ba2b44143421 Add completion for cygcheck.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 263
diff changeset
   167
          pkgs=( ${pkgs[@]%.lst.gz} )
ba2b44143421 Add completion for cygcheck.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 263
diff changeset
   168
          COMPREPLY=( $(compgen -W '${pkgs[@]}' -- $cur ) )
ba2b44143421 Add completion for cygcheck.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 263
diff changeset
   169
          return 0;;
ba2b44143421 Add completion for cygcheck.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 263
diff changeset
   170
      esac
ba2b44143421 Add completion for cygcheck.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 263
diff changeset
   171
      return 0;;
ba2b44143421 Add completion for cygcheck.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 263
diff changeset
   172
  esac
ba2b44143421 Add completion for cygcheck.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 263
diff changeset
   173
  return 0
ba2b44143421 Add completion for cygcheck.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 263
diff changeset
   174
}
ba2b44143421 Add completion for cygcheck.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 263
diff changeset
   175
complete -F _cygcheck cygcheck.exe cygcheck
ba2b44143421 Add completion for cygcheck.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 263
diff changeset
   176
553
50b46df6ca28 Add lighty-*-mod completion.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 552
diff changeset
   177
_lighty() {
50b46df6ca28 Add lighty-*-mod completion.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 552
diff changeset
   178
  local cur=${COMP_WORDS[COMP_CWORD]}
50b46df6ca28 Add lighty-*-mod completion.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 552
diff changeset
   179
  local mods=( /etc/lighttpd/conf-available/*.conf )
50b46df6ca28 Add lighty-*-mod completion.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 552
diff changeset
   180
  mods=( ${mods[@]##*/} )
50b46df6ca28 Add lighty-*-mod completion.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 552
diff changeset
   181
  mods=( ${mods[@]#??-} )
50b46df6ca28 Add lighty-*-mod completion.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 552
diff changeset
   182
  mods=( ${mods[@]%.conf} )
50b46df6ca28 Add lighty-*-mod completion.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 552
diff changeset
   183
50b46df6ca28 Add lighty-*-mod completion.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 552
diff changeset
   184
  COMPREPLY=( $(compgen -W '${mods[@]}' -- $cur) )
50b46df6ca28 Add lighty-*-mod completion.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 552
diff changeset
   185
  return 0
50b46df6ca28 Add lighty-*-mod completion.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 552
diff changeset
   186
}
50b46df6ca28 Add lighty-*-mod completion.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 552
diff changeset
   187
50b46df6ca28 Add lighty-*-mod completion.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 552
diff changeset
   188
complete -F _lighty lighty-disable-mod
50b46df6ca28 Add lighty-*-mod completion.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 552
diff changeset
   189
complete -F _lighty lighty-enable-mod
587
b0807924930d Add command aliases.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 577
diff changeset
   190
complete -F _lighty lighttpd-disable-mod
b0807924930d Add command aliases.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 577
diff changeset
   191
complete -F _lighty lighttpd-enable-mod
553
50b46df6ca28 Add lighty-*-mod completion.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 552
diff changeset
   192