From e5b4b0df5be39cb693f32fcba59289abfef0269a Mon Sep 17 00:00:00 2001 From: Steven Xu Date: Tue, 30 Sep 2025 20:28:12 +1000 Subject: [PATCH] feat: add the `@tnotify-prompt-regex` option --- scripts/notify.sh | 21 ++++++++++++--------- scripts/variables.sh | 2 ++ 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/scripts/notify.sh b/scripts/notify.sh index a1d9a06..36f9c99 100755 --- a/scripts/notify.sh +++ b/scripts/notify.sh @@ -46,14 +46,17 @@ if [[ ! -f "$PID_FILE_PATH" ]]; then # If pane not yet monitored complete_message="Tmux pane task completed!" fi - # Create bash suffix list - # NOTE: Looks complicated but uses shell parameter expansion - # see https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Shell-Parameter-Expansion - prompt_suffixes="$(get_tmux_option "$prompt_suffixes" "$prompt_suffixes_default")" - prompt_suffixes=${prompt_suffixes// /} # Remove whitespace - prompt_suffixes=${prompt_suffixes//,/|} # Replace comma with or operator - prompt_suffixes=$(escape_glob_chars "$prompt_suffixes") - prompt_suffixes="\(${prompt_suffixes}\)$" + prompt_regex_value="$(get_tmux_option "$prompt_regex" "$prompt_regex_default")" + if [[ -z "$prompt_regex_value" ]]; then + # Create bash suffix list + # NOTE: Looks complicated but uses shell parameter expansion + # see https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Shell-Parameter-Expansion + prompt_regex_value="$(get_tmux_option "$prompt_suffixes" "$prompt_suffixes_default")" + prompt_regex_value=${prompt_regex_value// /} # Remove whitespace + prompt_regex_value=${prompt_regex_value//,/|} # Replace comma with or operator + prompt_regex_value=$(escape_glob_chars "$prompt_regex_value") + prompt_regex_value="\(${prompt_regex_value}\)$" + fi # Check process status every 10 seconds to see if has is finished while true; do @@ -62,7 +65,7 @@ if [[ ! -f "$PID_FILE_PATH" ]]; then # If pane not yet monitored # run tests to determine if work is done # if so, break and notify - if echo "$output" | tail -n2 | grep -e $prompt_suffixes &> /dev/null; then + if echo "$output" | tail -n2 | grep -e $prompt_regex_value &> /dev/null; then # tmux display-message "$@" if [[ "$1" == "true" ]]; then tmux switch -t \$"$SESSION_ID" diff --git a/scripts/variables.sh b/scripts/variables.sh index d8f28b4..5a0f824 100644 --- a/scripts/variables.sh +++ b/scripts/variables.sh @@ -17,6 +17,8 @@ export PID_FILE_PATH="${PID_DIR}/${PANE_ID}.pid" ## Tnotify tmux options export prompt_suffixes="@tnotify-prompt-suffixes" export prompt_suffixes_default="$,#,%" +export prompt_regex="@tnotify-prompt-regex" +export prompt_regex_default="" export custom_notify_command="@tnotify-custom-cmd" export custom_notify_command_default="bash ~/Desktop/test.bash"