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..79558d72
--- /dev/null
+++ b/docs/confirm_actions.md
@@ -0,0 +1,6 @@
+# Confirm save & restore actions
+
+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'
diff --git a/resurrect.tmux b/resurrect.tmux
index 21fed7e1..4eb1f45d 100755
--- a/resurrect.tmux
+++ b/resurrect.tmux
@@ -6,18 +6,38 @@ 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 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_save_script\""
+ else
+ 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" run-shell "$CURRENT_DIR/scripts/save.sh"
+ 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_restore_script\""
+ else
+ 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" run-shell "$CURRENT_DIR/scripts/restore.sh"
+ tmux unbind "$key"
+ 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"