#!/usr/bin/env zsh# ── music.zsh : rmpc / MPD helpers ───────────────────────────────────────────# Playback itself lives in MPD, so rmpc can come and go without interrupting a# track. These are the bits that are awkward to remember as raw systemctl.# ── Discord Rich Presence ────────────────────────────────────────────────────# rmpc-discord-presence watches MPD over its idle protocol and mirrors playback# to Discord. Toggling flips BOTH the running state and the boot state, so# turning it off keeps it off after a reboot -- which is the whole point of# turning it off._RPC_UNIT=rmpc-discord-presence.service
rpc(){# ── Rose Pine, tty-gated ──localFOAM=''GOLD=''LOVE=''SUBTLE=''TEXT=''B=''R=''if[[ -z "${NO_COLOR:-}"&& -t 1]]; thenFOAM=$'\033[38;2;156;207;216m'GOLD=$'\033[38;2;246;193;119m'LOVE=$'\033[38;2;235;111;146m'SUBTLE=$'\033[38;2;144;140;170m'TEXT=$'\033[38;2;224;222;244m'B=$'\033[1m'R=$'\033[0m'filocal active enabled
_rpc_state(){active=$(systemctl --user is-active "$_RPC_UNIT"2>/dev/null)enabled=$(systemctl --user is-enabled "$_RPC_UNIT"2>/dev/null)} _rpc_report(){ _rpc_state
local dot col
if[[$active== active ]]; thendot="●"col=$FOAM; elsedot="○"col=$SUBTLE; fiprintf" ${col}${B}%s discord rpc %s${R}${SUBTLE}(%s at boot)${R}\n"\"$dot""${active:-unknown}""${enabled:-unknown}"}case"${1:-toggle}"in -h|--help|help)printf"%s\n"\"rpc — Discord Rich Presence for rmpc/MPD"\""\"usage: rpc [on|off|status|log|restart]"\" (nothing) toggle it, running state and boot state together"\" on enable + start"\" off stop + disable"\" status is it running, does it start at boot"\" log follow the journal (Ctrl-C to leave)"\" restart bounce it, e.g. after editing the script"\""\"unit: $_RPC_UNIT"\"script: ~/.config/rmpc/scripts/discord-presence" ;;
status|s) _rpc_report
systemctl --user --no-pager --lines=3 status "$_RPC_UNIT"2>/dev/null \ | sed -n '/^ *Active:/,$p' | sed "s/^/ ${SUBTLE}/;s/\$/${R}/" ;;
log|logs|l) journalctl --user -u "$_RPC_UNIT" -f -n 40 ;;
restart|r) systemctl --user restart "$_RPC_UNIT"&& _rpc_report
;;
on|start|1) systemctl --user enable --now "$_RPC_UNIT"2>/dev/null && _rpc_report
;;
off|stop|0) systemctl --user disable --now "$_RPC_UNIT"2>/dev/null && _rpc_report
;;
toggle|t) _rpc_state
if[[$active== active ]]; then systemctl --user disable --now "$_RPC_UNIT"2>/dev/null
else systemctl --user enable --now "$_RPC_UNIT"2>/dev/null
fi _rpc_report
;;
*)printf" ${LOVE}rpc: unknown argument '%s'${R}${SUBTLE}try: rpc --help${R}\n""$1"return1 ;;
esac}aliasdiscordrpc='rpc'