* [PATCH 1/2] Add bash-completion file for the location command.
@ 2023-02-24 16:22 Stefan Schantl
2023-02-24 16:22 ` [PATCH 2/2] Install bash-completion files Stefan Schantl
0 siblings, 1 reply; 2+ messages in thread
From: Stefan Schantl @ 2023-02-24 16:22 UTC (permalink / raw)
To: location
[-- Attachment #1: Type: text/plain, Size: 4165 bytes --]
From: Hans-Christoph Steiner <hans(a)guardianproject.info>
Signed-off-by: Stefan Schantl <stefan.schantl(a)ipfire.org>
---
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 <hans(a)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
--
2.30.2
^ permalink raw reply [flat|nested] 2+ messages in thread
* [PATCH 2/2] Install bash-completion files.
2023-02-24 16:22 [PATCH 1/2] Add bash-completion file for the location command Stefan Schantl
@ 2023-02-24 16:22 ` Stefan Schantl
0 siblings, 0 replies; 2+ messages in thread
From: Stefan Schantl @ 2023-02-24 16:22 UTC (permalink / raw)
To: location
[-- Attachment #1: Type: text/plain, Size: 2774 bytes --]
Signed-off-by: Stefan Schantl <stefan.schantl(a)ipfire.org>
---
Makefile.am | 9 +++++++++
configure.ac | 36 ++++++++++++++++++++++++++++++++++++
2 files changed, 45 insertions(+)
diff --git a/Makefile.am b/Makefile.am
index 4da2ec5..4edb9e9 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -13,6 +13,8 @@ if ENABLE_PERL
BINDINGS += perl
endif
+bashcompletiondir = @bashcompletiondir@
+
AM_CPPFLAGS = \
-include $(top_builddir)/config.h \
-DSYSCONFDIR=\""$(sysconfdir)"\" \
@@ -172,6 +174,13 @@ EXTRA_DIST += \
CLEANFILES += \
src/libloc.pc
+#dist_bashcompletion_DATA =
+
+if BUILD_BASH_COMPLETION
+dist_bashcompletion_DATA = \
+ bash-completion/location
+endif
+
dist_pkgpython_PYTHON = \
src/python/database.py \
src/python/downloader.py \
diff --git a/configure.ac b/configure.ac
index edca1d4..e21574d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -55,6 +55,41 @@ AC_CHECK_PROGS(ASCIIDOC, [asciidoc])
if test "${have_man_pages}" = "yes" && test -z "${ASCIIDOC}"; then
AC_MSG_ERROR([Required program 'asciidoc' not found])
fi
+
+# - pkg-config -----------------------------------------------------------------
+
+m4_ifndef([PKG_PROG_PKG_CONFIG],
+ [m4_fatal([Could not locate the pkg-config autoconf
+ macros. These are usually located in /usr/share/aclocal/pkg.m4.
+ If your macros are in a different location, try setting the
+ environment variable AL_OPTS="-I/other/macro/dir" before running
+ ./autogen.sh or autoreconf again. Make sure pkg-config is installed.])])
+
+PKG_PROG_PKG_CONFIG
+PKG_INSTALLDIR(['${usrlib_execdir}/pkgconfig'])
+
+# - bash-completion ------------------------------------------------------------
+
+#enable_bash_completion=yes
+AC_ARG_WITH([bashcompletiondir],
+ AS_HELP_STRING([--with-bashcompletiondir=DIR], [Bash completions directory]),
+ [],
+ [AS_IF([`$PKG_CONFIG --exists bash-completion`], [
+ with_bashcompletiondir=`$PKG_CONFIG --variable=completionsdir bash-completion`
+ ], [
+ with_bashcompletiondir=${datadir}/bash-completion/completions
+ ])
+])
+
+AC_SUBST([bashcompletiondir], [$with_bashcompletiondir])
+
+AC_ARG_ENABLE([bash-completion],
+ AS_HELP_STRING([--disable-bash-completion], [do not install bash completion files]),
+ [], [enable_bash_completion=yes]
+)
+
+AM_CONDITIONAL([BUILD_BASH_COMPLETION], [test "x$enable_bash_completion" = xyes])
+
# - debug ----------------------------------------------------------------------
AC_ARG_ENABLE([debug],
@@ -206,6 +241,7 @@ AC_MSG_RESULT([
debug: ${enable_debug}
systemd support: ${have_systemd}
+ bash-completion: ${enable_bash_completion}
Bindings:
perl: ${enable_perl}
--
2.30.2
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-02-24 16:22 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-24 16:22 [PATCH 1/2] Add bash-completion file for the location command Stefan Schantl
2023-02-24 16:22 ` [PATCH 2/2] Install bash-completion files Stefan Schantl
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox