Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add confirm option for save and restore. #502

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:<br/>
`vi vim nvim emacs man less more tail top htop irssi weechat mutt`.<br/>
Expand Down
6 changes: 6 additions & 0 deletions docs/confirm_actions.md
Original file line number Diff line number Diff line change
@@ -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'
Copy link

@shabaev shabaev Mar 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a typo - ressurect-confirm-...

24 changes: 22 additions & 2 deletions resurrect.tmux
Original file line number Diff line number Diff line change
Expand Up @@ -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\""
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jfyi - tmux 3.2a-4ubuntu0.2 - -y is unknown option

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
}

Expand Down
6 changes: 6 additions & 0 deletions scripts/variables.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down