From patchwork Fri Feb 24 16:22:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Schantl X-Patchwork-Id: 6606 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384 client-signature ECDSA (P-384) client-digest SHA384) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4PNZt111lwz3x1w for ; Fri, 24 Feb 2023 16:22:17 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail02.haj.ipfire.org", Issuer "R3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4PNZt03Kskz1ln; Fri, 24 Feb 2023 16:22:16 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4PNZt01b18z3019; Fri, 24 Feb 2023 16:22:16 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384 client-signature ECDSA (P-384) client-digest SHA384) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4PNZsy3dCqz2xPJ; Fri, 24 Feb 2023 16:22:14 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by mail01.ipfire.org (Postfix) with ESMTPSA id 4PNZsw4dZvzBD; Fri, 24 Feb 2023 16:22:12 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1677255733; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=obc7AvnU/W8TxAfGNjygUODZ2kw7OqvU+4N9bZkdA4g=; b=VkeRrxREuzWil+BVNQcB6S0uPCLYvmR4p++tL3I2WgXiKscbqjBEf7XbEHT/ea6FgCa6Rm EEYl+bbTPldQbYCw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1677255733; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=obc7AvnU/W8TxAfGNjygUODZ2kw7OqvU+4N9bZkdA4g=; b=f55HXlDKm9GeFGRTQZv4hOpCrp1jkSlPulkkIYWHZVNfa89XVHjGnIUhuAqKp8ok0WyI7q 72ljxsKpTXexgSSWCFjWU9BbMK66azjEuu0UXTkcnpavV/Hu112vLy8RHi29JvHl5P3gfF wnW+rT1KFKQtLC1LrMfVij2KxX4f0A2MogiAd2ARklsT/8ij2DGjlGEjLdB+gOg0KCwaxO C50h817kJ9xZYUop/o6mGyp309uIBZ9lbd5zf65YmoopSuqdrvYj1PkfFBTSodYApgOo9+ V86Zhw+BQ7st/PzRNfZzXTgdJAeNFmx2a2sCQSp9zbXa6cTEyEz6dPittlnJmg== From: Stefan Schantl To: location@lists.ipfire.org Subject: [PATCH 1/2] Add bash-completion file for the location command. Date: Fri, 24 Feb 2023 17:22:05 +0100 Message-Id: <20230224162206.89971-1-stefan.schantl@ipfire.org> MIME-Version: 1.0 X-BeenThere: location@lists.ipfire.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: development@lists.ipfire.org, Hans-Christoph Steiner Errors-To: location-bounces@lists.ipfire.org Sender: "Location" From: Hans-Christoph Steiner Signed-off-by: Stefan Schantl --- bash-completion/location | 151 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 bash-completion/location diff --git a/bash-completion/location b/bash-completion/location new file mode 100644 index 0000000..66fc6c1 --- /dev/null +++ b/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