~mil/mepo

05ea15d8cf1ff70a04ba016549c3c30450a00ddd — Miles Alan 2 years ago cc63479 scripts-rework-and-central-menu
Add first pass at generated central script menu

- Uses all scripts in $PATH prefixed with mepo_ as valid entries
- Sources each script calling with arg nonexistentfn
- If $DISPLAYNAME is set by the script, that will show as the menu entry
  for that script
- Picking entry in menu runs the script consequently
3 files changed, 50 insertions(+), 21 deletions(-)

A scripts/mepo_ui_central_menu.sh
M scripts/mepo_ui_dbg_api.sh
M src/config.zig
A scripts/mepo_ui_central_menu.sh => scripts/mepo_ui_central_menu.sh +23 -0
@@ 0,0 1,23 @@
#!/usr/bin/env sh

menuoptions() {
  for SCRIPT in $(echo "$PATH" | tr : '\n' | xargs ls -1 2>/dev/null | grep -E ^mepo_); do
    unset DISPLAYNAME
    . "$SCRIPT" nonexistentfn 2> /dev/null
    [ -z "$DISPLAYNAME" ] && continue
    echo "$DISPLAYNAME ^ $SCRIPT"
  done
}

main() {
  OPTIONS="$(menuoptions)"
  PRETTYNAMES="$(echo "$OPTIONS" | cut -d^ -f1)"
  PICKED="$(
    echo "$PRETTYNAMES" | 
    PROMPT="Run Script" mepo_ui_helper_menu.sh
  )"
  RUNSCRIPT="$(echo "$OPTIONS" | grep "$PICKED" | cut -d^ -f2)"
  eval "$RUNSCRIPT"
}

if [ -n "$1" ]; then "$@"; else main; fi

M scripts/mepo_ui_dbg_api.sh => scripts/mepo_ui_dbg_api.sh +25 -20
@@ 1,25 1,30 @@
#!/usr/bin/env sh
DISPLAYNAME="Debug API"

OPTIONS='
  bind_key (key) (command)
  center_on_coords (lat) (lon)
  center_on_mouse
  move_relative (x) (y)
  pin_add (is_structural) (lat) (lon) (name)
  pin_cycle (index)
  pin_deactivate
  pin_purge
  prefset (pref) (value)
  shellpipe (command)
  zoom_relative (index)
'
main() {
  OPTIONS='
    bind_key (key) (command)
    center_on_coords (lat) (lon)
    center_on_mouse
    move_relative (x) (y)
    pin_add (is_structural) (lat) (lon) (name)
    pin_cycle (index)
    pin_deactivate
    pin_purge
    prefset (pref) (value)
    shellpipe (command)
    zoom_relative (index)
  '

CMD="$(
  echo "$OPTIONS" |
    awk '{$1=$1};1' | 
    grep . | 
    mepo_ui_helper_menu.sh "Command"
)"
  CMD="$(
    echo "$OPTIONS" |
      awk '{$1=$1};1' | 
      grep . | 
      mepo_ui_helper_menu.sh "Command"
  )"

  echo "$CMD;"
}

if [ -n "$1" ]; then "$@"; else main; fi

echo "$CMD;"

M src/config.zig => src/config.zig +2 -1
@@ 34,6 34,7 @@ pub const DefaultBaseConfig =
    \\ bind_key cs q [cache_queueclear];
    \\ bind_key c c [quit];
    \\ # Scripts hotkeys;
    \\ bind_key _ c [shellpipe mepo_ui_central_menu.sh];
    \\ bind_key _ g [shellpipe mepo_ui_reposition_nominatim.sh];
    \\ bind_key s g [shellpipe mepo_ui_search_nominatim.sh];
    \\ bind_key _ b [shellpipe mepo_ui_search_overpass.sh];


@@ 63,7 64,7 @@ pub const DefaultBaseConfig =
    \\ bind_key _ e [preftoggle debug_vars];
    \\ bind_key _ s [preftoggle download_bar];
    \\ bind_key _ m [preftoggle tile_cache_network];
    \\ bind_key _ c [center_on_mouse];
    \\ bind_key s c [center_on_mouse];
    \\
    \\ # Signals;
    \\ bind_signal USR1 [zoom_relative 1];