aboutsummaryrefslogtreecommitdiffstats
path: root/bin/udt-steps
blob: da4aca0f10dccec62359fba4619d3333563c0e0d (plain)
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
#!/bin/bash
# udt-steps: hand a consumer's pending manual steps to the steps window.
# Copyright (C) 2026 Danilo M. <danix@danix.xyz>
# Licensed under the GNU General Public License v2 only.
#
# Usage: <producer> | udt-steps NAME
#
# stdin becomes the NAME tab of quickshell's steps window, one file per
# consumer under ~/.cache/udt/steps/. Empty stdin clears the tab: a consumer
# that is up to date has nothing to ask for. Either way the running shell is
# poked over IPC, which reloads the tabs and opens the window when any remain.
#
# Format: a line indented two spaces is a command, and a run of them is one
# block with its own copy button. Everything else is prose. So the root
# commands producers already printed for a terminal read the same here.

name="${1:?usage: udt-steps NAME}"
case "$name" in
    *[!a-z0-9-]*) echo "udt-steps: bad name '$name'" >&2; exit 2 ;;
esac

dir="$HOME/.cache/udt/steps"
mkdir -p "$dir"
text="$(cat)"
if [ -z "$text" ]; then
    rm -f "$dir/$name"
else
    # Atomic, so the shell never reads half a file.
    printf '%s\n' "$text" > "$dir/.$name.tmp" && mv "$dir/.$name.tmp" "$dir/$name"
fi

repo="$(dirname "$(readlink -f "$0")")/.."
qs_dir="$(realpath -m "$repo/../quickshell/appearance")"
[ -f "$qs_dir/shell.qml" ] && command -v qs >/dev/null 2>&1 &&
    timeout 5 qs -p "$qs_dir" ipc call appearance steps >/dev/null 2>&1
exit 0