# bash completion for info -*- shell-script -*- proc _info { local cur prev words cword split _init_completion -s || return _expand || return 0 # default completion if parameter looks like a path if [[ "$cur" == @(*/|[.~])* ]] { _filedir return 0 } match $prev { with -k|--apropos|--index-search|-n|--node|-h|--help|-v|--version return with -d if [[ ${1##*/} == info ]] { _filedir -d return } with --directory _filedir -d return with --dribble|-f|--file|-o|--output|--restore|-r|--raw-filename|--rcfile _filedir return } $split && return if [[ $cur == -* ]] { setglobal COMPREPLY = ''( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) ) [[ $COMPREPLY == *= ]] && compopt -o nospace return } local i infopath=/usr/share/info if [[ $INFOPATH == *: ]] { setglobal infopath = "$(INFOPATH)$(infopath)" } elif [[ ${INFOPATH:+set} ]] { setglobal infopath = $INFOPATH } setglobal infopath = "$infopath:" if [[ -n $cur ]] { setglobal infopath = $(infopath//://$cur* ) } else { setglobal infopath = $(infopath//:// ) } # redirect stderr for when path doesn't exist setglobal COMPREPLY = ''( $( eval command ls "$infopath" 2>/dev/null ) ) # weed out directory path names and paths to info pages setglobal COMPREPLY = ''( ${COMPREPLY[@]##*/?(:)} ) # weed out info dir file for (( i=0 ; i < ${#COMPREPLY[@]} ; ++i )); do [[ ${COMPREPLY[$i]} == dir ]] && unset "COMPREPLY[$i]" done # strip suffix from info pages setglobal COMPREPLY = ''( ${COMPREPLY[@]%.@(gz|bz2|xz|lzma)} ) setglobal COMPREPLY = ''( $( compgen -W '${COMPREPLY[@]%.*}' -- "${cur//\\\\/}" ) ) return 0 } && complete -F _info info pinfo # ex: ts=4 sw=4 et filetype=sh