feat(@scripts): add voice toggle command

Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
This commit is contained in:
Natalie 2026-05-17 18:18:15 -07:00
parent fedabb0924
commit 45daeb61ba
2 changed files with 64 additions and 0 deletions

View file

@ -1026,6 +1026,53 @@ if [ "${RCLAUDE_LIB_ONLY:-0}" = "1" ]; then
return 0 2>/dev/null || exit 0 return 0 2>/dev/null || exit 0
fi fi
cmd_voice() {
# `rclaude voice` — toggle / inspect the rvoice push-to-talk binding.
# rvoice itself is a separate script (bin/rvoice) driven by Hammerspoon.
# This subcommand just gates whether the Hammerspoon tap is active by
# writing/removing a sentinel file the lua module checks at load.
_flag=${XDG_STATE_HOME:-$HOME/.local/state}/rclaude/voice-disabled
mkdir -p "$(dirname "$_flag")" 2>/dev/null
_action=${1:-status}
case $_action in
on|enable)
rm -f "$_flag"
_reload_hammerspoon
echo "rvoice: enabled (Right ⌥ = push-to-talk)" ;;
off|disable)
: > "$_flag"
_reload_hammerspoon
echo "rvoice: disabled (delete $_flag or 'rclaude voice on' to re-enable)" ;;
status)
if [ -f "$_flag" ]; then echo "rvoice: disabled"
else echo "rvoice: enabled"; fi
command -v rvoice >/dev/null 2>&1 \
&& echo " rvoice binary: $(command -v rvoice)" \
|| echo " rvoice binary: NOT INSTALLED" ;;
test|target)
command -v rvoice >/dev/null 2>&1 || { echo "rclaude: rvoice not on PATH" >&2; exit 1; }
rvoice target ;;
log)
command -v rvoice >/dev/null 2>&1 && rvoice log ;;
*)
cat <<EOF
usage: rclaude voice {on|off|status|target|log}
on/off toggle Hammerspoon push-to-talk binding
status show whether voice is enabled
target show what host/tmux session rvoice would inject into
log tail the rvoice action log
EOF
exit 2 ;;
esac
}
# Tell a running Hammerspoon to reload its config (so the voice on/off
# sentinel takes effect immediately). No-op if Hammerspoon isn't running.
_reload_hammerspoon() {
osascript -e 'tell application "Hammerspoon" to reload config' 2>/dev/null || true
}
cmd_setup() { cmd_setup() {
# Args: # Args:
# (none) → install on every host in scan_hosts # (none) → install on every host in scan_hosts
@ -1051,6 +1098,7 @@ case ${1:-} in
resume) shift; cmd_resume "$@"; exit ;; resume) shift; cmd_resume "$@"; exit ;;
triage) shift; cmd_triage "$@"; exit ;; triage) shift; cmd_triage "$@"; exit ;;
setup|install) shift; cmd_setup "$@"; exit ;; setup|install) shift; cmd_setup "$@"; exit ;;
voice) shift; cmd_voice "$@"; exit ;;
-v|--version) cmd_version; exit ;; -v|--version) cmd_version; exit ;;
-h|--help|help) cmd_help; exit ;; -h|--help|help) cmd_help; exit ;;
esac esac

View file

@ -33,6 +33,22 @@ end
local RVOICE = resolveRvoice() local RVOICE = resolveRvoice()
local holding = false local holding = false
-- rvoice can be toggled off via `rclaude voice off`, which drops a sentinel
-- file. If present at load time, skip starting the eventtap entirely so the
-- Right-⌥ key behaves normally. `rclaude voice on` calls reloadConfig which
-- re-runs this module.
local DISABLE_FLAG = (os.getenv("XDG_STATE_HOME") or (os.getenv("HOME") .. "/.local/state"))
.. "/rclaude/voice-disabled"
local function isDisabled()
local f = io.open(DISABLE_FLAG, "r")
if f then f:close(); return true end
return false
end
if isDisabled() then
hs.alert.show("rvoice: disabled (rclaude voice on to re-enable)")
return {}
end
-- Run rvoice <cmd> in the background; capture stderr to the system log so -- Run rvoice <cmd> in the background; capture stderr to the system log so
-- failures are visible via Hammerspoon's console. -- failures are visible via Hammerspoon's console.
local function run(cmd) local function run(cmd)