From 2ef4eb49ce223ffea38c7483617b339d0cb07b6d Mon Sep 17 00:00:00 2001 From: veg Date: Sat, 4 Jul 2026 09:39:45 +0000 Subject: [PATCH] fix: pin absolute script path in status-right widget The #() body runs with the tmux server's PATH; a bare 'party' silently broke the widget for uninstalled or non-standard-prefix hosts. --- party | 19 ++++++++++++++++++- tests/90-notifications.bats | 6 +++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/party b/party index b580934..343f803 100755 --- a/party +++ b/party @@ -430,6 +430,22 @@ compute_default_party_name() { printf 'party-%s\n' "$rand" } +# Absolute path to this script, for embedding in tmux server state that +# outlives this invocation (the status-right #() widget runs with the +# tmux server's PATH, which need not contain an installed `party`). +# $0 forms: absolute — take it; relative-with-slash — anchor to cwd; +# bare word — resolve via PATH, falling back to $0 verbatim. No `--` +# after command -v/dirname/basename: old illumos userland predates it, +# and $0 here never starts with '-'. +party_self_path() { + case "$0" in + /*) printf '%s\n' "$0" ;; + */*) printf '%s/%s\n' "$(cd "$(dirname "$0")" && pwd)" \ + "$(basename "$0")" ;; + *) command -v "$0" 2>/dev/null || printf '%s\n' "$0" ;; + esac +} + # After spawning the party server, configure status line and hooks. # All commands run against -S "$sock". Every literal name embedded @@ -469,8 +485,9 @@ EOF chgrp "$TMUX_PARTY_GROUP" "$notify_script" "$PARTY_TMUX" -S "$sock" set-option -s exit-empty on + party_self=$(party_self_path) "$PARTY_TMUX" -S "$sock" set-option -g status-right \ - "party: #(party who --short --socket $sock 2>/dev/null)" + "party: #($party_self who --short --socket $sock 2>/dev/null)" # Join/leave broadcast. Hook bodies fan a display-message out to # every attached client of THIS server via the notify helper script. # tmux substitutes #{client_user} before running the shell command. diff --git a/tests/90-notifications.bats b/tests/90-notifications.bats index 6eb06a5..34bf63e 100644 --- a/tests/90-notifications.bats +++ b/tests/90-notifications.bats @@ -19,12 +19,16 @@ party_rec() { printf '%s/party-%s:%s.d/roster\n' "$PARTY_SOCKET_DIR" "$USER" "$1 [[ "$out" == *"client-detached"* ]] } -@test "status-right widget is configured" { +@test "status-right widget is configured with an absolute self path" { "$PARTY_BIN" host srtest rec=$(party_rec srtest) sock=$(awk -F= '$1=="SOCKET"{print $2}' "$rec") sr=$(tmux -S "$sock" show-options -gv status-right) [[ "$sr" == *"party who --short"* ]] + # The #() body is executed with the tmux server's PATH, which need + # not contain an installed `party` — the widget must pin the absolute + # path of the script that hosted the party. + [[ "$sr" == "party: #(/"* ]] } @test "client-attached hook invokes a notify helper that broadcasts display-message" {