2011-11-01 22:14:45 +02:00
|
|
|
# bash completion for info -*- shell-script -*-
|
2009-05-27 19:01:26 +02:00
|
|
|
|
|
|
|
_info()
|
|
|
|
{
|
2011-05-01 22:18:40 +03:00
|
|
|
local cur prev words cword split
|
|
|
|
_init_completion -s || return
|
2009-10-04 19:42:50 +02:00
|
|
|
|
|
|
|
_expand || return 0
|
|
|
|
|
2011-04-24 19:35:42 +03:00
|
|
|
# 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
|
2011-06-29 00:30:08 +03:00
|
|
|
-k|--apropos|--index-search|-n|--node|-h|--help|-v|--version)
|
2011-04-28 20:56:59 +03:00
|
|
|
return
|
|
|
|
;;
|
2011-06-29 00:30:08 +03:00
|
|
|
-d)
|
|
|
|
if [[ ${1##*/} == info ]]; then
|
|
|
|
_filedir -d
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
--directory)
|
2011-04-28 20:56:59 +03:00
|
|
|
_filedir -d
|
|
|
|
return
|
|
|
|
;;
|
2011-06-29 00:30:08 +03:00
|
|
|
--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" ) )
|
2011-05-02 11:41:52 +03:00
|
|
|
[[ $COMPREPLY == *= ]] && compopt -o nospace
|
2011-04-28 20:56:59 +03:00
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2011-04-20 17:13:48 +03:00
|
|
|
local i infopath=/usr/share/info
|
2009-10-04 19:42:50 +02:00
|
|
|
|
2011-11-09 22:24:39 +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
|
|
|
} &&
|
2011-06-29 00:30:08 +03:00
|
|
|
complete -F _info info pinfo
|
2009-10-01 20:54:51 +03:00
|
|
|
|
2009-10-04 19:42:50 +02:00
|
|
|
# ex: ts=4 sw=4 et filetype=sh
|