updated on Thu Jan 19 20:01:47 UTC 2012
[aur-mirror.git] / xmms2-git-oss / bash-completion-xmms2
blob6fab029504504c3ba1e9979821391e74ffcdd5f2
1 #-*- mode: shell-script; tab-width: 4-*-
3 # xmms2 completion
4 # Copyright 2005 Remi Vanicat
5 # Modified by lh, 2008
6 # License: GNU GPL v2 or later
8 _xmms2()
10         local cmd cur prev query i saveifs
11         
12         COMPREPLY=()
13         cmd=${COMP_WORDS[1]}
14         cur=${COMP_WORDS[COMP_CWORD]}
15         prev=${COMP_WORDS[COMP_CWORD-1]}
16         
17         if [ $COMP_CWORD -eq 1 ]; then
18                 COMPREPLY=( $(compgen -W "add addarg addid insert insertid radd rinsert clear shuffle \
19                                          sort remove list addpls play stop toggleplay pause next prev seek \
20                                          jump move volume volume_list mlib playlist coll browse status info \
21                                          current config config_list plugin_list stats quit help"  -- "$cur") )
22                 return 0
23         fi
24         case "$cmd" in
25                 mlib)
26                         cmd=${COMP_WORDS[2]}
27                         case "$cmd$COMP_CWORD" in
28                                 *2)
29                                         COMPREPLY=( $(compgen -W "add loadall searchadd search addpath rehash remove setstr setint rmprop addcover" -- "$cur") )
30                                         return 0
31                                         ;;
32                                 list_playlist3|save_playlist3|load_playlist3|import_playlist3|export_playlist3|remove_playlist3)
33                                         COMPREPLY=($(compgen -W "$(xmms2 mlib playlists_list)" \
34                                                         -- "$cur"))
35                                         return 0
36                                         ;;
37                                 import_playlist4)
38                                         return 0
39                                         ;;
40                                 addpath*)
41                                         return 0
42                                         ;;
43                                 search*|searchadd*)
44                                         if [[ "$cur" == *=* ]]; then
45                                                 prev=${cur%%=*}
46                                                 prev=${prev%%\\*}
47                                                 cur=$(echo "${cur#*=}" | sed -e 's/\\//g' | sed -e "s/'/''/g")
48                                                 query="select value from Media \
49                                                         where key='$prev' and value like '$cur%' \
50                                                         group by lower(value) order by lower(value)"
51                                                 saveifs=$IFS
52                                                 IFS=""
53                                                 COMPREPLY=( $(xmms2 mlib query "$query"|cut -c 9- )) # | sed -e 's/ /\\ /g' | sed -e "s/'/\\\\'/g") )
54                                                 for (( i=0; ${#COMPREPLY[@]} - i; i=i+1 )); do
55                                                         COMPREPLY[i]="$(printf '%q' "${COMPREPLY[i]}")"
56                                                 done
58                                                 IFS=$saveifs
59                                                 return 0
60                                         else
61                                                 COMPREPLY=($(compgen -W "$(xmms2 mlib query 'select distinct key from Media' | sed 's/^key = \(.*\)$/\1/')" -- "$cur" | sed 's/$/=/'))
62                                                 return 0
63                                         fi
64                         esac
65                         ;;
66                 config)
67                         if [ $COMP_CWORD -eq 2 ]; then
68                                 COMPREPLY=($(compgen -W  "$(xmms2 config_list | sed 's/ .*//')"))
69                                 return 0
70                         fi
71                         ;;
72                 coll)
73                         if [ $COMP_CWORD -eq 2 ]; then
74                                 COMPREPLY=($(compgen -W  "save rename list query queryadd find get remove attr sync"))
75                                 return 0
76                         fi
77                         ;;
78                 addpls)
79                         if [ $COMP_CWORD -eq 2 ]; then
80                                 COMPREPLY=($(compgen -W  "$(xmms2 mlib playlists_list)"))
81                                 return 0
82                         fi
83                         ;;
84                 playlist)
85                         if [ $COMP_CWORD -eq 2 ]; then
86                                 COMPREPLY=($(compgen -W  "list active create type load remove"))
87                                 return 0
88                         fi
89                         ;;
90                 sort)
91                         if [ $COMP_CWORD -eq 2 ]; then
92                                 COMPREPLY=($(compgen -W  "artist title duration album \
93                                         laststarted lmod mime added url bitrate tracknr album_id \
94                                         artist_id track_id"))
95                                 return 0
96                         fi
97                         ;;
98                 radd)
99                         return 0
100                         ;;
101         esac
102         
104         return 0
107 complete -F _xmms2 -o default xmms2