[eos-bash-shared] added bash completion for show-location-info

This commit is contained in:
manuel
2024-06-03 11:38:05 +03:00
parent 292e1f54a6
commit d0b7456842
2 changed files with 35 additions and 6 deletions
+19 -6
View File
@@ -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
Options "$@"
source /etc/eos-script-lib-yad.conf || return 1
# info source
local infourl="$EOS_LOCATION_PROVIDER_URL"
local url
Options "$@"
[ "$infourl" ] || infourl="$EOS_LOCATION_PROVIDER_URL"
if [ -n "$infourl" ] ; then
# add the given url as first in list
+16
View File
@@ -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