# Turn on extended globbing shopt -s extglob ## # Helper functions ## _lunar_modules_list() { COMPREPLY=( $( compgen -W "$( cut -d: -f1 /var/state/lunar/module.index )" -- "$cur" ) ) } _lunar_modules_installed_list() { COMPREPLY=( $( compgen -W "$( cut -d: -f1 /var/state/lunar/packages )" -- "$cur" ) ) } _lunar_modules_held_list() { COMPREPLY=( $( compgen -W "$( awk -F: '/:installed\+held:/ { print $1 }' /var/state/lunar/packages )" -- "$cur" ) ) } _lunar_internal_variable_list() { COMPREPLY=( $( compgen -W "$( sed -rn 's;\s*([^=]*).*;\1;p' /etc/lunar/local/config )" -- "$cur" ) ) } _lunar_exilable_module_list() { COMPREPLY=( $( compgen -W "$( comm -3 <(cut -d: -f1 /var/state/lunar/module.index | sort) <(cut -d: -f1 /var/state/lunar/packages | sort) )" -- "$cur" ) ) } _lunar_modules_exiled_list() { COMPREPLY=( $( compgen -W "$( awk -F: '/:exiled:/ { print $1 }' /var/state/lunar/packages )" -- "$cur" ) ) } _lunar_sections_list() { COMPREPLY=( $( compgen -W "$(cut -d: -f2 /var/state/lunar/module.index | sort -u) zlocal" -- "$cur" ) ) } ## # Completion functions ## _lunar() { local cur prev cmd COMPREPLY=() cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do if [[ ${COMP_WORDS[i]} == @(exile|fix|hold|install|nofix|remove|unexile|unhold) ]]; then cmd=${COMP_WORDS[i]} fi done if [[ -n "$cmd" ]]; then case $cmd in exile) _lunar_exilable_module_list return 0 ;; install) _lunar_modules_list return 0 ;; fix|hold|nofix|remove) _lunar_modules_installed_list return 0 ;; unexile) _lunar_modules_exiled_list return 0 ;; unhold) _lunar_modules_held_list return 0 ;; esac fi case "$prev" in -d|--debug|-v|--verbose|-h|--help) ;; fixdepends|optimize|prune|rebuild|renew|resurrect|update) # Return since these options does not take any arguments return 0 ;; set|unset) _lunar_internal_variable_list return 0 ;; esac if [[ "$cur" == -* ]]; then COMPREPLY=( $( compgen -W '-d --debug -v --verbose -h --help' -- "$cur") ) elif [[ $COMP_CWORD -gt 2 && "${COMP_WORDS[COMP_CWORD-2]}" == @(set|unset) ]]; then return 0 else COMPREPLY=( $( compgen -W 'prune renew update rebuild optimize fix nofix fixdepends set resurrect install remove hold unhold exile unexile unset' -- "$cur" ) ) fi return 0 } complete -F _lunar lunar _lunar_lvu() { local cur prev cmd COMPREPLY=() cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} case "$prev" in -d|--debug|-v|--verbose|-h|--help) ;; activity) COMPREPLY=( $(compgen -W '-f' -- "$cur") ) return 0 ;; leafs|orphans|conflicts|moonalyze|alien|held|exiled|export|moonbase|html|updatelog|pam|expired|new|newer|older|search|service|apropos) # Do nothing because either the options don't take an argument or we can't do completion return 0 ;; from|import) compopt -o filenames COMPREPLY=( $(compgen -f -- "$cur") ) return 0 ;; DETAILS|DEPENDS|CONFLICTS|BUILD|PRE_BUILD|POST_BUILD|CONFIGURE|POST_INSTALL|PRE_REMOVE|POST_REMOVE|what|where|cd|service|website|compiler|links|sources|maintainer|version|sum|md5sum|depends|tree|eert|stree|leert|urls|versions|short|info|edit|compile|installed) _lunar_modules_list return 0 ;; install|size) _lunar_modules_installed_list return 0 ;; section) _lunar_sections_list return 0 ;; submit|unedit|diff) COMPREPLY=( $(compgen -W "$(lvu section zlocal)" -- "$cur") ) return 0 ;; esac if [[ "${COMP_WORDS[COMP_CWORD-2]}" == "activity" && "$prev" == "-f" ]]; then return 0 elif [[ "$cur" == -* ]]; then COMPREPLY=( $( compgen -W '-d --debug -v --verbose -h --help' -- "$cur") ) elif [[ $COMP_CWORD -gt 2 && "${COMP_WORDS[COMP_CWORD-2]}" == @(DETAILS|DEPENDS|CONFLICTS|BUILD|PRE_BUILD|POST_BUILD|CONFIGURE|POST_INSTALL|PRE_REMOVE|POST_REMOVE|what|where|cd|from|search|apropos|service|website|install|size|installed|compile|compiler|links|sources|maintainer|version|sum|md5sum|depends|tree|eert|stree|leert|urls|versions|short|info|edit|unedit|diff|new|submit|section) ]]; then return 0 else COMPREPLY=( $( compgen -W 'DETAILS DEPENDS CONFLICTS BUILD PRE_BUILD POST_BUILD CONFIGURE POST_INSTALL PRE_REMOVE POST_REMOVE \ what where cd alien from leafs orphans conflicts search service website install size installed compile \ compiler links sources maintainer version sum md5sum export import section moonbase html updatelog \ activity newer older voyeur pam expired depends tree eert stree leert held exiled urls versions short \ info edit unedit diff new submit moonalyze apropos' -- "$cur" ) ) fi return 0 } complete -F _lunar_lvu lvu _lunar_comp_modules() { local cur cur=${COMP_WORDS[COMP_CWORD]} _lunar_modules_list return 0 } alias lwtf="lvu what" complete -F _lunar_comp_modules lwtf function lcd(){ local mb section mb="$(lsh 'echo $MOONBASE')" if [[ -z "$1" || "$1" = "." ]]; then cd "$mb" else section="$(lsh find_section "$1")" if [[ -z "$section" ]]; then echo "$0: lcd: No such module in moonbase" >&2 return 1 else cd "$mb/$section/$1" fi fi } complete -F _lunar_comp_modules lcd _lunar_lin() { local cur cur=${COMP_WORDS[COMP_CWORD]} if [[ "$cur" == -* ]]; then COMPREPLY=( $( compgen -W '-c --compile -d --debug --deps -f --from -h --help --opts -p --probe -r --reconfigure -R --resurrect -s --silent -v --verbose -w --want -4 --ipv4 -6 --ipv6' -- "$cur") ) else _lunar_modules_list fi return 0 } complete -F _lunar_lin lin _lunar_lget() { local cur cur=${COMP_WORDS[COMP_CWORD]} if [[ "$cur" == -* ]]; then COMPREPLY=( $( compgen -W '-a --all -d --debug -f --from -h --help -u --url -v --verbose -w --want -4 --ipv4 -6 --ipv6' -- "$cur") ) else _lunar_modules_list fi return 0 } complete -F _lunar_lget lget _lunar_lrm () { local cur cur=${COMP_WORDS[COMP_CWORD]} if [[ "$cur" == -* ]]; then COMPREPLY=( $( compgen -W '-d --debug -D --downgrade -h --help -k --keepconfig -n --nosustain -u --upgrade -v --verbose -p --purge' -- "$cur" ) ) else _lunar_modules_installed_list fi return 0 } complete -F _lunar_lrm lrm