# R overlay -- bash completion for roverlay # -*- coding: utf-8 -*- _roverlay_comp() { local cur local prev COMPREPLY=() _get_comp_words_by_ref cur prev local LONGOPTS=( '--help' '--version' '--config' '--field-definition' '--fdef' '--repo-config' '--deprule-file' '--package-rules' '--overlay' '--overlay-name' '--additions-dir' '--write-overlay' '--write' '--no-write-overlay' '--no-write' '--show-overlay' '--show' '--no-show-overlay' '--no-show' '--strict-sync' '--sync' '--no-sync' '--sync-imports' '--distroot' '--force-distroot' '--local-distdir' '--from' '--incremental' '--no-incremental' '--fixup-category-move' '--fixup-category-move-reverse' '--distmap-verify' '--revbump' '--no-revbump' '--immediate-ebuild-writes' '--manifest' '--no-manifest' '--manifest-implementation' '--pc' '--print-config' '--ppr' '--print-package-rules' '--help-config' '--list-config-entries' '--dump-file' '--strict' '--stats' '--no-stats' '--dump-stats' '--log-level' '--verbose' '--package-revbump' '--package-replace' '--package-replace-only' '--package-list' '--ebuild-list' ) local SHORTOPTS=( '-h' '-V' '-c' '-F' '-R' '-D' '-P' '-O' '-N' '-A' '-M' '-v' ) local CMDARGS=( 'sync' 'create' 'depres' 'depres_console' 'nop' 'apply_rules' 'setupdirs' 'distmap_rebuild' ) local have_command= local k local first=y for k in "${COMP_WORDS[@]}"; do if [[ " ${CMDARGS[*]} " == *" ${k} "* ]] && [[ -z "${first}" ]]; then have_command=y break fi first= done case "${prev}" in '-c'|'--config'|'-F'|'--field-definition'|'--fdef'|\ '-R'|'--repo-config'|'--package-list'|'--ebuild-list') # options with arg _filedir ;; '-O'|'--overlay'|'-A'|'--additions-dir'|'--distroot'|\ '--local-distdir'|'--from') # options with arg _filedir -d ;; '-D'|'--deprule-file'|'-P'|'--package-rules') # options with arg _filedir ;; '--dump-file') # stdout or file _filedir [[ "${cur}" ]] || COMPREPLY+=( "-" ) ;; '-M'|'--manifest-implementation') COMPREPLY=( $(compgen -W "default next ebuild e" -- "${cur}" ) ) ;; '-N'|'--overlay-name'|'--package-'*) # options with str/unspecified arg true ;; '--log-level') COMPREPLY=( $(compgen -W "DEBUG INFO WARN WARNING ERROR CRITICAL" -- "${cur}" ) ) ;; *) case "${cur}" in --*) COMPREPLY=( $( compgen -W "${LONGOPTS[*]}" -- "${cur}" ) ) ;; -*) COMPREPLY=( $( compgen -W "${LONGOPTS[*]} ${SHORTOPTS[*]}" -- "${cur}" ) ) ;; *) local words="${LONGOPTS[*]} ${SHORTOPTS[*]}" [[ "${have_command}" ]] || words+=" ${CMDARGS[*]}" COMPREPLY=( $( compgen -W "${words}" -- "${cur}" ) ) ;; esac ;; esac } complete -F _roverlay_comp roverlay _roverlay_status_comp() { local cur local prev COMPREPLY=() _get_comp_words_by_ref cur prev local MODE_LONGOPTS=( '--mode' '--cli' '--html' '--cgi' ) local LONGOPTS=( '--help' '--version' '--config' '--output' '--template' '--cgi-content-type' '--module-root' ) local MODE_SHORTOPTS=( '-m' ) local SHORTOPTS=( '-h' '-V' '-c' '-O' '-t' '-T' '-M' ) local CMDARGS=( 'status' ) local have_mode= local have_command= local k local first=y for k in "${COMP_WORDS[@]}"; do if [[ -z "${first}" ]]; then case "${k}" in '--cgi'|'--cli'|'--html'|'--mode'|'-m') have_mode=y ;; *) if [[ " ${CMDARGS[*]} " == *" ${k} "* ]]; then have_command=y fi ;; esac if [[ ( "${have_mode}" ) && ( "${have_command}" ) ]]; then break fi else first= fi done if [[ -z "${have_mode}" ]]; then LONGOPTS+=( "${MODE_LONGOPTS[@]}" ) SHORTOPTS+=( "${MODE_SHORTOPTS[@]}" ) fi case "${prev}" in '-c'|'--config'|'-O'|'--output') # options with arg _filedir ;; '-t'|'--template') # --template accepts names and files _filedir ;; '-M'|'--module-root') # options with arg _filedir -d ;; '-m'|'--mode') COMPREPLY=( $(compgen -W "cli html cgi" -- "${cur}" ) ) ;; '-T'|'--cgi-content-type') # accepts any word, but text/plain, text/html are common choices COMPREPLY=( $(compgen -W "text/plain text/html" -- "${cur}" ) ) ;; *) case "${cur}" in --*) COMPREPLY=( $( compgen -W "${LONGOPTS[*]}" -- "${cur}" ) ) ;; -*) COMPREPLY=( $( compgen -W "${LONGOPTS[*]} ${SHORTOPTS[*]}" -- "${cur}" ) ) ;; *) local words="${LONGOPTS[*]} ${SHORTOPTS[*]}" [[ "${have_command}" ]] || words+=" ${CMDARGS[*]}" COMPREPLY=( $( compgen -W "${words}" -- "${cur}" ) ) ;; esac ;; esac } complete -F _roverlay_status_comp roverlay-status _roverlay_setup_comp() { local cur local prev COMPREPLY=() _get_comp_words_by_ref cur prev local LONGOPTS=( '--help' '--usage' '--version' '--work-root' '--data-root' '--conf-root' '--conf-dir' '--my-conf-root' '--target-type' '--foreign' '--not-gentoo' '--output' '--ask' '--expand-user' '--additions-dir' '--variable' '--prjroot-relpath' '--enable-default-hooks' '--no-default-hooks' '--import-config' '--no-import-config' '--force-import-config' '--target-uid' '--target-gid' '--overwrite-hooks' '--relpath-hooks' '--no-relpath-hooks' ) local SHORTOPTS=( '-h' '-V' '-W' '-D' '-C' '-O' '-a' '-A' '-v' '-I' ) local CMDARGS=( 'init' 'hooks' 'mkconfig' ) local CONFIG_IMPORT_MODES=( 'disable' 'symlink' 'symlink=root' 'symlink=dirs' 'symlink=files copy' ) local HOOK_OVERWRITE=( 'none' 'dead' 'links' 'all' ) local have_command local k local first=y for k in "${COMP_WORDS[@]}"; do if [[ " ${CMDARGS[*]} " == *" ${k} "* ]] && [[ -z "${first}" ]]; then have_command="${k}" case "${k}" in 'init'|'hooks') LONGOPTS+=( '--pretend' ) SHORTOPTS+=( '-p' ) ;; esac break else first= fi done # bashcomp for subcommands is missing: # * init, mkconfig do not have any special options # * hooks has "show|add|del ..." [[ -z "${have_command-}" ]] || return 0 case "${prev}" in '-v'|'--variable') : ;; '-W'|'--work-root'|'-D'|'--data-root'|'--conf-root'|\ '-C'|'--conf-dir'|'--my-conf-root'|'-A'|'--additions-dir') # options with arg _filedir -d ;; '-O'|'--output') # ||- _filedir [[ "${cur}" ]] || COMPREPLY+=( "-" ) ;; '-I'|'--import-config') COMPREPLY=( $(compgen -W "${CONFIG_IMPORT_MODES[*]}" -- "${cur}" ) ) ;; '--overwrite-hooks') COMPREPLY=( $(compgen -W "${HOOK_OVERWRITE[*]}" -- "${cur}" ) ) ;; '--target-uid') COMPREPLY=( $( compgen -u -- "${cur}" ) ) #_uids #COMPREPLY+= ;; '--target-gid') COMPREPLY=( $( compgen -g -- "${cur}" ) ) #_gids #COMPREPLY+= ;; '--target-type') COMPREPLY=( $( compgen -W "gentoo foreign" -- "${cur}" ) ) ;; *) case "${cur}" in --*) COMPREPLY=( $( compgen -W "${LONGOPTS[*]}" -- "${cur}" ) ) ;; -*) COMPREPLY=( $( compgen -W "${LONGOPTS[*]} ${SHORTOPTS[*]}" -- "${cur}" ) ) ;; *) local words="${LONGOPTS[*]} ${SHORTOPTS[*]}" [[ "${have_command}" ]] || words+=" ${CMDARGS[*]}" COMPREPLY=( $( compgen -W "${words}" -- "${cur}" ) ) ;; esac ;; esac } complete -F _roverlay_setup_comp roverlay-setup _roverlay_query_config_comp() { local cur local prev COMPREPLY=() _get_comp_words_by_ref cur prev local LONGOPTS=( '--help' '--config-file' '--all' '--list-all' '--empty-missing' '--from-file' '--outfile' '--variable' ) local SHORTOPTS=( '-h' '-c' '-a' '-l' '-u' '-f' '-O' '-v' ) case "${prev}" in '-c'|'--config-file'|'-f'|'--from-file'|'-O'|'--outfile') # arg _filedir ;; '-v'|'--variable') true ;; *) COMPREPLY=( $( compgen -W "${LONGOPTS[*]} ${SHORTOPTS[*]}" -- "${cur}" ) ) ;; esac } complete -F _roverlay_query_config_comp roverlay-query-config