From d0b7456842829d4bb861987613925518a31420d8 Mon Sep 17 00:00:00 2001 From: manuel Date: Mon, 3 Jun 2024 11:38:05 +0300 Subject: [PATCH] [eos-bash-shared] added bash completion for show-location-info --- show-location-info | 25 +++++++++++++++++++------ show-location-info.completion | 16 ++++++++++++++++ 2 files changed, 35 insertions(+), 6 deletions(-) create mode 100644 show-location-info.completion diff --git a/show-location-info b/show-location-info index 7913a7d..26d1843 100755 --- a/show-location-info +++ b/show-location-info @@ -8,9 +8,18 @@ DIE() { exit 0 } +DumpOptions() { + local tmp="--${lopts//,/ --}" + tmp="${tmp//:/}" + echo "$tmp" +} +DumpItems() { + echo "${items[*]}" +} + Options() { local opts - local lopts="help,timeout:,tolower,url:" + local lopts="help,timeout:,tolower,url:,dump-all" local sopts="ht:lu:" opts="$(/usr/bin/getopt -o=$sopts --longoptions $lopts --name "$progname" -- "$@")" || { @@ -22,6 +31,10 @@ Options() { while true ; do case "$1" in + #--dump-options) DumpOptions; exit 0 ;; + #--dump-items) DumpItems; exit 0 ;; + --dump-all) DumpItems; DumpOptions; exit 0 ;; + -t | --timeout) timeout="$2" ; shift ;; -l | --tolower) tolower=yes ;; -u | --url) infourl="$2" ; shift ;; @@ -73,17 +86,17 @@ Main() { https://ipinfo.io https://ipapi.co ) + local infourl="" # info source + local url # supported values local items=(city country hostname ip loc org postal region timezone "") # "" means: all - source /etc/eos-script-lib-yad.conf || return 1 + Options "$@" - # info source - local infourl="$EOS_LOCATION_PROVIDER_URL" - local url + source /etc/eos-script-lib-yad.conf || return 1 - Options "$@" + [ "$infourl" ] || infourl="$EOS_LOCATION_PROVIDER_URL" if [ -n "$infourl" ] ; then # add the given url as first in list diff --git a/show-location-info.completion b/show-location-info.completion new file mode 100644 index 0000000..eda5153 --- /dev/null +++ b/show-location-info.completion @@ -0,0 +1,16 @@ +# bash completion for show-location-info -*- shell-script -*- + +_show-location-info_complete() { + COMPREPLY=( $(compgen -W "$1" -- "$cur") ) + [[ $COMPREPLY == *= ]] && compopt -o nospace + compopt -o nosort +} + +_show-location-info_() +{ + local cur prev #words cword split + _init_completion -s || return + + _show-location-info_complete "$(show-location-info --dump-all)" +} +complete -F _show-location-info_ show-location-info