Newer
Older
Sebastien Luttringer
committed
Sebastien Luttringer
committed
_local_repo() {
COMPREPLY=("${COMPREPLY[@]}" $(compgen -W "$(is --no-color --no-sync repo --local)" -- "$cur"))
Sebastien Luttringer
committed
}
# list all defined repositories
COMPREPLY=("${COMPREPLY[@]}" $(compgen -W "$(is --no-color --no-sync repo)" -- "$cur"))
}
# list all images available in any online repositories
COMPREPLY=("${COMPREPLY[@]}" $(compgen -W "$(is -q --no-color --no-sync --repo-search '' list)" -- "$cur"))
}
# list all local (files) images
_local_image() {
COMPREPLY=("${COMPREPLY[@]}" $(compgen -f -X '!*.isimage' -- "$cur"))
_local_image
_remote_image
}
# 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'
'extract' 'get' 'help' 'info' 'init' 'install' 'list' 'move' 'new' 'repo'
'search' 'version' 'diff' 'prepare_chroot' 'unprepare_chroot')
opts=('-h' '--help'
'-V' '--version'
'-d' '--debug'
'-q' '--quiet'
'-R' '--repo-config'
'-f' '--repo-filter'
'-s' '--repo-search'
'-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
Sebastien Luttringer
committed
(( args == 2 )) && _local_repo
(( args > 2 )) && _filedir '?(u)isimage'
;;
build)
[[ "$cur" == -* ]] && _opt '-h --help -f --force -p --payload -c --no-check' && return 0
_count_args
(( args == 2 )) && _filedir -d
;;
cat)
[[ "$cur" == -* ]] && _opt '-h --help -b --best' && return 0
_count_args
(( args == 2 )) && _image
;;
changelog)
[[ "$cur" == -* ]] && _opt '-h --help -b --best -v --all-version' && return 0
_image
;;
check)
[[ "$cur" == -* ]] && _opt '-h --help' && return 0
Sebastien Luttringer
committed
_local_repo
;;
chroot)
[[ "$cur" == -* ]] && _opt '-h --help -m --no-mount -s --shell' && return 0
_filedir -d
;;
clean)
[[ "$cur" == -* ]] && _opt '-h --help' && return 0
Sebastien Luttringer
committed
_local_repo
;;
copy)
[[ "$cur" == -* ]] && _opt '-h --help -b --best' && return 0
_count_args
(( args == 2 )) && _remote_image
Sebastien Luttringer
committed
(( args > 2 )) && _remote_image && _local_repo
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
;;
del)
[[ "$cur" == -* ]] && _opt '-h --help -b --best -f --force -p --preserve' && return 0
_remote_image
;;
diff)
[[ "$cur" == -* ]] && _opt '-h --help -b --best' && return 0
_count_args
(( args < 4 )) && _image
;;
extract)
[[ "$cur" == -* ]] && _opt '-h --help -f --force -b --best -p --payload -g --gen-description' && return 0
_count_args
(( args == 2 )) && _image
(( args == 3 )) && _filedir -d
;;
get)
[[ "$cur" == -* ]] && _opt '-h --help -f --force -b --best --payload -I --no-image' && return 0
_remote_image
;;
help)
_count_args
(( args == 2 )) && _opt "${cmds[@]}"
;;
info)
[[ "$cur" == -* ]] && _opt '-v --verbose -c --changelog -b --best' && return 0
_image
;;
init)
[[ "$cur" == -* ]] && _opt '-h --help' && return 0
Sebastien Luttringer
committed
_local_repo
;;
install)
[[ "$cur" == -* ]] && _opt '-b --best' && 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 --all-version -A --author -u --url -D --description' && return 0
_remote_image
;;
move)
[[ "$cur" == -* ]] && _opt '-h --help -b --best -f --force' && return 0
Sebastien Luttringer
committed
_count_args
(( args == 2 )) && _remote_image
(( args > 2 )) && _remote_image && _local_repo
;;
new)
[[ "$cur" == -* ]] && _opt '-h --help -f --force' && return 0
_filedir -d
;;
prepare_chroot)
[[ "$cur" == -* ]] && _opt '-h --help -m --no-mount' && return 0
_filedir -d
;;
repo)
[[ "$cur" == -* ]] && _opt '-h --help -l --local -r --remote -o --online -O --offline -s --state --force-offline --purge -u --url' && return 0
_repo
;;
search)
[[ "$cur" == -* ]] && _opt '-h --help' && return 0
;;
unprepare_chroot)
[[ "$cur" == -* ]] && _opt '-h --help -m --no-mount' && return 0
_filedir -d
;;
version)
[[ "$cur" == -* ]] && _opt '-h --help' && return 0
;;
esac
return 0
# ex: ts=3 sw=3 et filetype=sh