~mil/mepo

ref: 041d978478ae78e241802ca9d750677e101c3f5b mepo/scripts/mepo_ui_central_menu.sh -rwxr-xr-x 1.2 KiB
041d9784 — Miles Alan Show progress in % complete for transfer datum on tiles while downloading 5 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env sh

menuoptions() {
  echo "$PATH" | tr : '\n' | xargs ls -1 2>/dev/null | grep mepo_ | while read -r SCRIPT; do
    unset DISPLAYNAME
    ASYNC=0
    eval "$(cat "$(which "$SCRIPT")" | grep -E '^(DISPLAYNAME|HOTKEY|ASYNC)=' )"
    [ -z "$DISPLAYNAME" ] && continue
    echo "$DISPLAYNAME ^ $SCRIPT ^ $HOTKEY ^ $ASYNC"
  done | uniq | sort -d
}

main() {
  OPTIONS="$(menuoptions)"
  PRETTYNAMES="$(echo "$OPTIONS" | cut -d^ -f1 | uniq)"
  PICKED="$(
    printf %b "$PRETTYNAMES\nī™• Close Menu" |
    PROMPT="Run Script" mepo_ui_helper_menu.sh
  )"
  [ -z "$PICKED" ] && return
  [ "$PICKED" = "Close Menu" ] && return
  RUNSCRIPT="$(echo "$OPTIONS" | grep "$PICKED" | head -n1 | cut -d^ -f2)"
  ASYNC="$(echo "$OPTIONS" | grep "$PICKED" | head -n1 | cut -d^ -f4)"

  # E.g. if script is tagged with variable ASYNC, run the script
  # as an asynchronous shellpipe (e.g. wont lock UI etc).
  #
  # Otherwise, runs script directly (not as a shellpipe since that would
  # need to wait for this script (which is also run from shellpipe) to return
  # but directly evals the script
  if echo "$ASYNC" | grep -q 1; then
    echo "shellpipe 1 $RUNSCRIPT;"
  else
    eval "$RUNSCRIPT"
  fi
}

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