From b499ddacc0f008270092c1f4f85844b5c981dc2f Mon Sep 17 00:00:00 2001 From: Izzy Gomez Date: Thu, 14 Mar 2024 01:56:38 -0400 Subject: [PATCH 1/4] add `@resurrect-confirm-{save,restore}` options --- resurrect.tmux | 20 ++++++++++++++++++-- scripts/variables.sh | 6 ++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/resurrect.tmux b/resurrect.tmux index 21fed7e1..7689f8f1 100755 --- a/resurrect.tmux +++ b/resurrect.tmux @@ -6,18 +6,34 @@ source "$CURRENT_DIR/scripts/variables.sh" source "$CURRENT_DIR/scripts/helpers.sh" set_save_bindings() { + local should_confirm_save=$(get_tmux_option "$confirm_save_option" "$default_confirm_save") + local command + if [ "$should_confirm_save" == "on" ]; then + command="confirm-before -y -p \"$confirm_save_prompt\" \"run-shell \\\"$CURRENT_DIR/scripts/save.sh\\\"\"" + else + command="run-shell \"$CURRENT_DIR/scripts/save.sh\"" + fi + local key_bindings=$(get_tmux_option "$save_option" "$default_save_key") local key for key in $key_bindings; do - tmux bind-key "$key" run-shell "$CURRENT_DIR/scripts/save.sh" + tmux bind-key "$key" $command done } set_restore_bindings() { + local should_confirm_restore=$(get_tmux_option "$confirm_restore_option" "$default_confirm_restore") + local command + if [ "$should_confirm_restore" == "on" ]; then + command="confirm-before -y -p \"$confirm_restore_prompt\" \"run-shell \\\"$CURRENT_DIR/scripts/restore.sh\\\"\"" + else + command="run-shell \"$CURRENT_DIR/scripts/restore.sh\"" + fi + local key_bindings=$(get_tmux_option "$restore_option" "$default_restore_key") local key for key in $key_bindings; do - tmux bind-key "$key" run-shell "$CURRENT_DIR/scripts/restore.sh" + tmux bind-key "$key" $command done } diff --git a/scripts/variables.sh b/scripts/variables.sh index 9d42e02a..8734c533 100644 --- a/scripts/variables.sh +++ b/scripts/variables.sh @@ -2,10 +2,16 @@ default_save_key="C-s" save_option="@resurrect-save" save_path_option="@resurrect-save-script-path" +default_confirm_save="off" +confirm_save_option="@resurrect-confirm-save" +confirm_save_prompt="Save tmux environment? (Y/n)" default_restore_key="C-r" restore_option="@resurrect-restore" restore_path_option="@resurrect-restore-script-path" +default_confirm_restore="off" +confirm_restore_option="@resurrect-confirm-restore" +confirm_restore_prompt="Restore tmux environment? (Y/n)" # default processes that are restored default_proc_list_option="@resurrect-default-processes" From d0f77fceb25c23d562142e9d9c566c693594906a Mon Sep 17 00:00:00 2001 From: Izzy Gomez Date: Thu, 14 Mar 2024 02:01:55 -0400 Subject: [PATCH 2/4] confirm save/restore doc updates --- README.md | 1 + docs/confirm_actions.md | 6 ++++++ 2 files changed, 7 insertions(+) create mode 100644 docs/confirm_actions.md diff --git a/README.md b/README.md index f137ad8b..a5258fe7 100644 --- a/README.md +++ b/README.md @@ -90,6 +90,7 @@ You should now be able to use the plugin. **Configuration** - [Changing the default key bindings](docs/custom_key_bindings.md). +- [Adding a confirmation step on save & restore](docs/confirm_actions.md). - [Setting up hooks on save & restore](docs/hooks.md). - Only a conservative list of programs is restored by default:
`vi vim nvim emacs man less more tail top htop irssi weechat mutt`.
diff --git a/docs/confirm_actions.md b/docs/confirm_actions.md new file mode 100644 index 00000000..d7cf4419 --- /dev/null +++ b/docs/confirm_actions.md @@ -0,0 +1,6 @@ +# Confirm save & restore actions + +By default save & restore will have no confirmation when the key bindings are pressed. To change this, add to `.tmux.conf`: + + set -g @resurrect-save-confirm 'on' + set -g @resurrect-restore-confirm 'on' From 23045b74df1ef83aa359fc5d6a543b35db47d6b3 Mon Sep 17 00:00:00 2001 From: Izzy Gomez Date: Thu, 14 Mar 2024 14:00:25 -0400 Subject: [PATCH 3/4] confirm actions doc update --- docs/confirm_actions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/confirm_actions.md b/docs/confirm_actions.md index d7cf4419..79558d72 100644 --- a/docs/confirm_actions.md +++ b/docs/confirm_actions.md @@ -1,6 +1,6 @@ # Confirm save & restore actions -By default save & restore will have no confirmation when the key bindings are pressed. To change this, add to `.tmux.conf`: +By default save & restore will have no confirmation step when the key bindings are pressed. To change this, add to `.tmux.conf`: set -g @resurrect-save-confirm 'on' set -g @resurrect-restore-confirm 'on' From cbc6f8d909c71c606e81e9239ae8f082e2935885 Mon Sep 17 00:00:00 2001 From: Izzy Gomez Date: Thu, 14 Mar 2024 15:02:12 -0400 Subject: [PATCH 4/4] Fix whitespace issue when running `tmux bind-key`. The previous line `tmux bind-key "$key" $command` would experience issues if there was whitespace in `$command`. This fixes this. Also does small refactor to save `run-shell` commands into `run_{save,restore}_script` vars. Also makes sure keys are unbounded (run `unbind`) before binding (`bind-key`). --- resurrect.tmux | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/resurrect.tmux b/resurrect.tmux index 7689f8f1..4eb1f45d 100755 --- a/resurrect.tmux +++ b/resurrect.tmux @@ -7,33 +7,37 @@ source "$CURRENT_DIR/scripts/helpers.sh" set_save_bindings() { local should_confirm_save=$(get_tmux_option "$confirm_save_option" "$default_confirm_save") + local run_save_script="run-shell \"$CURRENT_DIR/scripts/save.sh\"" local command if [ "$should_confirm_save" == "on" ]; then - command="confirm-before -y -p \"$confirm_save_prompt\" \"run-shell \\\"$CURRENT_DIR/scripts/save.sh\\\"\"" + command="confirm-before -y -p \"$confirm_save_prompt\" \"$run_save_script\"" else - command="run-shell \"$CURRENT_DIR/scripts/save.sh\"" + command="$run_save_script" fi local key_bindings=$(get_tmux_option "$save_option" "$default_save_key") local key for key in $key_bindings; do - tmux bind-key "$key" $command + tmux unbind "$key" + tmux bind-key "$key" "$command" done } set_restore_bindings() { local should_confirm_restore=$(get_tmux_option "$confirm_restore_option" "$default_confirm_restore") + local run_restore_script="run-shell \"$CURRENT_DIR/scripts/restore.sh\"" local command if [ "$should_confirm_restore" == "on" ]; then - command="confirm-before -y -p \"$confirm_restore_prompt\" \"run-shell \\\"$CURRENT_DIR/scripts/restore.sh\\\"\"" + command="confirm-before -y -p \"$confirm_restore_prompt\" \"$run_restore_script\"" else - command="run-shell \"$CURRENT_DIR/scripts/restore.sh\"" + command="$run_restore_script" fi local key_bindings=$(get_tmux_option "$restore_option" "$default_restore_key") local key for key in $key_bindings; do - tmux bind-key "$key" $command + tmux unbind "$key" + tmux bind-key "$key" "$command" done }