Spin a spinner while tmux sessions are restored

Closes #16
This commit is contained in:
Bruno Sutic 2014-08-28 12:58:07 +02:00
parent 655bdb9a75
commit 18f4d1099e
No known key found for this signature in database
GPG Key ID: 66D96E4F2F7EF26C
4 changed files with 41 additions and 0 deletions

View File

@ -2,6 +2,7 @@
### master ### master
- refactor checking if saved tmux session exists - refactor checking if saved tmux session exists
- spinner while tmux sessions are restored
### v0.0.5, 2014-08-28 ### v0.0.5, 2014-08-28
- restore pane processes - restore pane processes

View File

@ -4,6 +4,7 @@ CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$CURRENT_DIR/helpers.sh" source "$CURRENT_DIR/helpers.sh"
source "$CURRENT_DIR/process_restore_helpers.sh" source "$CURRENT_DIR/process_restore_helpers.sh"
source "$CURRENT_DIR/spinner_helpers.sh"
is_line_type() { is_line_type() {
local line_type="$1" local line_type="$1"
@ -150,6 +151,7 @@ restore_active_and_alternate_sessions() {
main() { main() {
if supported_tmux_version_ok && check_saved_session_exists; then if supported_tmux_version_ok && check_saved_session_exists; then
start_spinner
restore_all_sessions restore_all_sessions
restore_all_pane_processes restore_all_pane_processes
restore_pane_layout_for_each_window >/dev/null 2>&1 restore_pane_layout_for_each_window >/dev/null 2>&1
@ -157,6 +159,7 @@ main() {
restore_active_pane_for_each_window restore_active_pane_for_each_window
restore_active_and_alternate_windows restore_active_and_alternate_windows
restore_active_and_alternate_sessions restore_active_and_alternate_sessions
stop_spinner
display_message "Restored all Tmux sessions!" display_message "Restored all Tmux sessions!"
fi fi
} }

View File

@ -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
}

29
scripts/tmux_spinner.sh Executable file
View File

@ -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