From 18f4d1099e06f29ea45c00831abd3458ba504fa0 Mon Sep 17 00:00:00 2001 From: Bruno Sutic Date: Thu, 28 Aug 2014 12:58:07 +0200 Subject: [PATCH] Spin a spinner while tmux sessions are restored Closes #16 --- CHANGELOG.md | 1 + scripts/session_restorer.sh | 3 +++ scripts/spinner_helpers.sh | 8 ++++++++ scripts/tmux_spinner.sh | 29 +++++++++++++++++++++++++++++ 4 files changed, 41 insertions(+) create mode 100644 scripts/spinner_helpers.sh create mode 100755 scripts/tmux_spinner.sh diff --git a/CHANGELOG.md b/CHANGELOG.md index a8edcb1..23cddf4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ### master - refactor checking if saved tmux session exists +- spinner while tmux sessions are restored ### v0.0.5, 2014-08-28 - restore pane processes diff --git a/scripts/session_restorer.sh b/scripts/session_restorer.sh index f9ccadc..65bf0cb 100755 --- a/scripts/session_restorer.sh +++ b/scripts/session_restorer.sh @@ -4,6 +4,7 @@ CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" source "$CURRENT_DIR/helpers.sh" source "$CURRENT_DIR/process_restore_helpers.sh" +source "$CURRENT_DIR/spinner_helpers.sh" is_line_type() { local line_type="$1" @@ -150,6 +151,7 @@ restore_active_and_alternate_sessions() { main() { if supported_tmux_version_ok && check_saved_session_exists; then + start_spinner restore_all_sessions restore_all_pane_processes restore_pane_layout_for_each_window >/dev/null 2>&1 @@ -157,6 +159,7 @@ main() { restore_active_pane_for_each_window restore_active_and_alternate_windows restore_active_and_alternate_sessions + stop_spinner display_message "Restored all Tmux sessions!" fi } diff --git a/scripts/spinner_helpers.sh b/scripts/spinner_helpers.sh new file mode 100644 index 0000000..e3a429e --- /dev/null +++ b/scripts/spinner_helpers.sh @@ -0,0 +1,8 @@ +start_spinner() { + $CURRENT_DIR/tmux_spinner.sh "Restoring sessions..." "Restored all Tmux sessions!" & + export SPINNER_PID=$! +} + +stop_spinner() { + kill $SPINNER_PID +} diff --git a/scripts/tmux_spinner.sh b/scripts/tmux_spinner.sh new file mode 100755 index 0000000..354c3bb --- /dev/null +++ b/scripts/tmux_spinner.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash + +# This script shows tmux spinner with a message. It is intended to be running +# as a background process which should be `kill`ed at the end. +# +# Example usage: +# +# ./tmux_spinner.sh "Working..." "End message!" & +# SPINNER_PID=$! +# .. +# .. execute commands here +# .. +# kill $SPINNER_PID # Stops spinner and displays 'End message!' + +MESSAGE="$1" +END_MESSAGE="$2" +SPIN='-\|/' + +trap "tmux display-message $END_MESSAGE; exit" SIGINT SIGTERM + +main() { + local i=0 + while true; do + i=$(( (i+1) %4 )) + tmux display-message " ${SPIN:$i:1} $MESSAGE" + sleep 0.1 + done +} +main