]> kaliko git repositories - mpd-sima.git/blob - data/bash/completion.sh
Add missing daemon option in bash completion
[mpd-sima.git] / data / bash / completion.sh
1 # Copyright (c) 2010, 2011, 2013, 2014 Jack Kaliko <kaliko@azylum.org>
2 #
3 #  This file is part of MPD_sima
4 #
5 #  MPD_sima is free software: you can redistribute it and/or modify
6 #  it under the terms of the GNU General Public License as published by
7 #  the Free Software Foundation, either version 3 of the License, or
8 #  (at your option) any later version.
9 #
10 #  MPD_sima is distributed in the hope that it will be useful,
11 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 #  GNU General Public License for more details.
14 #
15 #  You should have received a copy of the GNU General Public License
16 #  along with MPD_sima.  If not, see <http://www.gnu.org/licenses/>.
17 #
18 #
19
20 # Bash completion file
21 #
22 # On debian system either place this file in etc/bash_completion.d/ or source it
23 # in your barshrc.
24
25 _sima() {
26     local cur prev opts
27     COMPREPLY=()
28     _get_comp_words_by_ref cur prev
29     opts="-c --config \
30           -p --pid \
31           -l --log \
32           -v --log-level \
33           -S --host \
34           -P --mpd_port \
35           -h --help --version \
36           --var_dir \
37           -d --daemon"
38
39     if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
40         COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
41         return 0
42     fi
43
44     case "${prev}" in
45         --var_dir)
46             _filedir -d
47             ;;
48         -v|--log-level)
49             COMPREPLY=( $(compgen -W "debug info warning error" -- ${cur} ))
50             ;;
51         -p|--pid|-l|--log)
52             _filedir
53             ;;
54         -c|--config)
55             _filedir
56             if [ -z $XDG_DATA_HOME ]; then
57                 local confnames=$(for x in $(ls -1 $HOME/.config/mpd_sima/*.cfg 2>/dev/null) ; do echo "${x##*//}"; done)
58             else
59                 local confnames=$(for x in $(ls -1 $HOME/.config/mpd_sima/*.cfg $XDG_DATA_HOME/mpd_sima/*.cfg 2>/dev/null) ; do echo "${x##*//}"; done)
60             fi
61             COMPREPLY+=( $(compgen -W "${confnames}") )
62             return 0
63             ;;
64         --host|-S)
65             COMPREPLY=( $(compgen -A hostname ${cur}) )
66             ;;
67         *)
68             ;;
69     esac
70 }
71 complete -F _sima mpd_sima
72 complete -F _sima mpd-sima
73
74 _art_names_list() {
75     local IFS=$'\n'
76     compgen -W "${artists}" -- ${cur}
77 }
78
79 _simadb_cli() {
80     local cur prev opts artists
81     local IFS=$'\n'
82     COMPREPLY=()
83     _get_comp_words_by_ref cur prev
84     opts="--add_similarity -a --remove_similarity --remove_artist \
85     --purge_hist --view_artist --view_all \
86     --bl_curr_trk --bl_curr_art --bl_curr_al --bl_art --remove_bl --view_bl \
87     --dbfile -d \
88     --host -S --port -P \
89     --reciprocal -r --check_names -c \
90     --version -h --help"
91     opts=$(echo $opts | sed 's/ /\n/g')
92
93     if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
94         COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
95         return 0
96     fi
97
98     case "${prev}" in
99         --bl_curr*|--view_bl|--view_all|--purge_hist|--version|--help|-h)
100             return 0
101             ;;
102         -d|--dbfile)
103             _filedir
104             ;;
105         --host|-S)
106             COMPREPLY=( $(compgen -A hostname ${cur}) )
107             ;;
108         -a|--add_similarity|--view_artist|-v|--bl_art)
109             if [ -x /usr/bin/mpc ]; then
110                 artists=$(for x in $(/usr/bin/mpc list artist) ; do echo "'${x}'"; done)
111                 COMPREPLY=( $(compgen -W "${artists}" -- ${cur}) )
112                 return 0
113             fi
114             # It should also complete artist name when the string ends with a comma
115             return 0
116             ;;
117         *)
118             ;;
119     esac
120 }
121 complete -F _simadb_cli simadb_cli