]> git.ipfire.org Git - location/debian/libloc.git/blame - debian/bash-completion/location
add bash-completion for 'location' command
[location/debian/libloc.git] / debian / bash-completion / location
CommitLineData
183d10a1
HCS
1# location(1) completion -*- shell-script -*-
2#
3# bash-completion - part of libloc
4#
5# Copyright (C) 2020,2023 Hans-Christoph Steiner <hans@eds.org>
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU Lesser General Public License as published by
9# the Free Software Foundation, either version 2.1 of the License, or
10# (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU Lesser General Public License for more details.
16#
17# You should have received a copy of the GNU Lesser General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20__location_init() {
21 if type -t _init_completion >/dev/null; then
22 _init_completion -n : || return
23 else
24 # manual initialization for older bash completion versions
25 COMPREPLY=()
26 cur="${COMP_WORDS[COMP_CWORD]}"
27 prev="${COMP_WORDS[COMP_CWORD-1]}"
28 fi
29
30 (( $# >= 1 )) && __complete_${1}
31 __ltrim_colon_completions "$cur"
32}
33
34__complete_options() {
35 case "${prev}" in
36 --directory)
37 _filedir -d
38 return 0;;
39 --cron)
40 COMPREPLY=( $( compgen -W "daily weekly monthly" -- $cur ) )
41 return 0;;
42 --family)
43 COMPREPLY=( $( compgen -W "ipv6 ipv4" -- $cur ) )
44 return 0;;
45 --format)
46 COMPREPLY=( $( compgen -W "ipset list nftables xt_geoip" -- $cur ) )
47 return 0;;
48 esac
49
50 case "$cur" in
51 -*)
52 COMPREPLY=( $( compgen -W "--help ${lopts}" -- $cur ) )
53 return 0;;
54 esac
55}
56
57__complete_dump() {
58 __complete_options
59}
60
61__complete_get_as() {
62 __complete_options
63}
64
65__complete_export() {
66 lopts="--directory --family --format"
67 __complete_options
68}
69
70__complete_list_networks_by_as() {
71 lopts="--family --format"
72 __complete_options
73}
74
75__complete_list_networks_by_cc() {
76 lopts="--family --format"
77 __complete_options
78}
79
80__complete_list_networks_by_flags() {
81 lopts="--anonymous-proxy --satellite-provider --anycast --drop --family --format"
82 __complete_options
83}
84
85__complete_list_bogons() {
86 lopts="--family --format"
87 __complete_options
88}
89
90__complete_list_countries() {
91 lopts="--show-name --show-continent"
92 __complete_options
93}
94
95__complete_lookup() {
96 __complete_options
97}
98
99__complete_search_as() {
100 __complete_options
101}
102
103__complete_update() {
104 lopts="--cron"
105 __complete_options
106}
107
108__complete_version() {
109 __complete_options
110}
111
112__complete_verify() {
113 __complete_options
114}
115
116# for f in `location|grep -Eo '[a-z,-]+,[a-z,-]+'| sed 's/,/ /g'`; do printf '%s \\\n' $f; done|sort -u
117__cmds=" \
118dump \
119export \
120get-as \
121list-bogons \
122list-countries \
123list-networks-by-as \
124list-networks-by-cc \
125list-networks-by-flags \
126lookup \
127search-as \
128update \
129verify \
130version \
131"
132
133for c in $__cmds; do
134 eval "_location_${c} () {
135 local cur prev lopts
136 __location_init ${c//-/_}
137 }"
138done
139
140_location() {
141 local cmd
142 cmd=${COMP_WORDS[1]}
143
144 [[ $__cmds == *\ $cmd\ * ]] && _location_${cmd} || {
145 (($COMP_CWORD == 1)) && COMPREPLY=( $( compgen -W "${__cmds}" -- $cmd ) )
146 }
147}
148
149complete -F _location location
150
151return 0