Blame | Last modification | View Log | RSS feed
# main function bound to scl command_scl(){local cur prev optsCOMPREPLY=()cur="${COMP_WORDS[COMP_CWORD]}"prev="${COMP_WORDS[COMP_CWORD-1]}"opts="-l --list"# handle optionsif [[ ${cur} == -* ]] ; thenCOMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )return 0filocal collections=($(find /etc/scl/prefixes -maxdepth 1 -mindepth 1 -type f -exec basename {} \; | sort -u))# handle scriptlets; the first parameter must be a scriptlet if it is not an optionif ((COMP_CWORD == 1)); then# get array of scriptlets found throughout collectionslocal scriptlets=()for col in ${collections[@]}; dolocal prefix=`cat /etc/scl/prefixes/$col`scriptlets+=($(find $prefix/$col/* -maxdepth 1 -type f -exec basename {} \; | sort -u))donescriptlets_str=`echo ${scriptlets[@]} | sed 's/ /\n/g'| sort -u`COMPREPLY=( $(compgen -W "$scriptlets_str register deregister" -- ${cur}) )return 0fi# handle commands; does not handle commands without single or double quotesif [[ ${cur} == \'* || ${cur} == \"* ]] ; then# it is a command do not reply with anythingreturn 0fi# handle collections; if it is not an option or a command, it must be a collectionif [ $prev == "register" ]; thencompopt -o nospaceCOMPREPLY=( $(compgen -A directory ${cur}) )return 0fiCOMPREPLY=( $(compgen -W "${collections[*]}" -- ${cur}) )return 0}# bind the scl command to the _scl function for completioncomplete -F _scl scl