Skip to content

Commit

Permalink
[eos-bash-shared] added bash completion for show-location-info
Browse files Browse the repository at this point in the history
  • Loading branch information
manuel-192 committed Jun 3, 2024
1 parent 292e1f5 commit d0b7456
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
25 changes: 19 additions & 6 deletions show-location-info
Original file line number Diff line number Diff line change
Expand Up @@ -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" -- "$@")" || {
Expand All @@ -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 ;;
Expand Down Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions show-location-info.completion
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit d0b7456

Please sign in to comment.