_lctl() { local cur prev words cword COMPREPLY=() # allow different versions of bash_completion to work if declare -F _init_completion > /dev/null; then # this provides more functionality, but is only in v2.x _init_completion || return else # this is compatible with both v1.3 and v2.x _get_comp_words_by_ref -n : cur prev words cword fi if [[ "$cword" == "1" ]]; then COMPREPLY=( $( compgen -W '$(lctl --list-commands | grep -v '^=')' -- "$cur" ) ) return 0 fi case "${words[1]}" in set_param|list_param|get_param) local filter="s/=$//" [[ "${words[1]}" == "set_param" ]] && filter="/[^=/]$/d" mapfile -t COMPREPLY < <( lctl list_param -F "${cur#[\"\']}*" 2>/dev/null | sed -e "$filter" -e 's#/$#.#' \ -e "s#^${cur//\*/[^.]*}#$cur#" ) compopt -o nospace return 0 ;; esac } && complete -F _lctl lctl