]> git.tue.mpg.de Git - paraslash.git/commitdiff
Update bash_completion to v0.3 commands.
authorAndre Noll <maan@systemlinux.org>
Fri, 28 Dec 2007 16:03:02 +0000 (17:03 +0100)
committerAndre Noll <maan@systemlinux.org>
Fri, 28 Dec 2007 16:03:02 +0000 (17:03 +0100)
It doesn't care about options, and it's slow.  But it's better than
what was there before.

bash_completion

index 2f074990e1a662ae04977e99f4889576623a48e6..aeee64c17713f7d1d16cb1b226958fcf7d304124 100644 (file)
-_para()
-{
-local cur prev sect i manpath tmp
-COMPREPLY=()
-cur=${COMP_WORDS[COMP_CWORD]}
-prev=${COMP_WORDS[COMP_CWORD-1]}
-
-#_expand || return 0
-
-case "${COMP_WORDS[1]}" in
-       cs|cs|strdel|strq)
-       COMPREPLY=( $( eval  para_client streams | grep "^$cur" \
-               2>/dev/null ) )
-       return 0
-       ;;
-       info|la|us|ca|ls|pic|us)
-       COMPREPLY=( $( eval  para_client ls "$cur%"  ) )
-       return 0
-       ;;
-       sa)
-       COMPREPLY=( $( eval  para_client laa | grep "^$cur" \
-               2>/dev/null ) )
-       return 0
-       
-
-       
-esac
-# default completion if parameter contains /
-# [[ "$cur" == */* ]] && return 0
-#echo "cur=$cur"
-COMPREPLY=( $( eval  para_client help | cut -f 1 | sed 1d | grep ^$cur 2>/dev/null ) )
-# weed out directory path names and paths to man pages
-COMPREPLY=( ${COMPREPLY[@]##*/?(:)} )
-COMPREPLY=( ${COMPREPLY[@]} $( compgen -G $cur\*.[0-9ln] ) )
-return 0
-} 
-complete -F _para -o default para
-complete -F _para -o default para_client
+# Copyright (C) 2007 Andre Noll <maan@systemlinux.org>
+#
+# Licensed under the GPL v2. For licencing details see COPYING.
+
+PC="para_client -l 5 -- "
+
+__para_commandlist=
+__para_sender_list=
+__para_table_list=
+__para_mood_list=
+__para_lyrics_list=
+__para_image_list=
+__para_playlist_list=
+__para_attributes_list=
+
+__paracomp()
+{
+        local cur="${COMP_WORDS[COMP_CWORD]}"
+        if [ $# -gt 2 ]; then
+                cur="$3"
+        fi
+        COMPREPLY=($(compgen -P "$2" -W "$1" -- "$cur"))
+}
+
+__para_complete_file()
+{
+       local cur="${COMP_WORDS[COMP_CWORD]}"
+       local sed_cmd="-e s|^\($cur[^/]\+/\).*|\1|1"
+       $PC ls -p -sp "${cur}*" | sed $sed_cmd | uniq
+}
+
+__para_complete_command()
+{
+       if test -z "$__para_command_list"; then
+               __para_command_list="$($PC help | cut -f 1)"
+       fi
+       echo "$__para_command_list"
+}
+
+__para_complete_table()
+{
+       if test -z "$__para_table_list"; then
+               __para_table_list="$(ls $HOME/.paraslash/afs_database/)"
+       fi
+       echo "$__para_table_list"
+}
+__para_complete_sender()
+{
+       if test -z "$__para_sender_list"; then
+               __para_sender_list="$($PC si | grep "supported senders:" | sed -e 's/.*: //')"
+       fi
+       echo "$__para_sender_list"
+}
+__para_complete_attribute()
+{
+       if test -z "$__para_attributes_list"; then
+               __para_attributes_list="$($PC lsatt)"
+       fi
+       echo "$__para_attributes_list"
+}
+__para_complete_playlist()
+{
+       if test -z "$__para_playlist_list"; then
+               __para_playlist_list="$($PC lspl)"
+       fi
+       echo "$__para_playlist_list"
+}
+__para_complete_mood()
+{
+       if test -z "$__para_mood_list"; then
+               __para_mood_list="$($PC lsmood)"
+       fi
+       echo "$__para_mood_list"
+}
+__para_complete_image()
+{
+       if test -z "$__para_image_list"; then
+               __para_image_list="$($PC lsimg)"
+       fi
+       echo "$__para_imagelist"
+}
+__para_complete_lyrics()
+{
+       if test -z "$__para_lyrics_list"; then
+               __para_lyrics_list="$($PC lslyr)"
+       fi
+       echo "$__para_lyrics_list"
+}
+
+__para_select()
+{
+       local cur="${COMP_WORDS[COMP_CWORD]}"
+       case "$cur" in
+       *)
+               __paracomp "$($PC lspl "${cur}*" | sed -e 's|^|p/|1') $($PC lsmood | sed -e 's|^|m/|1')"
+               ;;
+       esac
+}
+
+__para_setatt()
+{
+       local cur="${COMP_WORDS[COMP_CWORD]}"
+       if [ $COMP_CWORD -lt 3 ]; then
+               __paracomp "$(__para_complete_attribute)"
+       else
+               if test -z "$cur" -o "$cur" = "${cur#/}"; then
+                       __paracomp "$(__para_complete_attribute)"
+               else
+                       __paracomp "$(__para_complete_file)"
+               fi
+       fi
+}
+
+__para_sender()
+{
+       if test $COMP_CWORD -eq 2; then
+               __paracomp "$(__para_complete_sender)"
+       elif test $COMP_CWORD -eq 3; then
+               __paracomp "on off add delete allow deny help"
+       else
+               COMPREPLY=()
+       fi
+}
+
+_para_client()
+{
+       local i c=1 command
+
+
+       while [ $c -lt $COMP_CWORD ]; do
+               i="${COMP_WORDS[c]}"
+               case "$i" in
+               --*) ;;
+               *) command="$i"; break ;;
+               esac
+               c=$((++c))
+       done
+
+       if [ $c -eq $COMP_CWORD ]; then
+               case "${COMP_WORDS[COMP_CWORD]}" in
+               --*=*) COMPREPLY=();;
+               *) __paracomp "$(__para_complete_command)";;
+               esac
+               return
+       fi
+
+       case "$command" in
+       stop|play|term|hup|pause|nomore|si|version) COMPREPLY=();;
+       setatt) __para_setatt;;
+       select) __para_select;;
+       touch|ls|rm|cpsi) __paracomp "$(__para_complete_file)";;
+       mvatt|lsatt|rmatt) __paracomp "$(__para_complete_attribute)";;
+       help) __paracomp "$(__para_complete_command)";;
+       sender) __para_sender;;
+       init) __paracomp __paracomp "$(__para_complete_table)";;
+       mvmood|lsmood|rmmood) __paracomp "$(__para_complete_mood)";;
+       mvlyr|lslyr|rmlyr) __paracomp "$(__para_complete_lyrics)";;
+       mvimg|lsimg|rmimg) __paracomp "$(__para_complete_image)";;
+       mvpl|lspl|rmpl) __paracomp "$(__para_complete_playlist)";;
+       esac
+
+}
+complete -o default -o nospace -F _para_client para_client
+complete -o default -o nospace -F _para_client para
+