Skip to content

Commit

Permalink
🔀 Merge pull request #21 from ntwk/bug/cancel-monitoring
Browse files Browse the repository at this point in the history
Improves method of getting unique target ID's
  • Loading branch information
rickstaa authored Apr 17, 2021
2 parents 52b086b + 6553f4d commit f585fef
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 25 deletions.
7 changes: 0 additions & 7 deletions scripts/cancel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@ CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$CURRENT_DIR/helpers.sh"
source "$CURRENT_DIR/variables.sh"

# Get pane id
SESSION_NR=$(tmux list-sessions | grep "(attached)" | awk '{print $1}' | tr -d :)
WINDOW_NR=$(tmux list-windows | grep "(active)" | awk '{print $1}' | tr -d :)
PANE_NR=$(tmux list-panes | grep "active" | awk -F\] '{print $3}' | awk '{print $1}' | tr -d %)
PANE_ID=$(detox_file_name "s_${SESSION_NR}_w${WINDOW_NR}_p${PANE_NR}")
PID_FILE_PATH="${PID_DIR}/${PANE_ID}.pid"

# Cancel pane monitoring if active
if [[ -f "$PID_FILE_PATH" ]]; then

Expand Down
7 changes: 0 additions & 7 deletions scripts/helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,3 @@ set_tmux_option() {
local value="$2"
tmux set-option -gq "$option" "$value"
}

## Detox file names
# Makes sure invalid chars are removed from a filename
detox_file_name(){
local file_name="$1"
echo "${file_name//[^A-Za-z0-9._-]/_}"
}
15 changes: 4 additions & 11 deletions scripts/notify.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,6 @@ verbose_enabled() {

## Main script

# Get pane id
SESSION_NR=$(tmux list-sessions | grep "(attached)" | awk '{print $1}' | tr -d :)
WINDOW_NR=$(tmux list-windows | grep "(active)" | awk '{print $1}' | tr -d :)
PANE_NR=$(tmux list-panes | grep "active" | awk '{print $1}' | tr -d :)
PANE_ID=$(detox_file_name "s_${SESSION_NR}_w${WINDOW_NR}_p${PANE_NR//%}")
PID_FILE_PATH="${PID_DIR}/${PANE_ID}.pid"

# Monitor pane if it is not already monitored
if [[ ! -f "$PID_FILE_PATH" ]]; then # If pane not yet monitored

Expand All @@ -60,7 +53,7 @@ if [[ ! -f "$PID_FILE_PATH" ]]; then # If pane not yet monitored
while true; do

# capture pane output
output=$(tmux capture-pane -pt "$PANE_NR")
output=$(tmux capture-pane -pt %"$PANE_ID")

# run tests to determine if work is done
# if so, break and notify
Expand All @@ -69,9 +62,9 @@ if [[ ! -f "$PID_FILE_PATH" ]]; then # If pane not yet monitored
"$" | "#" )
# tmux display-message "$@"
if [[ "$1" == "refocus" ]]; then
tmux switch -t "$SESSION_NR"
tmux select-window -t "$WINDOW_NR"
tmux select-pane -t "$PANE_NR"
tmux switch -t \$"$SESSION_ID"
tmux select-window -t @"$WINDOW_ID"
tmux select-pane -t %"$PANE_ID"
fi
# notify-send does not always work due to changing dbus params
# see https://superuser.com/questions/1118878/using-notify-send-in-a-tmux-session-shows-error-no-notification#1118896
Expand Down
6 changes: 6 additions & 0 deletions scripts/variables.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
export SUPPORTED_VERSION="1.9"
export PID_DIR=~/.tmux/notify

# Get ID's
export SESSION_ID=$(tmux display-message -p '#{session_id}' | tr -d $)
export WINDOW_ID=$(tmux display-message -p '#{window_id}' | tr -d @)
export PANE_ID=$(tmux display-message -p '#{pane_id}' | tr -d %)
export PID_FILE_PATH="${PID_DIR}/${PANE_ID}.pid"

## Tnotify tmux options

# Notification verbosity settings
Expand Down

0 comments on commit f585fef

Please sign in to comment.