Skip to content

Add per-session save files/session manager script#557

Open
philippossfrn wants to merge 1 commit intotmux-plugins:masterfrom
philippossfrn:feature/per-session-saves-with-manager
Open

Add per-session save files/session manager script#557
philippossfrn wants to merge 1 commit intotmux-plugins:masterfrom
philippossfrn:feature/per-session-saves-with-manager

Conversation

@philippossfrn
Copy link

  • Modified resurrect_file_path() to save sessions using session name
  • Prompts user to name session if using default numeric name
  • Added session manager script to $HOME/bin/ on install
    • Interactive menu to attach, delete, or rename saved sessions
  • Allows multiple distinct session saves instead of single global file

What the change does

This modification enhances tmux-resurrect to save session state on a per-session basis rather than using a single global save file. Additionally, it includes a session manager script that
provides an interactive menu for managing saved sessions.

Core changes:

  • Modifies resurrect_file_path() to use the tmux session name as the save filename (e.g., ~/.tmux/resurrect/dev-project.txt instead of last)
  • Prompts the user to name their session if it still has the default numeric name (e.g., 0, 1)
  • Installs a tmux-session-manager script to $HOME/bin/ that allows users to:
    • Attach to a previously saved session
    • Delete saved session files
    • Rename saved sessions

Why it's useful

  • Multiple project workflows: Keep separate save states for different projects without overwriting each other
  • Cleaner organization: Session saves are named meaningfully instead of using timestamps
  • Easy management: The session manager script provides a simple way to browse, clean up, or reorganize saved sessions without manually navigating the resurrect directory
  • Safer restores: Restoring one session won't accidentally load state from a completely different project

Breaking changes

  • Save file location changed: Existing saves in ~/.tmux/resurrect/last will not be automatically migrated. Users should manually restore their old session once, then save it under the new
    naming scheme.
  • Session naming prompt: Users with default-named sessions will now be prompted to provide a name on first save. This can be skipped by pre-naming sessions with tmux rename-session.

resurrect.tmux Outdated
local attach_script="$bin_dir/attach"

# Only create if attach script doesn't already exist
if [ -f "$attach_script" ]; then
Copy link

Choose a reason for hiding this comment

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

Wouldn't mix posix [] with bash's [[]]. If we're writing bash, let's stay in bash syntax.
This applies not only to this line, but throughout this patch.

Copy link
Author

Choose a reason for hiding this comment

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

Good point, fixed. Replaced all [ ] with [[ ]] for consistent bash syntax throughout the script.

resurrect.tmux Outdated

# List saved sessions
echo "Available saved tmux sessions:"
SAVED_SESSIONS=($(ls "$RESURRECT_DIR" | grep -vE 'last|readme'))
Copy link

Choose a reason for hiding this comment

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

ls is generally frowned upon in script usage. Best collect directory contents using find. That way there's also no need for the filtering grep, as find can provide that functionality.

Copy link
Author

Choose a reason for hiding this comment

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

Nice thought, done.

resurrect.tmux Outdated
cp "$RESURRECT_DIR/$SELECTED_SESSION" "$RESURRECT_DIR/last"

# Ensure the tmux server is running by creating a detached session
tmux new-session -d -s temp_session 2>/dev/null
Copy link

Choose a reason for hiding this comment

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

Maybe I'm paranoid, but would randomize the temp session name just in case. E.g. temp_session="temp-session-$RANDOM"

Copy link
Author

@philippossfrn philippossfrn Feb 2, 2026

Choose a reason for hiding this comment

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

Good catch, also added a timestamp suffix to avoid creating more than one session with the same name

@philippossfrn philippossfrn force-pushed the feature/per-session-saves-with-manager branch 2 times, most recently from ed75cff to 84cb3b9 Compare February 2, 2026 21:08
  - Modified resurrect_file_path() to save sessions using session name
  - Prompts user to name session if using default numeric name
  - Added session manager script to $HOME/bin/ on install
    - Interactive menu to attach, delete, or rename saved sessions
  - Allows multiple distinct session saves instead of single global file
  - Randomize temp session name with PID and $RANDOM to avoid collisions
  - Only kill temp session if we successfully created it
  - Use dynamic path for restore.sh based on plugin install location
  - Add Unix timestamp suffix to saved session filenames
  - Add custom keybinding example to README
  - Use find cmd to list saved sessions
@philippossfrn philippossfrn force-pushed the feature/per-session-saves-with-manager branch from 84cb3b9 to 11c2757 Compare February 2, 2026 21:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants