Skip to content
bash-completion 6.29 KiB
Newer Older
# This file is part of Installsystems.
#
# Installsystems is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Installsystems is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Installsystems.  If not, see <http://www.gnu.org/licenses/>.
Sebastien Luttringer's avatar
Sebastien Luttringer committed

# list local repositories
   COMPREPLY=("${COMPREPLY[@]}" $(compgen -W "$(is --quiet --no-color --no-sync repo --local 2>/dev/null)"  -- "$cur"))
Sebastien Luttringer's avatar
Sebastien Luttringer committed
_repo() {
   COMPREPLY=("${COMPREPLY[@]}" $(compgen -W "$(is --quiet --no-color --no-sync repo 2>/dev/null)"  -- "$cur"))
Sebastien Luttringer's avatar
Sebastien Luttringer committed
}

# list all images available in any online repositories
_remote_image() {
   COMPREPLY=("${COMPREPLY[@]}" $(compgen -W "$(is --quiet --no-color --no-sync list '*/*:*' 2>/dev/null)" -- "$cur"))
}

# list all local (files) images
_local_image() {
   COMPREPLY=("${COMPREPLY[@]}" $(compgen -f -X '!*.isimage' -- "$cur"))
}

# list local and remote images
Sebastien Luttringer's avatar
Sebastien Luttringer committed
_image() {
   _local_image
   _remote_image
Sebastien Luttringer's avatar
Sebastien Luttringer committed
}

# generate completion from optional arguments
_opt() {
   COMPREPLY=("${COMPREPLY[@]}" $(compgen -W "$*" -- "${cur}"))
   local cur prev cword
   local -a cmds opts
   COMPREPLY=()
   COMP_WORDBREAKS="${COMP_WORDBREAKS//:}"
   _get_comp_words_by_ref cur prev cword
   _get_first_arg
   cmds=('add' 'build' 'cat' 'changelog' 'check' 'chroot' 'clean' 'copy' 'del'
Aurélien Dunand's avatar
Aurélien Dunand committed
       'extract' 'get' 'help' 'info' 'init' 'install' 'list' 'motd' 'move'
       'new' 'repo' 'search' 'version' 'diff' 'payload' 'prepare_chroot'
       'unprepare_chroot' 'upgrade_db')
   opts=('-h'  '--help'
   '-V'  '--version'
   '-v'  '--verbosity'
   '-d'  '--debug'
   '-q'  '--quiet'
   '-R'  '--repo-config'
   '-f'  '--repo-filter'
   '-r'  '--repo-config'
   '-c'  '--config'
   '-C'  '--cache'
   '-t'  '--timeout'
   '--no-cache'
   '--no-color'
   '--no-sync')
   case "$arg" in
      '')
         [[ "$cur" == -* ]] && _opt "${opts[@]}" || _opt "${cmds[@]}"
      ;;
      add)
         [[ "$cur" == -* ]] && _opt "-h --help -p --preserve" && return 0
         _count_args
         (( args > 2 )) && _filedir '?(u)isimage'
      ;;
      build)
         [[ "$cur" == -* ]] && _opt '-h --help -f --force -p --payload -c --no-check -s --no-script -C --chdir' && return 0
         (( args >= 2 )) && _filedir -d
         [[ "$cur" == -* ]] && _opt '-h --help' && return 0
         _count_args
         (( args == 2 )) && _image
      ;;
      changelog)
         [[ "$cur" == -* ]] && _opt '-h --help -v --all-version' && return 0
         _image
      ;;
      check)
         [[ "$cur" == -* ]] && _opt '-h --help' && return 0
      ;;
      chroot)
         [[ "$cur" == -* ]] && _opt '-h --help -m --no-mount -s --shell' && return 0
         _filedir -d
      ;;
      clean)
         [[ "$cur" == -* ]] && _opt '-h --help -f --force' && return 0
         [[ "$cur" == -* ]] && _opt '-h --help -f --force' && return 0
         _count_args
         (( args == 2 )) && _remote_image
         (( args > 2 )) && _remote_image && _local_repo
         [[ "$cur" == -* ]] && _opt '-h --help -f --force -p --preserve' && return 0
         [[ "$cur" == -* ]] && _opt '-h --help' && return 0
         _count_args
         (( args < 4 )) && _image
      ;;
      extract)
         [[ "$cur" == -* ]] && _opt '-h --help -f --force -p --payload -g --gen-description' && return 0
         _count_args
         (( args == 2 )) && _image
         (( args == 3 )) && _filedir -d
      ;;
      get)
         [[ "$cur" == -* ]] && _opt '-h --help -f --force --payload -I --no-image' && return 0
         _remote_image
      ;;
      help)
         _count_args
         (( args == 2 )) && _opt "${cmds[@]}"
      ;;
      info)
         [[ "$cur" == -* ]] && _opt '-a --all -j --json -c --changelog -f --files -p --payloads' && return 0
         _image
      ;;
      init)
         [[ "$cur" == -* ]] && _opt '-h --help' && return 0
         [[ "$cur" == -* ]] && _opt '--dry-run' && return 0
         _count_args
         (( args == 2 )) && _image
         (( args > 2 )) && _filedir
      ;;
      list)
         [[ "$cur" == -* ]] && _opt '-h --help -l --long -j --json -m --md5 -s --size -d --date -A --author -u --url -D --description -f --format -i --is-min-version' && return 0
Aurélien Dunand's avatar
Aurélien Dunand committed
      motd)
         [[ "$cur" == -* ]] && _opt '-h --help -r --remove -f --files -s --set' && return 0
Aurélien Dunand's avatar
Aurélien Dunand committed
         _repo
      ;;
         [[ "$cur" == -* ]] && _opt '-h --help -f --force' && return 0
         _count_args
         (( args == 2 )) && _remote_image
         (( args > 2 )) && _remote_image && _local_repo
      ;;
      new)
         [[ "$cur" == -* ]] && _opt '-h --help -f --force' && return 0
         _filedir -d
      ;;
      payload)
         [[ "$cur" == -* ]] && _opt '-h --help -j --json -i --images' && return 0
      ;;
      prepare_chroot)
         [[ "$cur" == -* ]] && _opt '-h --help -m --no-mount' && return 0
         _filedir -d
      ;;
         [[ "$cur" == -* ]] && _opt '-h --help -l --local -r --remote -o --online -O --offline -s --state --force-offline --purge -u --url -U --uuid -j --json -v --version' && return 0
         _repo
      ;;
      search)
         [[ "$cur" == -* ]] && _opt '-h --help' && return 0
      ;;
      unprepare_chroot)
         [[ "$cur" == -* ]] && _opt '-h --help -m --no-mount' && return 0
         _filedir -d
      ;;
         [[ "$cur" == -* ]] && _opt '-h --help' && return 0
         _count_args
         (( args == 2 )) && _local_repo
      ;;
      version)
         [[ "$cur" == -* ]] && _opt '-h --help' && return 0
      ;;
   esac
   return 0
Sebastien Luttringer's avatar
Sebastien Luttringer committed
}

complete -F _is is

# ex: ts=3 sw=3 et filetype=sh