Introduce omarchy-shell -q for fire and forget

This commit is contained in:
David Heinemeier Hansson
2026-05-20 14:24:19 +02:00
parent ed3320cb8d
commit c87bfb8da8
8 changed files with 34 additions and 31 deletions
+26 -7
View File
@@ -1,19 +1,30 @@
#!/bin/bash
# omarchy:summary=Send an IPC call to the running Omarchy shell
# omarchy:args=<target> <method> [args...]
# omarchy:args=[-q] <target> <method> [args...]
# omarchy:examples=omarchy shell shell ping | omarchy-shell menu toggle root
QUIET=0
if [[ ${1:-} == "-q" ]]; then
QUIET=1
shift
fi
if [[ $# -eq 0 || $1 == "-h" || $1 == "--help" ]]; then
cat <<USAGE
Usage: omarchy-shell <target> <method> [args...]
Usage: omarchy-shell [-q] <target> <method> [args...]
Forwards an IPC call to the running Omarchy shell. The shell is expected
to already be running; this command does not start it.
Options:
-q Quiet best-effort mode. Suppress output and return success even when
the shell, target, method, or arguments are unavailable.
Examples:
omarchy-shell shell ping
omarchy-shell shell summon omarchy.settings "{}"
omarchy-shell -q bar refreshIndicators
omarchy-shell shell listPlugins
omarchy-shell menu toggle root
USAGE
@@ -21,11 +32,13 @@ USAGE
fi
if (( $# < 2 )); then
(( QUIET )) && exit 0
echo "Usage: omarchy-shell <target> <method> [args...]" >&2
exit 1
fi
if [[ -z ${OMARCHY_PATH:-} ]]; then
(( QUIET )) && exit 0
echo "OMARCHY_PATH is not set" >&2
exit 1
fi
@@ -36,6 +49,8 @@ if [[ $1 == "shell" && ( $2 == "summon" || $2 == "toggle" ) && $# -eq 3 ]]; then
set -- "$1" "$2" "$3" "{}"
fi
export OMARCHY_SHELL_QUIET="$QUIET"
perl -MCwd=abs_path -MEncode=encode,decode -MSocket -MIO::Handle \
-e '
binmode STDOUT, ":encoding(UTF-8)";
@@ -82,10 +97,12 @@ perl -MCwd=abs_path -MEncode=encode,decode -MSocket -MIO::Handle \
my $function = decode("UTF-8", shift @ARGV);
my @args = map { decode("UTF-8", $_) } @ARGV;
my $runtime_dir = $ENV{"XDG_RUNTIME_DIR"} || "/run/user/$<";
my $quiet = ($ENV{"OMARCHY_SHELL_QUIET"} || "") eq "1";
my $payload = chr(3) . qstring($target) . qstring($function) . pack("N", scalar @args) . join("", map { qstring($_) } @args);
my @candidates;
if (!defined $shell_qml) {
exit 0 if $quiet;
print STDERR "omarchy-shell config not found: $shell_qml_arg\n";
exit 1;
}
@@ -124,22 +141,24 @@ perl -MCwd=abs_path -MEncode=encode,decode -MSocket -MIO::Handle \
next unless length($response);
my $code = ord(substr($response, 0, 1));
if ($code == 5) {
exit 0 if $quiet;
print_success($response);
exit 0;
} elsif ($code == 2) {
print STDERR "Target not found.\n";
print STDERR "Target not found.\n" unless $quiet;
} elsif ($code == 3) {
print STDERR "Function not found.\n";
print STDERR "Function not found.\n" unless $quiet;
} elsif ($code == 4) {
print STDERR "Invalid arguments.\n";
print STDERR "Invalid arguments.\n" unless $quiet;
} else {
print STDERR "Unexpected IPC response: $code\n";
print STDERR "Unexpected IPC response: $code\n" unless $quiet;
}
exit 1;
exit($quiet ? 0 : 1);
}
close($client);
}
exit 0 if $quiet;
print STDERR "omarchy-shell is not running\n";
exit 1;
' "$SHELL_QML" "$@"