Omarchy menu helpers

Get more stuff out of the terminal
This commit is contained in:
David Heinemeier Hansson
2026-05-08 12:40:37 +02:00
parent 129c39448c
commit cbf4044c70
3 changed files with 99 additions and 0 deletions
+45
View File
@@ -0,0 +1,45 @@
#!/bin/bash
# omarchy:summary=Pick a file with Walker
# omarchy:group=menu
# omarchy:name=file
# omarchy:args=label paths formats [walker args...]
# omarchy:examples=omarchy menu file "Select image" "$HOME/Pictures" "jpg png webp"|omarchy-menu-file "Select media" "$HOME/Pictures:$HOME/Videos" "jpg png mp4 mov" --width 800
set -euo pipefail
if (( $# < 3 )); then
echo "Usage: omarchy-menu-file <label> <paths> <formats> [walker args...]" >&2
exit 1
fi
label="$1"
paths_arg="$2"
formats_arg="$3"
shift 3
IFS=: read -r -a paths <<<"$paths_arg"
read -r -a formats <<<"$formats_arg"
if (( ${#paths[@]} == 0 || ${#formats[@]} == 0 )); then
echo "Usage: omarchy-menu-file <label> <paths> <formats> [walker args...]" >&2
exit 1
fi
for path in "${paths[@]}"; do
[[ -e $path ]] || { echo "Path not found: $path" >&2; exit 1; }
done
find_args=("${paths[@]}" -type f "(")
for format in "${formats[@]}"; do
if (( ${#find_args[@]} > ${#paths[@]} + 3 )); then
find_args+=(-o)
fi
format="${format#.}"
find_args+=(-iname "*.$format")
done
find_args+=(")")
find "${find_args[@]}" -printf '%T@\t%p\n' 2>/dev/null | sort -rn | cut -f2- |
omarchy-launch-walker --dmenu --width 800 --minheight 1 --maxheight 500 -p "$label…" "$@" 2>/dev/null
+16
View File
@@ -0,0 +1,16 @@
#!/bin/bash
# omarchy:summary=Prompt for text input with Walker
# omarchy:group=menu
# omarchy:name=input
# omarchy:args=prompt [walker args...]
# omarchy:examples=omarchy menu input Reminder|omarchy-menu-input "Reminder in minutes" --width 400
set -euo pipefail
prompt="${1:-Input}"
if (( $# > 0 )); then
shift
fi
omarchy-launch-walker --dmenu --inputonly --width 295 --minheight 1 --maxheight 1 -p "$prompt…" "$@" 2>/dev/null
+38
View File
@@ -0,0 +1,38 @@
#!/bin/bash
# omarchy:summary=Pick one option with Walker
# omarchy:group=menu
# omarchy:name=select
# omarchy:args=prompt option... [-- walker args...]
# omarchy:examples=omarchy menu select Format jpg png|omarchy-menu-select Resolution 4k 1080p 720p -- --width 400
set -euo pipefail
if (( $# < 2 )); then
echo "Usage: omarchy-menu-select <prompt> <option>... [-- walker args...]" >&2
exit 1
fi
prompt="$1"
shift
options=()
walker_args=()
while (( $# > 0 )); do
if [[ $1 == "--" ]]; then
shift
walker_args=("$@")
break
fi
options+=("$1")
shift
done
if (( ${#options[@]} == 0 )); then
echo "Usage: omarchy-menu-select <prompt> <option>... [-- walker args...]" >&2
exit 1
fi
printf '%s\n' "${options[@]}" | omarchy-launch-walker --dmenu --width 295 --minheight 1 --maxheight 300 -p "$prompt…" "${walker_args[@]}" 2>/dev/null