Krolyxon
Commit 2495d96

Branches

Refs →

aurora.localbinaurora-run

51 lines · 2.1 KB · Bourne Again Shell (bash)

1#!/bin/bash
2# aurora-run: fuzzel-compatible front end for aurora's runner (needs aurora running).
3# aurora-run open the app runner (same as SUPER+R)
4# aurora-run -d [opts] dmenu: lines on stdin, the choice on stdout, exit 1 when cancelled
5# dmenu opts (fuzzel/dmenu spelling): -p/--prompt TEXT, -l/--lines N (0 = input only), --placeholder TEXT,
6# --password, --index (print the line number instead). Other fuzzel flags (-i, --width, -fn, ...) are ignored.
7
8dmenu=0 prompt="" placeholder="" lines="" password=0 index=0
9while [ $# -gt 0 ]; do
10 case $1 in
11 -d | --dmenu) dmenu=1 ;;
12 -p | --prompt) prompt=$2; shift ;;
13 --prompt=*) prompt=${1#*=} ;;
14 -l | --lines) lines=$2; shift ;;
15 --lines=*) lines=${1#*=} ;;
16 --placeholder) placeholder=$2; shift ;;
17 --placeholder=*) placeholder=${1#*=} ;;
18 --password | --password=*) password=1 ;;
19 --index) index=1 ;;
20 # ignored flags that take a separate value
21 -fn | -f | --font | -w | --width | --cache | --with-nth | --nth-delimiter | -a | --anchor | -o | --output) shift ;;
22 *) ;;
23 esac
24 shift
25done
26
27pid=$(pgrep -nf 'quickshell.*/aurora$|qs -c aurora$')
28[ -n "$pid" ] || { echo "aurora-run: aurora is not running" >&2; exit 2; }
29
30if [ "$dmenu" = 0 ]; then
31 exec qs -c aurora ipc call shell run
32fi
33
34# private dir on tmpfs: items, opts and the reply fifo (a password only ever passes through the fifo)
35dir=$(mktemp -d "${XDG_RUNTIME_DIR:-/tmp}/aurora-run.XXXXXX") || exit 2
36trap 'rm -rf "$dir"' EXIT
37[ -t 0 ] || cat > "$dir/items"
38printf 'prompt=%s\nplaceholder=%s\nlines=%s\npassword=%s\nindex=%s\n' \
39 "${prompt//$'\n'/ }" "${placeholder//$'\n'/ }" "$lines" "$password" "$index" > "$dir/opts"
40mkfifo "$dir/reply"
41exec 3<> "$dir/reply" # read-write: never blocks aurora's writer, and lets us time out below
42
43err=$(qs -c aurora ipc call shell dmenu "$dir" 2>&1)
44[ -z "$err" ] || { echo "aurora-run: $err" >&2; exit 2; }
45
46# reply is "<0|1>\n<value>\0"; give up if aurora goes away while we wait
47until IFS= read -r -d '' -t 1 -u 3 reply; do
48 kill -0 "$pid" 2>/dev/null || { echo "aurora-run: aurora exited" >&2; exit 2; }
49done
50[ "${reply%%$'\n'*}" = 0 ] || exit 1
51printf '%s\n' "${reply#*$'\n'}"