From 7f50660918052ba5ec0c99536c0f117389b28dac Mon Sep 17 00:00:00 2001 From: Bruno Sutic Date: Wed, 27 Aug 2014 13:12:32 +0200 Subject: [PATCH] User option for disabling pane process restoring --- CHANGELOG.md | 1 + scripts/helpers.sh | 5 ++++- scripts/session_restorer.sh | 33 ++++++++++++++++++++++++++------- 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cfdf711..57c050a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ### master - restore pane processes +- user option for disabling pane process restoring ### v0.0.4, 2014-08-26 - restore pane layout for each window diff --git a/scripts/helpers.sh b/scripts/helpers.sh index e546b3b..538b216 100644 --- a/scripts/helpers.sh +++ b/scripts/helpers.sh @@ -1,6 +1,9 @@ # configurable constants default_sessions_dir="$HOME/.tmux/sessions" -sessions_dir_option="@sessions-dir" +sessions_dir_option="@session-saver-dir" + +restore_processes_option="@session-saver-restore-processes" +default_restore_processes="true" SUPPORTED_VERSION="1.9" diff --git a/scripts/session_restorer.sh b/scripts/session_restorer.sh index df5a615..9a47586 100755 --- a/scripts/session_restorer.sh +++ b/scripts/session_restorer.sh @@ -105,14 +105,33 @@ restore_all_sessions() { done < $(last_session_path) } +restore_pane_processes_enabled() { + local restore_processes="$(get_tmux_option "$restore_processes_option" "$default_restore_processes")" + if [ $restore_processes == "false" ]; then + return 1 + else + return 0 + fi +} + +restore_pane_process() { + local pane_full_command="$1" + local session_name="$2" + local window_number="$3" + local pane_index="$4" + tmux switch-client -t "${session_name}:${window_number}" + tmux send-keys -t "$pane_index" "$pane_full_command" "C-m" +} + restore_all_pane_processes() { - local pane_full_command - awk 'BEGIN { FS="\t"; OFS="\t" } /^pane/ && $11 !~ "^:$" { print $2, $3, $7, $11; }' $(last_session_path) | - while IFS=$'\t' read session_name window_number pane_index pane_full_command; do - pane_full_command="$(remove_first_char "$pane_full_command")" - tmux switch-client -t "${session_name}:${window_number}" - tmux send-keys -t "$pane_index" "$pane_full_command" "C-m" - done + if restore_pane_processes_enabled; then + local pane_full_command + awk 'BEGIN { FS="\t"; OFS="\t" } /^pane/ && $11 !~ "^:$" { print $2, $3, $7, $11; }' $(last_session_path) | + while IFS=$'\t' read session_name window_number pane_index pane_full_command; do + pane_full_command="$(remove_first_char "$pane_full_command")" + restore_pane_process "$pane_full_command" "$session_name" "$window_number" "$pane_index" + done + fi } restore_pane_layout_for_each_window() {