]>
Commit | Line | Data |
---|---|---|
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=" \ | |
118 | dump \ | |
119 | export \ | |
120 | get-as \ | |
121 | list-bogons \ | |
122 | list-countries \ | |
123 | list-networks-by-as \ | |
124 | list-networks-by-cc \ | |
125 | list-networks-by-flags \ | |
126 | lookup \ | |
127 | search-as \ | |
128 | update \ | |
129 | verify \ | |
130 | version \ | |
131 | " | |
132 | ||
133 | for c in $__cmds; do | |
134 | eval "_location_${c} () { | |
135 | local cur prev lopts | |
136 | __location_init ${c//-/_} | |
137 | }" | |
138 | done | |
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 | ||
149 | complete -F _location location | |
150 | ||
151 | return 0 |