executable_voxtype-polybar.sh

 1#!/bin/bash
 2# Wrapper for voxtype status to output polybar-friendly format
 3#
 4# Usage:
 5#   voxtype-polybar.sh         - output status for polybar
 6#   voxtype-polybar.sh toggle  - launch if stopped, toggle recording if running
 7#
 8# Environment variables (set in polybar module):
 9#   color_foreground - default text color
10#   color_primary    - accent/alert color (used for recording)
11#   color_secondary  - secondary accent (used for transcribing)
12
13# Respect XDG_STATE_HOME for log location
14state_dir="${XDG_STATE_HOME:-$HOME/.local/state}/voxtype"
15log_file="$state_dir/voxtype.log"
16
17output=$(voxtype status --format json 2>/dev/null)
18
19if [[ -z "$output" ]]; then
20	echo ""
21	exit 0
22fi
23
24alt=$(echo "$output" | jq -r '.alt // "idle"')
25
26# Handle toggle action
27if [[ "$1" == "toggle" ]]; then
28	if [[ "$alt" == "stopped" ]]; then
29		mkdir -p "$state_dir"
30		setsid fish -c "voxtype" >>"$log_file" 2>&1 &
31	else
32		voxtype record toggle
33	fi
34	exit 0
35fi
36
37# Use env vars if set, otherwise fall back to reasonable defaults
38fg="${color_foreground:-#cdd6f4}"
39recording="${color_primary:-#f38ba8}"
40transcribing="${color_secondary:-#f9e2af}"
41
42case "$alt" in
43stopped)
44	echo ""
45	;;
46idle)
47	echo "󰍬"
48	;;
49recording)
50	echo "%{F${recording}}󰍬%{F-}"
51	;;
52transcribing)
53	echo "%{F${transcribing}}󰮍%{F-}"
54	;;
55error)
56	echo "%{F${recording}}%{F-}"
57	;;
58*)
59	echo "󰍬"
60	;;
61esac