File: location

package info (click to toggle)
libloc 0.9.18-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 42,824 kB
  • sloc: ansic: 7,602; python: 2,893; makefile: 511; sh: 39; perl: 13
file content (151 lines) | stat: -rw-r--r-- 3,383 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# location(1) completion                                   -*- shell-script -*-
#
# bash-completion - part of libloc
#
# Copyright (C) 2020,2023 Hans-Christoph Steiner <hans@eds.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 2.1 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

__location_init() {
    if type -t _init_completion >/dev/null; then
        _init_completion -n : || return
    else
	# manual initialization for older bash completion versions
	COMPREPLY=()
	cur="${COMP_WORDS[COMP_CWORD]}"
	prev="${COMP_WORDS[COMP_CWORD-1]}"
    fi

    (( $# >= 1 )) && __complete_${1}
    __ltrim_colon_completions "$cur"
}

__complete_options() {
    case "${prev}" in
        --directory)
            _filedir -d
            return 0;;
        --cron)
	    COMPREPLY=( $( compgen -W "daily weekly monthly" -- $cur ) )
            return 0;;
	--family)
	    COMPREPLY=( $( compgen -W "ipv6 ipv4" -- $cur ) )
            return 0;;
        --format)
	    COMPREPLY=( $( compgen -W "ipset list nftables xt_geoip" -- $cur ) )
            return 0;;
    esac

    case "$cur" in
	-*)
	    COMPREPLY=( $( compgen -W "--help ${lopts}" -- $cur ) )
	    return 0;;
    esac
}

__complete_dump() {
    __complete_options
}

__complete_get_as() {
    __complete_options
}

__complete_export() {
    lopts="--directory --family --format"
    __complete_options
}

__complete_list_networks_by_as() {
    lopts="--family --format"
    __complete_options
}

__complete_list_networks_by_cc() {
    lopts="--family --format"
    __complete_options
}

__complete_list_networks_by_flags() {
    lopts="--anonymous-proxy --satellite-provider --anycast --drop --family --format"
    __complete_options
}

__complete_list_bogons() {
    lopts="--family --format"
    __complete_options
}

__complete_list_countries() {
    lopts="--show-name --show-continent"
    __complete_options
}

__complete_lookup() {
    __complete_options
}

__complete_search_as() {
    __complete_options
}

__complete_update() {
    lopts="--cron"
    __complete_options
}

__complete_version() {
    __complete_options
}

__complete_verify() {
    __complete_options
}

# for f in `location|grep -Eo '[a-z,-]+,[a-z,-]+'| sed 's/,/ /g'`; do printf '%s \\\n' $f; done|sort -u
__cmds=" \
dump \
export \
get-as \
list-bogons \
list-countries \
list-networks-by-as \
list-networks-by-cc \
list-networks-by-flags \
lookup \
search-as \
update \
verify \
version \
"

for c in $__cmds; do
    eval "_location_${c} () {
                local cur prev lopts
                __location_init ${c//-/_}
        }"
done

_location() {
    local cmd
    cmd=${COMP_WORDS[1]}

    [[ $__cmds == *\ $cmd\ * ]] && _location_${cmd} || {
            (($COMP_CWORD == 1)) && COMPREPLY=( $( compgen -W "${__cmds}" -- $cmd ) )
        }
}

complete -F _location location

return 0