From: Hans-Christoph Steiner Date: Fri, 24 Feb 2023 12:41:40 +0000 (+0100) Subject: add bash-completion for 'location' command X-Git-Tag: debian/0.9.16-2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=183d10a1fa572b55c40f4fdafe274e434f16c79c;p=location%2Fdebian%2Flibloc.git add bash-completion for 'location' command --- diff --git a/debian/bash-completion/location b/debian/bash-completion/location new file mode 100644 index 0000000..66fc6c1 --- /dev/null +++ b/debian/bash-completion/location @@ -0,0 +1,151 @@ +# location(1) completion -*- shell-script -*- +# +# bash-completion - part of libloc +# +# Copyright (C) 2020,2023 Hans-Christoph Steiner +# +# 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 . + +__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 diff --git a/debian/control b/debian/control index cdf2509..9e5ae58 100644 --- a/debian/control +++ b/debian/control @@ -10,6 +10,7 @@ Priority: optional Standards-Version: 4.6.1 Build-Depends: debhelper-compat (= 13), + dh-sequence-bash-completion, dh-sequence-python3, asciidoc, intltool, diff --git a/debian/copyright b/debian/copyright index 0d821e1..afa7513 100644 --- a/debian/copyright +++ b/debian/copyright @@ -40,7 +40,8 @@ Copyright: 2017-2022, IPFire Development Team License: CC-BY-SA-4 Files: debian/* -Copyright: 2022, Jochen Sprickerhof +Copyright: 2023, Hans-Christoph Steiner + 2022-2023, Jochen Sprickerhof 2019, Stefan Schantl License: LGPL-2.1+ diff --git a/debian/location.bash-completion b/debian/location.bash-completion new file mode 100644 index 0000000..9838912 --- /dev/null +++ b/debian/location.bash-completion @@ -0,0 +1 @@ +debian/bash-completion/location location