simplier completion

This commit is contained in:
Mattias Andrée 2012-08-18 16:37:55 +02:00
parent c4f07a8b00
commit dce179f8a3
2 changed files with 11 additions and 44 deletions

View file

@ -8,28 +8,18 @@ _ponysay()
options='-v -h -l -f -W -q' options='-v -h -l -f -W -q'
COMPREPLY=( $( compgen -W "$options" -- "$cur" ) ) COMPREPLY=( $( compgen -W "$options" -- "$cur" ) )
if [ $prev = "-f" ]; then if [ $prev = "-f" ]; then
COMPREPLY=() ponies=$('/usr/bin/ponysay.py' --onelist)
COMPREPLY=( $( compgen -W "$ponies" -- "$cur" ) )
sysponies=/usr/share/ponysay/ponies/ elif [ $prev = "-q" ]; then
usrponies=~/.local/share/ponysay/ponies/ quoters=$('/usr/bin/ponysay.py' --quoters)
if [[ $TERM = "linux" ]]; then COMPREPLY=( $( compgen -W "$quoters" -- "$cur" ) )
sysponies=/usr/share/ponysay/ttyponies/
usrponies=~/.local/share/ponysay/ttyponies/
fi
[ -d $sysponies ] && COMPREPLY+=( $( compgen -W "$(ls --color=no $sysponies | sed -e 's/.pony//g')" -- "$cur" ) )
[ -d $usrponies ] && COMPREPLY+=( $( compgen -W "$(ls --color=no $usrponies | sed -e 's/.pony//g')" -- "$cur" ) )
elif [ $prev = "-W" ]; then elif [ $prev = "-W" ]; then
cols=$(( `stty size | cut -d ' ' -f 2` - 10 )) cols=$(( `stty size | cut -d ' ' -f 2` - 10 ))
COMPREPLY=( $cols $(( $cols / 2 )) 100 60 ) COMPREPLY=( $cols $(( $cols / 2 )) 100 60 )
elif [ $prev = "-q" ]; then
qcmd=/usr/lib/ponysay/pq4ps
quoters=$($qcmd -l)
COMPREPLY=( $( compgen -W "$quoters" -- "$cur" ) )
fi fi
} }

View file

@ -3,43 +3,20 @@
# #
# Author: Elis Axelsson <etu AT elis DOT nu> # Author: Elis Axelsson <etu AT elis DOT nu>
if test $TERM = "linux"
set -g systempath /usr/share/ponysay/ttyponies/
set -g homepath ~/.local/share/ponysay/ttyponies/
else
set -g systempath /usr/share/ponysay/ponies/
set -g homepath ~/.local/share/ponysay/ponies/
end
set -g ponies ('/usr/bin/ponysay.pl' --onelist)
if test -d $systempath set -g quoters ('/usr/bin/ponysay.pl' --quoters)
set -g systemponies (ls --color=no $systempath | sed -e 's/\.pony//' -e 's/_.*//' | perl -pe 's/([a-z])([A-Z])/\1\\\ \2/' )
end
if test -d $homepath
set -g homeponies (ls --color=no $homepath | sed -e 's/\.pony//' -e 's/_.*//' | perl -pe 's/([a-z])([A-Z])/\1\\\ \2/' )
end
set -g qcmd /usr/lib/ponysay/pq4ps
set -g quoters ($qcmd -l)
complete -c ponysay -s h --description "Help of ponysay" complete -c ponysay -s h --description "Help of ponysay"
complete -c ponysay -s v --description "Version of ponysay" complete -c ponysay -s v --description "Version of ponysay"
complete -c ponysay -s l --description "List pony files" complete -c ponysay -s l --description "List pony files"
complete -c ponysay -s L --description "List pony files with alternatives" complete -c ponysay -s L --description "List pony files with alternatives"
complete -c ponysay -s f -a "$homeponies $systemponies" --description "Select a pony" complete -c ponysay -s f -a "$ponies" --description "Select a pony"
complete -c ponysay -s q -a "$quoters" --description "Select ponies for MLP:FiM quotes" complete -c ponysay -s q -a "$quoters" --description "Select ponies for MLP:FiM quotes"
complete -c ponysay -s W -a "Integer" --description "The screen column where the message should be wrapped" complete -c ponysay -s W -a "Integer" --description "The screen column where the message should be wrapped"
set -e systempath set -e ponies
set -e homepath
set -e systemponies
set -e homeponies
set -e qcmd
set -e quoters set -e quoters