Skip to content

Add helper to wait for text in pane #74

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions lib/layout-helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,21 @@ balance_windows_horizontal() {
tmuxifier-tmux select-layout even-horizontal
}

# Wait for text to appear in a pane. Useful to wait before continuing execution
#
# Arguments:
# - $1: String to look for.
# - $2: Timeout if string does not show up.
# - $3: (optional) Target pane ID to send input to.
#
wait_for_text_event()
{
if [ "$(__wait_for_text_helper $@)" != 0 ]
then
echo "Timeout: Wait for text $1"
fi
}

# Send/paste keys to the currently active pane/window.
#
# Arguments:
Expand Down Expand Up @@ -372,3 +387,13 @@ __go_to_window_or_session_path() {
run_cmd "clear"
fi
}

__wait_for_text_helper()
{
timeout $2 bash <<EOT
while :; do
tmuxifier-tmux capture-pane -t "$session:$window.$3" -p | grep "$1" 2>&1 > /dev/null && break
done
EOT
echo $?
}