diff options
| author | Robert Günzler <r@gnzler.io> | 2026-09-27 17:38:39 +0200 |
|---|---|---|
| committer | Robert Günzler <r@gnzler.io> | 2026-09-27 17:38:39 +0200 |
| commit | 0860db73ae6fd9a6f6347219d820bf026a6b8b91 (patch) | |
| tree | 11318c3670d1c32c5aa0bf404c22fba3bf63fc53 /bin/libfuzl.sh | |
| parent | 4e34cbf9673aeaba252e01df554a0d204e83c5e2 (diff) | |
| download | dotfiles-0860db73ae6fd9a6f6347219d820bf026a6b8b91.tar.gz | |
Automated-commit-by: dots Signed-off-by: Robert Günzler <r@gnzler.io>
Diffstat (limited to 'bin/libfuzl.sh')
| -rw-r--r-- | bin/libfuzl.sh | 39 |
1 files changed, 33 insertions, 6 deletions
diff --git a/bin/libfuzl.sh b/bin/libfuzl.sh index a28c861..c53a71f 100644 --- a/bin/libfuzl.sh +++ b/bin/libfuzl.sh @@ -4,9 +4,12 @@ set -eu +# TODO: use custom-1 somehow + # pick up configuration FUZL_PROMPT=${FUZL_PROMPT:-fuzl} FUZL_ICON=${FUZL_ICON:-} +FUZL_CLI_ARGS=${FUZL_CLI_ARGS:-$@} fuzl_try() { [ "$1" == "--" ] && shift 1 @@ -89,6 +92,11 @@ fuzl_loading_cancel() { FUZL_ACTIONS=() +fuzl_action_reset() { + # reset actions + FUZL_ACTIONS=() +} + fuzl_action_add() { local action="${1:?}" icon="${2:?}" shift 2 @@ -97,17 +105,36 @@ fuzl_action_add() { FUZL_ACTIONS+=("${action}\t${icon}\t${*}") } +fuzl_action_help() { + echo "usage: $FUZL_PROMPT [action]" + echo + for action in "${FUZL_ACTIONS[@]}"; do + echo -e " $action" + done + echo + exit 0 +} + fuzl_action_menu() { local action - action=$(printf '%s\n' "${FUZL_ACTIONS[@]}" | - FUZL_PROMPT="$FUZL_PROMPT: $*" fuzl_menu $FUZL_MENU_FILTER --with-nth='{2} {3..}' --accept-nth=1) + # only actually ask if action wasn't provided on cli + action=${FUZL_CLI_ARGS} + if [[ "$action" == "--help" ]]; then + fuzl_action_help + fi + if test -z "$action"; then + action=$(printf '%s\n' "${FUZL_ACTIONS[@]}" | + FUZL_PROMPT="$FUZL_PROMPT: $*" fuzl_menu $FUZL_MENU_FILTER --with-nth='{2} {3..}' --accept-nth=1) + fi - # reset actions - FUZL_ACTIONS=() + fuzl_action_reset - test -n "$action" || return - eval "${FUZL_PROMPT}_${action}" "'$*'" + if declare -f "${FUZL_PROMPT}_${action}" >/dev/null; then + eval "${FUZL_PROMPT}_${action}" "'$*'" + else + return 1 + fi } # setup common debug helper |