This commit is contained in:
turtlebasket
2026-03-05 13:25:51 -08:00
parent 7ca47853f9
commit 26e442f8f0
5 changed files with 157 additions and 32 deletions

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env python3
#
# ntfy-bell - run a command, forwarding OSC 9 notifications and BEL to ntfy
# ntfy-bell - run a command, forwarding OSC 9 notifications to ntfy
#
# Usage:
# ntfy-bell <command> [args...]
@@ -102,9 +102,9 @@ def _copy_winsize(src_fd: int, dst_fd: int) -> None:
def main() -> int:
topic = os.environ.get("BELL2NTFY_TOPIC")
topic = os.environ.get("NTFY_ME_TOPIC")
if not topic:
print("Error: environment variable BELL2NTFY_TOPIC not set", file=sys.stderr)
print("Error: environment variable NTFY_ME_TOPIC not set", file=sys.stderr)
return 2
if len(sys.argv) < 2:
@@ -155,7 +155,6 @@ def main() -> int:
signal.signal(signal.SIGWINCH, _on_winch)
osc_last_sent = 0.0
bel_last_sent = 0.0
cooldown_s = 1.5
parse_buf = bytearray()
stdin_eof_sent = False
@@ -224,19 +223,6 @@ def main() -> int:
except Exception:
pass
if bytes([BEL]) in data and parse_buf.find(OSC9_PREFIX) == -1:
now = time.time()
if now - bel_last_sent >= cooldown_s:
bel_last_sent = now
try:
notify_ntfy(
topic=topic,
title="Terminal bell",
message=f"BEL from: {' '.join(cmd)}",
)
except Exception:
pass
finally:
if stdin_fd is not None and stdin_is_tty and old_tty_attrs is not None:
try: