]> kaliko git repositories - mpd-sima.git/blob - data/bash/completion.sh
2940cb7b1fca669c2c88096c9e0adbe4e1e29a45
[mpd-sima.git] / data / bash / completion.sh
1 # Copyright (c) 2010, 2011, 2013, 2014, 2015 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 --port \
35           -h --help --version \
36           --var-dir \
37           --generate-config \
38           -d --daemon"
39
40     if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
41         COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
42         return 0
43     fi
44
45     case "${prev}" in
46         --var-dir)
47             _filedir -d
48             ;;
49         -v|--log-level)
50             COMPREPLY=( $(compgen -W "debug info warning error" -- ${cur} ))
51             ;;
52         -p|--pid|-l|--log)
53             _filedir
54             ;;
55         -c|--config)
56             _filedir
57             if [ -z $XDG_DATA_HOME ]; then
58                 local confnames=$(for x in $(ls -1 $HOME/.config/mpd_sima/*.cfg $PWD/*.cfg 2>/dev/null) ; do echo "${x##*//}"; done)
59             else
60                 local confnames=$(for x in $(ls -1 $HOME/.config/mpd_sima/*.cfg $XDG_DATA_HOME/mpd_sima/*.cfg $PWD/*.cfg 2>/dev/null) ; do echo "${x##*//}"; done)
61             fi
62             COMPREPLY+=( $(compgen -W "${confnames}" -- ${cur} ) )
63             return 0
64             ;;
65         --host|-S)
66             COMPREPLY=( $(compgen -A hostname ${cur}) )
67             ;;
68         *)
69             ;;
70     esac
71 }
72 complete -F _sima mpd_sima
73 complete -F _sima mpd-sima
74
75 _simadb_cli() {
76     local cur prev opts
77     local IFS=$'\n'
78     COMPREPLY=()
79     _get_comp_words_by_ref cur prev
80     opts="--purge_hist \
81         --bl_curr_trk --bl_curr_art --bl_curr_al --bl_art --remove_bl --view_bl \
82         --dbfile -d \
83         --host -S --port -P \
84         --check_names -c \
85         --version -h --help"
86     opts=$(echo $opts | sed 's/ /\n/g')
87
88     if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
89         COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
90         return 0
91     fi
92
93     case "${prev}" in
94         --bl_curr*|--view_bl|--view_all|--purge_hist|--version|--help|-h)
95             return 0
96             ;;
97         -d|--dbfile)
98             _filedir
99             ;;
100         --host|-S)
101             COMPREPLY=( $(compgen -A hostname ${cur}) )
102             ;;
103         *)
104             ;;
105     esac
106 }
107 complete -F _simadb_cli simadb_cli