From 27c2a028de1792a3c9fd1b9541a731161ed22a2f Mon Sep 17 00:00:00 2001 From: GeeF Date: Thu, 18 Aug 2016 17:51:44 +0200 Subject: [PATCH] Add helper to wait for text in pane Will wait for text showing up in a pane. If it doesnt match am error will be echoed --- lib/layout-helpers.sh | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/lib/layout-helpers.sh b/lib/layout-helpers.sh index b021d67..17f7cc3 100644 --- a/lib/layout-helpers.sh +++ b/lib/layout-helpers.sh @@ -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: @@ -372,3 +387,13 @@ __go_to_window_or_session_path() { run_cmd "clear" fi } + +__wait_for_text_helper() +{ + timeout $2 bash <&1 > /dev/null && break + done +EOT + echo $? +}