Skip to content

Commit

Permalink
Merge pull request #17 from rickstaa/15_add_focus_option
Browse files Browse the repository at this point in the history
✨ Adds auto refocus option
  • Loading branch information
ChanderG authored Nov 28, 2020
2 parents 941ac00 + a802850 commit 52b086b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ Use `prefix + I` to install.

## Usage

`prefix + m`: Start monitoring a pane to notify; exits after first notification.
`prefix + m`: Start monitoring a pane and notify when it finishes.

`prefix + alt + m`: Start monitoring a pane, return it in focus and notify when it finishes.

`prefix + M`: Cancel monitoring of a pane.

## Pre-requisites
Expand Down
8 changes: 7 additions & 1 deletion scripts/notify.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ verbose_enabled() {
# 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_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"

Expand Down Expand Up @@ -67,6 +67,12 @@ if [[ ! -f "$PID_FILE_PATH" ]]; then # If pane not yet monitored
lc=$(echo "$output" | tail -c2)
case $lc in
"$" | "#" )
# tmux display-message "$@"
if [[ "$1" == "refocus" ]]; then
tmux switch -t "$SESSION_NR"
tmux select-window -t "$WINDOW_NR"
tmux select-pane -t "$PANE_NR"
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
notify-send "$complete_message"
Expand Down
2 changes: 2 additions & 0 deletions tnotify.tmux
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@ fi
# Bind plugin keys
tmux unbind-key m
tmux unbind-key M
tmux unbind-key M-m
tmux bind-key m run-shell -b "$CURRENT_DIR/scripts/notify.sh"
tmux bind-key M run-shell -b "$CURRENT_DIR/scripts/cancel.sh"
tmux bind-key M-m run-shell -b "$CURRENT_DIR/scripts/notify.sh refocus"

0 comments on commit 52b086b

Please sign in to comment.