76 lines
1.9 KiB
Plaintext
Raw Normal View History

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