### Inline Strategy Example with Arguments Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/process-strategies.md This example shows how to use the '*' wildcard in an inline strategy to preserve original arguments when restoring a process. ```tmux "~rails server->rails server *" ``` -------------------------------- ### Log Process Restoration Start Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/configuration.md Sets a shell command to be executed before processes are restored in panes, useful for logging or environment setup. ```tmux set -g @resurrect-hook-pre-restore-pane-processes 'echo "Starting processes..."' ``` -------------------------------- ### Window Line Example Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/file-format.md Examples of window lines, including session name, window index, name, active status, flags, layout string, and automatic rename setting. ```text window dev 0 :main 1 :* 6e80,120x30,0,0{60x30,0,0,0,60x30,60,0,1} 1 window dev 1 :sidebar 0 :- 5f68,120x30,0,0[120x15,0,0,0,120x14,0,16,1] : ``` -------------------------------- ### Install GDB on Ubuntu Source: https://github.com/tmux-plugins/tmux-resurrect/wiki/gdb-strategy-(deprecated) Use this command to install the gdb package on Ubuntu systems. This is a prerequisite for the gdb save command strategy. ```bash sudo apt-get install gdb ``` -------------------------------- ### Pane Line Example Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/file-format.md Examples of pane lines, showing session, window, pane indices, titles, directories, and commands. Note the escaped space in the full command. ```text pane dev 0 1 :* 0 bash :/home/user/work/project 1 bash :/bin/bash pane dev 0 1 :* 1 vim :/home/user/work/project 0 vim :/usr/bin/vim plugins/resurrect.vim pane dev 1 0 :- 0 server :/home/user/work/project 1 bundle :/usr/bin/ruby\ bundle\ server ``` -------------------------------- ### Install tpm (Tmux Plugin Manager) Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/integration-guide.md Clone the tpm repository to `~/.tmux/plugins/tpm` to install the Tmux Plugin Manager, which is required for managing other tmux plugins. ```bash # Install tpm git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm ``` -------------------------------- ### Combined Process Restoration Example Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/configuration.md A comprehensive example demonstrating the combination of different process restoration techniques, including exact matches, substring matching, custom restore commands, and argument preservation. ```tmux set -g @resurrect-processes 'ssh psql "~rails server->rails server *"' ``` -------------------------------- ### Tmux Resurrect Complete Configuration Example Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/configuration.md This snippet shows a comprehensive example of how to configure Tmux Resurrect. It covers key bindings, save directory, processes to restore, Vim/Neovim session handling, pane content capture, backup retention, and pre/post save/restore hooks. ```tmux set -g @resurrect-save 'S' set -g @resurrect-restore 'R' set -g @resurrect-dir '~/.tmux/resurrect' set -g @resurrect-processes 'ssh psql mysql sqlite3 "~rails server->rails server *"' set -g @resurrect-strategy-vim 'session' set -g @resurrect-strategy-nvim 'session' set -g @resurrect-capture-pane-contents 'on' set -g @resurrect-pane-contents-area 'full' set -g @resurrect-delete-backup-after '60' set -g @resurrect-hook-post-save-all 'notify-send "Tmux environment saved"' set -g @resurrect-hook-pre-restore-all 'notify-send "Starting tmux restore"' ``` -------------------------------- ### Save Process Example Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/README.md Illustrates the save phase for a vim process, showing how the PID is obtained and the command is written to a file with session and pane details. ```text User pane contains: $ vim /home/user/file.txt Save phase: 1. Get PID of vim process 2. Run save_command_strategy on PID → "/usr/bin/vim /home/user/file.txt" 3. Write to file: pane[TAB]session[TAB]0[TAB]1[TAB]:*[TAB]0[TAB]vim[TAB]:/home/user[TAB]1[TAB]vim[TAB]:/usr/bin/vim /home/user/file.txt Restore phase: 1. Read line: pane[TAB]session[TAB]0...:/usr/bin/vim /home/user/file.txt 2. Create pane with tmux split-window -c "/home/user" 3. Check if @resurrect-strategy-vim is set (it is: "session") 4. Load strategies/vim_session.sh 5. Call: vim_session.sh "/usr/bin/vim /home/user/file.txt" "/home/user" 6. Script checks if Session.vim exists in /home/user 7. If yes: Output "vim -S" 8. If no: Output "/usr/bin/vim /home/user/file.txt" 9. Send output + Enter to pane ``` -------------------------------- ### Install tmux-resurrect with TPM Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/integration-guide.md Add the tmux-resurrect plugin to your `.tmux.conf` using the Tmux Plugin Manager (TPM). After adding, press `prefix + I` to install. ```bash # Add to ~/.tmux.conf set -g @plugin 'tmux-plugins/tmux-resurrect' # Install plugins # Press: prefix + I (capital i) ``` -------------------------------- ### Verify TPM and Plugin Installation Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/integration-guide.md Check if the tmux plugin manager (TPM) and the tmux-resurrect plugin are installed correctly in the expected directories. ```bash # Verify TPM installed ls ~/.tmux/plugins/tpm # Verify plugin directory exists ls ~/.tmux/plugins/tmux-resurrect # Check .tmux.conf syntax tmux source-file ~/.tmux.conf # Should not error ``` -------------------------------- ### Vim Session Restoration Example Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/process-strategies.md This example shows how tmux-resurrect might restore a Vim session using a strategy file, depending on the presence of a Session.vim file. ```bash # Original command: /usr/bin/vim file.txt # Strategy file: strategies/vim_session.sh # Directory: /home/user/project # If Session.vim exists in /home/user/project: # Output: vim -S # Restored command: vim -S # If Session.vim does NOT exist: # Output: /usr/bin/vim file.txt # Restored command: /usr/bin/vim file.txt ``` -------------------------------- ### Restore Process with Arguments Example Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/README.md Demonstrates the restore phase for a process with arguments, showing how custom configurations and pattern matching are used to reconstruct and send commands to the pane. ```text Configuration: set -g @resurrect-processes '"~npm run->npm run *"' Saved command: /usr/local/bin/node /usr/local/lib/npm-cli.js run build --watch Restore phase: 1. Read process: /usr/local/bin/node /usr/local/lib/npm-cli.js run build --watch 2. Match against list: Check "~npm run" pattern 3. Found match: "npm run" is substring of saved command 4. Extract arguments: Everything after "npm run" = "build --watch" 5. Get restore template: "npm run *" 6. Replace *: "npm run build --watch" 7. Send to pane: npm run build --watch [Enter] ``` -------------------------------- ### Example of Substring Match Logic Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/process-strategies.md Demonstrates why substring matching is needed when the saved command is wrapped by an interpreter, like rbenv for Ruby. ```text Saved: /Users/john/.rbenv/versions/2.0.0/bin/ruby script/rails server Match with ~rails server: Found "rails server" in full command ✓ Match with rails server (no tilde): No match (doesn't start with "rails") ✗ ``` -------------------------------- ### Install Tmux Resurrect and Tmux Continuum Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/integration-guide.md Install both Tmux Resurrect and Tmux Continuum plugins using the Tmux Plugin Manager (TPM). Configure save intervals and auto-restore behavior for Continuum. ```tmux # Install both plugins set -g @plugin 'tmux-plugins/tmux-resurrect' set -g @plugin 'tmux-plugins/tmux-continuum' # Configure resurrect set -g @resurrect-processes 'ssh "~rails" "~npm"' # Configure continuum set -g @continuum-save-interval '15' # Save every 15 minutes set -g @continuum-restore 'on' # Auto-restore on tmux start run '~/.tmux/plugins/tpm/tpm' ``` -------------------------------- ### Install tmux-resurrect on NixOS Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/integration-guide.md Configure tmux-resurrect installation on NixOS using home-manager. This ensures the plugin is managed by your Nix configuration. ```nix programs.tmux.plugins = [ pkgs.tmuxPlugins.resurrect ]; ``` -------------------------------- ### Tmux Resurrect Pane Contents Example Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/file-format.md An example of the plain text content captured for a single tmux pane when pane contents are enabled. This includes shell commands and their output. ```shell $ ls -la total 24 drwxr-xr-x 5 user staff 160 Jul 6 14:30 . drwxr-xr-x 10 user staff 320 Jul 6 13:00 .. -rw-r--r-- 1 user staff 1234 Jul 6 14:25 file1.txt -rw-r--r-- 1 user staff 5678 Jul 6 14:30 file2.txt $ ``` -------------------------------- ### Inline Strategy Parsing Example Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/process-strategies.md Demonstrates how an inline strategy transforms an original saved command into a restored command, preserving arguments when the '*' wildcard is used. ```bash # Original saved command: # /Users/john/.rbenv/versions/2.0.0/bin/ruby script/rails server --port 3000 # Inline strategy match: ~rails server->rails server * # Result: rails server --port 3000 ``` -------------------------------- ### Install tmux-resurrect with Homebrew Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/integration-guide.md Install tmux-resurrect on macOS using Homebrew. The plugin will be installed in the default Homebrew location. ```bash brew install tmux-resurrect # Location: /usr/local/opt/tmux-resurrect ``` -------------------------------- ### Corrected Default Command Configuration Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/docs/restoring_pane_contents.md This is an example of a corrected `default-command` configuration that avoids problematic operators like `&&` and `||`. ```tmux set -g default-command "reattach-to-user-namespace -l $SHELL" ``` -------------------------------- ### Manual Installation of Tmux Resurrect Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/README.md Clone the repository to a local path and add the resurrect.tmux script to your .tmux.conf. Reload your tmux environment by sourcing the configuration file. ```bash $ git clone https://github.com/tmux-plugins/tmux-resurrect ~/clone/path ``` ```tmux run-shell ~/clone/path/resurrect.tmux ``` ```bash $ tmux source-file ~/.tmux.conf ``` -------------------------------- ### Minimal tmux-resurrect configuration Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/integration-guide.md A basic `.tmux.conf` setup for tmux-resurrect, including adding the plugin and defining optional key bindings for saving and restoring sessions. TPM is initialized at the end. ```tmux # Add resurrect plugin set -g @plugin 'tmux-plugins/tmux-resurrect' # Key bindings (optional, these are defaults) set -g @resurrect-save 'S' set -g @resurrect-restore 'R' # Initialize plugin manager run '~/.tmux/plugins/tpm/tpm' ``` -------------------------------- ### Recommended tmux-resurrect configuration Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/integration-guide.md A comprehensive `.tmux.conf` setup for tmux-resurrect. Includes defaults, custom save directory, process restoration rules, Vim/Neovim session strategies, and integration with tmux-continuum for automatic saving and restoring. ```tmux # Resurrection with reasonable defaults set -g @plugin 'tmux-plugins/tmux-resurrect' # Save location set -g @resurrect-dir '~/.config/tmux/resurrect' # Process restoration set -g @resurrect-processes 'ssh psql "~npm run" "~yarn"' # Vim/Neovim session restoration set -g @resurrect-strategy-vim 'session' set -g @resurrect-strategy-nvim 'session' # Pane contents (optional, uses disk space) # set @resurrect-capture-pane-contents 'on' # Combine with tmux-continuum for auto-save/restore set -g @plugin 'tmux-plugins/tmux-continuum' set -g @continuum-restore 'on' run '~/.tmux/plugins/tpm/tpm' ``` -------------------------------- ### Exact Process Match Configuration Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/process-strategies.md Use this to match saved commands that exactly equal the process name or start with the process name followed by a space. This is the default behavior. ```tmux set -g @resurrect-processes 'ssh psql mysql' ``` -------------------------------- ### Install Tmux Resurrect Manually Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/README.md Clone the repository to the plugins directory and add the run-shell command to your tmux.conf. This method requires manual cloning and configuration. ```bash # Via manual clone git clone https://github.com/tmux-plugins/tmux-resurrect ~/.tmux/plugins/tmux-resurrect # Add to ~/.tmux.conf: run-shell ~/.tmux/plugins/tmux-resurrect/resurrect.tmux ``` -------------------------------- ### Verify Tmux Resurrect Installation Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/README.md Check if the Tmux Resurrect plugin is loaded by inspecting global options and verify its key bindings are registered. ```bash # Check plugin is loaded tmux show-options -g | grep resurrect # Check key bindings tmux list-keys | grep resurrect ``` -------------------------------- ### Integrate Window Manager for X11 Geometry Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/integration-guide.md Save and restore window positions and sizes using `xdotool` and `wmctrl`. Ensure these tools are installed and configured. ```tmux # Save window position and size set -g @resurrect-hook-post-save-all \ 'eval $(xdotool getwindowgeometry --shell $WINDOWID); \ echo "$X,$Y,$WIDTH,$HEIGHT" > ~/.tmux/resurrect/geometry' # Restore window geometry set -g @resurrect-hook-pre-restore-all \ 'IFS=, read -r X Y W H < ~/.tmux/resurrect/geometry 2>/dev/null; \ wmctrl -i -r $WINDOWID -e "0,$X,$Y,$W,$H"' ``` -------------------------------- ### Configure process restoration with nvm and gulp Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/docs/restoring_programs.md This example shows how to configure tmux-resurrect to restore processes that involve nvm version management and gulp execution, ensuring the correct environment is set up. ```shell set -g @resurrect-processes '"~yarn gulp test->nvm use && gulp test"' ``` -------------------------------- ### supported_tmux_version_ok Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/api-reference.md Checks if the installed tmux version meets the minimum requirement of 1.9. ```APIDOC ## Function: `supported_tmux_version_ok()` ### Description Checks if the installed tmux version meets the minimum requirement (1.9). ### Parameters None ### Returns 0 (success) if version ≥ 1.9; 1 (failure) otherwise. ``` -------------------------------- ### Install Tmux Resurrect with TPM Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/README.md Add the tmux-resurrect plugin to your TPM plugins list in .tmux.conf. After adding, fetch and source the plugin using 'prefix + I'. ```tmux set -g @plugin 'tmux-plugins/tmux-resurrect' ``` -------------------------------- ### Modify Restore Behavior with Pre-Restore Hook Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/integration-guide.md Configure the `resurrect-hook-pre-restore-all` hook in `.tmux.conf` to run commands before restoring sessions. This example sources a script to prepare the environment. ```tmux # Pre-restore: prepare environment set -g @resurrect-hook-pre-restore-all \ 'source ~/.tmux/restore-env.sh' ``` -------------------------------- ### Check tmux Version Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/00-START-HERE.txt Displays the installed version of tmux. Important for ensuring compatibility with tmux-resurrect. ```shell tmux -V ``` -------------------------------- ### Check Supported Tmux Version Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/api-reference.md Verifies if the installed tmux version meets the minimum requirement of 1.9. Returns 0 for success (version OK) and 1 for failure. ```bash supported_tmux_version_ok() ``` -------------------------------- ### Runtime Strategy Selection Logic Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/process-strategies.md This script demonstrates how the plugin selects a save command strategy at runtime, falling back to 'ps.sh' if the chosen strategy file does not exist. ```bash save_command_strategy=$(get_tmux_option "$save_command_strategy_option" "$default_save_command_strategy") strategy_file="$CURRENT_DIR/../save_command_strategies/${save_command_strategy}.sh" if [ -e "$strategy_file" ]; then $strategy_file "$pane_pid" # Output: full command else default_strategy_file="$CURRENT_DIR/../save_command_strategies/ps.sh" $default_strategy_file "$pane_pid" fi ``` -------------------------------- ### Auto-Restore Tmux on Shell Start Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/integration-guide.md Add this snippet to your .bashrc or .zshrc to automatically restore the tmux session when you start a new shell within tmux. It ensures restoration only happens once. ```bash # Only in tmux, restore on first pane if [ -n "$TMUX" ] && [ -z "$TMUX_RESTORE_DONE" ]; then export TMUX_RESTORE_DONE=1 # Optional: auto-restore via tmux command # tmux send-keys -t "$TMUX_PANE" "C-r" # Uncomment to auto-restore fi ``` -------------------------------- ### Testing a Restore Strategy Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/process-strategies.md Shows how to test a custom restore strategy script. You provide the saved command and directory, and the script outputs the restoration command. ```bash # Test with actual command and directory: ./strategies/vim_session.sh \ "/usr/bin/vim file.txt" \ "/home/user/project" # Output: vim -S (if Session.vim exists) ``` -------------------------------- ### Testing a Save Strategy Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/process-strategies.md Demonstrates how to test a custom save strategy script. You provide a process ID and execute the script to verify its output. ```bash # Get a process ID (e.g., from tmux display-message -p "#{pane_pid}") pid=12345 # Test strategy: ./save_command_strategies/my_strategy.sh $pid # Output: /usr/bin/vim /home/user/file.txt ``` -------------------------------- ### Save Pipeline Overview Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/README.md Details the steps involved when saving a tmux session, from user input to writing the backup file. Includes information on backup rotation and hooks. ```text User: prefix + Ctrl-s ↓ scripts/save.sh ├─ Dump grouped sessions ├─ Dump panes (with full command via save_command_strategy) ├─ Dump windows (with layout) ├─ Dump state (active/alternate sessions) ├─ Execute hook: post-save-layout ├─ Optionally: Capture pane contents ├─ Remove old backups (>30 days, keep ≥5) ├─ Execute hook: post-save-all └─ Write: {resurrect_dir}/tmux_resurrect_YYYYMMDDTHHMMSS.txt Symlink: {resurrect_dir}/last ``` -------------------------------- ### Get Tmux-Resurrect Directory Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/api-reference.md Returns the directory path where tmux-resurrect saves its state files. This path can be customized via a tmux option. ```bash resurrect_dir() ``` -------------------------------- ### Calling a Custom Strategy File Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/process-strategies.md This bash snippet illustrates how to execute a custom strategy file, passing the original command and directory as arguments, and using its output as the restore command. ```bash # Strategy file receives original command and directory as args output=$($strategy_file "$pane_full_command" "$dir") # Use $output as the restore command ``` -------------------------------- ### Get Last Resurrect File Path Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/api-reference.md Returns the path to the symlink that points to the most recent state file. This is a simple utility function with no parameters. ```bash last_resurrect_file() ``` -------------------------------- ### View Configuration Options Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/00-START-HERE.txt Displays all global tmux options related to tmux-resurrect, filtering for lines containing 'resurrect'. Useful for checking current settings. ```shell tmux show-options -g | grep resurrect ``` -------------------------------- ### Constructing Custom Strategy File Path Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/process-strategies.md This bash snippet shows how to retrieve the configured strategy for a command and construct the expected path for a custom strategy file. ```bash # Get configured strategy for command strategy=$(tmux show-option -gqv "@resurrect-strategy-vim") # Construct path: strategies/vim_session.sh strategy_file="strategies/vim_${strategy}.sh" ``` -------------------------------- ### Tmux Configuration for Custom Strategies Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/process-strategies.md Illustrates how to enable custom save and restore strategies within the Tmux configuration file (.tmux.conf). ```tmux # Save strategy set -g @resurrect-save-command-strategy 'my_strategy' # Restore strategy set -g @resurrect-strategy-vim 'my_session' set -g @resurrect-strategy-ruby 'custom_restore' ``` -------------------------------- ### Argument Preservation Logic Example Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/process-strategies.md Illustrates how tmux-resurrect extracts arguments from the saved command and appends them to the restored command when the '*' placeholder is used in the inline strategy. ```bash # Given: # Full command: /path/to/ruby script/rails server --port 3000 # Match: "rails server" # Inline strategy: "rails server *" # Extract arguments after match: # Arguments = "--port 3000" # Replace * in strategy: # Result = "rails server --port 3000" ``` -------------------------------- ### Invalid Save Directory Configuration Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/docs/save_dir.md This example demonstrates an invalid configuration for the save directory. Environment variables and shell interpolation are not allowed in the @resurrect-dir option. ```tmux set -g @resurrect-dir '/path/$MY_VAR/$(some_executable)' ``` -------------------------------- ### Configure Additional Programs to Restore Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/docs/restoring_programs.md Use the @resurrect-processes option to specify space-separated programs to restore. Programs with arguments should be double-quoted. ```tmux set -g @resurrect-processes 'ssh psql mysql sqlite3' ``` ```tmux set -g @resurrect-processes 'some_program "git log"' ``` -------------------------------- ### Verify Process Restoration Settings Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/integration-guide.md Ensure that processes are configured for saving and check the saved file for the presence of process commands. This helps diagnose why only panes/windows restore, not the processes within them. ```bash # Verify processes are configured tmux show-options -g @resurrect-processes # Check saved file has commands grep '^pane' ~/.tmux/resurrect/last | cut -f11 | head # Test process matching # See docs/process-strategies.md for debugging ``` -------------------------------- ### Configure Program Restoration (Tilde for Flexible Matching) Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/docs/restoring_programs.md The tilde ('~') character allows for flexible matching of process names. It enables restoration if the specified string is found anywhere within the full process name. ```tmux set -g @resurrect-processes '"~rails server"' # OK ``` -------------------------------- ### Configure Processes to Restore Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/process-strategies.md Set the `@resurrect-processes` option to control which processes are restored. Use an empty string for default processes, a space-separated list for additional processes, 'false' to disable, or ':all:' to restore all processes. ```tmux set -g @resurrect-processes '' set -g @resurrect-processes 'ssh psql mysql sqlite3' set -g @resurrect-processes 'false' set -g @resurrect-processes ':all:' ``` -------------------------------- ### List All Restored Commands Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/file-format.md Filters the save file to show only lines starting with 'pane' and extracts the command being restored. This is useful for checking which commands tmux-resurrect will execute. ```bash grep '^pane' ~/.tmux/resurrect/last | cut -f11 ``` -------------------------------- ### Set Default Restoration Strategies Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/api-reference.md Initializes default restoration strategies for programs with known issues, such as irb and mosh-client. ```bash set_default_strategies() ``` -------------------------------- ### Pane Line Format Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/file-format.md Represents a tmux pane with its state and running process. Spaces in paths are escaped as \\ . Colons at column start are literal prefixes. ```text pane SESSION WINDOW WINDOW_ACTIVE WINDOW_FLAGS PANE_INDEX PANE_TITLE :DIR PANE_ACTIVE PANE_COMMAND :FULL_COMMAND ``` -------------------------------- ### Save Window Geometry with xdotool Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/docs/hooks.md This hook is called after all tmux state has been saved. It uses xdotool to get the window geometry and saves it to a file for later restoration. ```bash set -g @resurrect-hook-post-save-all 'eval $(xdotool getwindowgeometry --shell $WINDOWID); echo 0,$X,$Y,$WIDTH,$HEIGHT > $HOME/.tmux/resurrect/geometry' ``` -------------------------------- ### Check Hook Execution and Configuration Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/integration-guide.md Verify that custom hooks are set correctly and test their direct execution. Pay attention to quoting issues, preferring single quotes for commands. ```bash # Verify hook is set tmux show-options -g @resurrect-hook-post-save-all # Test hook directly eval "$(tmux show-options -gv @resurrect-hook-post-save-all)" # Check for quoting issues (use single quotes usually) set -g @resurrect-hook-post-save-all 'your command here' # Good set -g @resurrect-hook-post-save-all "your command here" # May have issues ``` -------------------------------- ### Configure Post-Save and Pre-Restore Notifications in Tmux Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/INDEX.md Set up notifications for save and restore events by configuring the @resurrect-hook-post-save-all and @resurrect-hook-pre-restore-all options in your .tmux.conf. Ensure notify-send is installed on your system. ```tmux set -g @resurrect-hook-post-save-all 'notify-send "Tmux saved"' ``` ```tmux set -g @resurrect-hook-pre-restore-all 'notify-send "Restoring..."' ``` -------------------------------- ### Pre-Restore Cleanup: Kill Vim Processes Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/integration-guide.md Execute commands before restoring to clean up specific processes, such as killing Vim instances to avoid swap file issues. Use the safer `killall` for current user only. ```tmux # Kill vim instances before restore (prevents "swap file" warnings) set -g @resurrect-hook-pre-restore-all 'pkill -f "^vim"' # Or more safely, for current user only: set -g @resurrect-hook-pre-restore-all 'killall -u $(whoami) vim 2>/dev/null || true' ``` -------------------------------- ### Get Tmux-Resurrect State File Path Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/api-reference.md Constructs and returns the full path to the current tmux-resurrect state file, including a timestamp. The path is based on the `resurrect_dir` function. ```bash resurrect_file_path() ``` -------------------------------- ### Tmux Resurrect Configuration Options Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/README.md Lists the various configuration options available in .tmux.conf for customizing Tmux Resurrect's behavior. These options control saving, restoring, and specific strategies. ```text .tmux.conf ├─ @resurrect-save (key binding) ├─ @resurrect-restore (key binding) ├─ @resurrect-dir (save location) ├─ @resurrect-processes (process list) ├─ @resurrect-strategy-* (per-command strategy) ├─ @resurrect-capture-pane-contents (on/off) ├─ @resurrect-pane-contents-area (full/visible) ├─ @resurrect-save-command-strategy (ps/pgrep/linux_procfs/gdb) ├─ @resurrect-delete-backup-after (days) ├─ @resurrect-hook-* (custom commands) └─ @resurrect-never-overwrite (flag) ↓ scripts/variables.sh (defines defaults) ↓ get_tmux_option() in scripts/helpers.sh ↓ Used by save.sh and restore.sh ``` -------------------------------- ### Get Tmux Option with Default Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/api-reference.md Retrieves a tmux global option value. If the option is not set, it returns a specified default value. Useful for configuring plugin behavior. ```bash get_tmux_option() { local option="$1" local default_value="$2" local option_value=$(tmux show-option -gqv "$option") if [ -z "$option_value" ]; then echo "$default_value" else echo "$option_value" fi } ``` -------------------------------- ### dump_windows() Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/api-reference.md Dumps all windows with their layout and properties into a tab-delimited format. ```APIDOC ## dump_windows() ### Description Dumps all windows with their layout and properties. ### Method Shell Function ### Parameters None ### Returns Tab-delimited output with fields: - `window` (line type) - session_name - window_index - `:window_name` (with leading `:`) - window_active (0 or 1) - `:window_flags` (with leading `:`) - window_layout (tmux layout string) - automatic_rename (0/1 or `:` if unset) ### Note Excludes windows from grouped sessions. ``` -------------------------------- ### Dump All Windows Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/api-reference.md Dumps all windows with their layout and properties. Excludes windows from grouped sessions. Returns tab-delimited output. ```bash dump_windows() ``` -------------------------------- ### Enable Auto-Save/Restore with Tmux Continuum Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/INDEX.md To enable automatic saving and restoring of tmux sessions on computer startup, install the tmux-continuum plugin and set the @continuum-restore option to 'on' in your .tmux.conf. ```tmux set -g @continuum-restore 'on' ``` -------------------------------- ### Modify Save Behavior with Post-Save Hook Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/integration-guide.md Use the `resurrect-hook-post-save-all` hook in `.tmux.conf` to execute commands after all sessions are saved. This example backs up the last saved state and commits it to Git. ```tmux # Post-save: do something with the file set -g @resurrect-hook-post-save-all \ 'cp ~/.tmux/resurrect/last ~/.tmux/resurrect/latest && \ git -C ~/.tmux add resurrect/latest && \ git -C ~/.tmux commit -m "Auto backup"' ``` -------------------------------- ### Basic Process List Restoration Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/configuration.md Configure a space-separated list of programs to restore. These processes will be restored if they were running in a pane. ```tmux set -g @resurrect-processes 'ssh psql' ``` -------------------------------- ### Get Pane Contents File Path Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/api-reference.md Generates the full file path for a single pane's captured contents. Requires parameters for save/restore context and the pane identifier. ```bash pane_contents_file() { local save_or_restore="$1" local pane_id="$2" echo "$(pane_contents_dir "$save_or_restore")/pane-${pane_id}" } ``` -------------------------------- ### Restore Pipeline Overview Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/README.md Details the steps involved when restoring a tmux session, from user input to displaying a completion message. Covers pane restoration, process restoration, and hooks. ```text User: prefix + Ctrl-r ↓ scripts/restore.sh ├─ Check saved file exists ├─ Execute hook: pre-restore-all ├─ Detect if restoring from scratch (1 pane only) ├─ Restore panes: │ ├─ For each pane, create session/window/pane as needed │ ├─ Restore pane title │ └─ Register existing panes (skip process restore for them) ├─ Handle session 0 cleanup (restore-from-scratch only) ├─ Restore window properties (layout, name, automatic-rename) ├─ Execute hook: pre-restore-pane-processes ├─ Restore pane processes: │ ├─ For each pane with full_command │ ├─ Check process should be restored (whitelist) │ ├─ Resolve strategy (inline → file → raw) │ └─ Send command to pane ├─ Restore active panes, zoomed windows ├─ Restore grouped sessions ├─ Restore alternate windows/sessions ├─ Cleanup pane contents ├─ Execute hook: post-restore-all └─ Display "Tmux restore complete!" message ``` -------------------------------- ### Get Pane Contents Directory Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/api-reference.md Constructs and returns the directory path for storing pane content captures. It takes one parameter to specify whether it's for saving or restoring. ```bash pane_contents_dir() { echo "$(resurrect_dir)/$1/pane_contents/" } ``` -------------------------------- ### set_default_strategies() Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/api-reference.md Initializes default process restoration strategies. Sets default restoration strategies for specific programs (`irb`, `mosh-client`) that have known issues with default restoration. ```APIDOC ## Function: set_default_strategies() ### Description Initializes default process restoration strategies. Sets default restoration strategies for specific programs (`irb`, `mosh-client`) that have known issues with default restoration. ### Method Shell Function ### Parameters None ### Source `resurrect.tmux:24–27` ``` -------------------------------- ### Configure npm process restoration with yarn Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/docs/restoring_programs.md This snippet shows the correct way to configure npm process restoration using yarn as a workaround for potential issues with direct npm commands. ```shell set -g @resurrect-processes '"~yarn watch"' ``` -------------------------------- ### Integrate tmux-copycat for Enhanced Search Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/integration-guide.md Add `tmux-copycat` as a plugin in `.tmux.conf` to enhance search capabilities within panes, complementing tmux-resurrect's restore functionality. ```tmux set -g @plugin 'tmux-plugins/tmux-copycat' ``` -------------------------------- ### Integrate tmux-continuum for Automatic Saving Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/integration-guide.md Add `tmux-continuum` as a plugin in `.tmux.conf` to enable automatic saving and restoring. Set `@continuum-restore` to 'on' to activate automatic restoration. ```tmux set -g @plugin 'tmux-plugins/tmux-continuum' set -g @continuum-restore 'on' ``` -------------------------------- ### Restore All Programs (Use with Caution) Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/docs/restoring_programs.md Setting @resurrect-processes to ':all:' attempts to restore all programs. This is generally discouraged due to potential data loss risks if a dangerous command is restored. ```tmux set -g @resurrect-processes ':all:' ``` -------------------------------- ### Configure Program Restoration (Basic) Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/docs/restoring_programs.md Use this to specify programs that `tmux-resurrect` should attempt to save and restore. Without special characters, the process name must strictly match. ```tmux set -g @resurrect-processes '"rails server"' # will NOT work ``` -------------------------------- ### Navigate to Save Directory Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/docs/restoring_previously_saved_environment.md Change directory to the tmux-resurrect save location. ```bash cd ~/.tmux/resurrect/ ``` -------------------------------- ### Define Inline Strategies for Process Restoration Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/process-strategies.md Use inline strategies in the `@resurrect-processes` option to map saved commands to specific restore commands. Use '~MATCH' for substring matching and 'MATCH' for exact matching. Append '*' to preserve original arguments. ```tmux set -g @resurrect-processes 'ssh "~rails server->rails server" "~npm run->npm run *"' ``` -------------------------------- ### Link Save File Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/docs/restoring_previously_saved_environment.md Create a symbolic link from the desired save file to 'last'. This prepares the file for restoration. ```bash ln -sf last ``` -------------------------------- ### Specify Custom Restore Command Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/docs/restoring_programs.md Use '->' to define a specific command for restoring a program, which is helpful if the default restore command is insufficient or fails. ```tmux set -g @resurrect-processes 'some_program "grunt->grunt development"' ``` -------------------------------- ### View tmux-resurrect Strategy Options Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/process-strategies.md This command displays all available resurrection strategy options configured in your tmux settings. It's useful for understanding which strategies are active and how they are set. ```bash # See all resurrection strategy options tmux show-options -g | grep resurrect-strategy ``` -------------------------------- ### Substring Matching for Process Restoration Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/configuration.md Use a tilde (~) prefix for substring matching to restore processes containing a specific string in their command line. This is useful when exact command names might vary due to interpreters or shebangs. ```tmux set -g @resurrect-processes '"~rails server"' ``` -------------------------------- ### Custom Restore Strategy Script Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/README.md Implement a custom restore strategy script to define how to restore a program based on its original command and directory. Associate this script with a specific program using the 'set -g @resurrect-strategy-' option. ```bash #!/bin/bash ORIGINAL_COMMAND="$1" DIRECTORY="$2" # Output command to restore ``` -------------------------------- ### Use notify-send for Persistent Notifications (Linux) Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/integration-guide.md Integrate with `notify-send` to show desktop notifications on save and restore events. Adjust urgency as needed. ```tmux set -g @resurrect-hook-post-save-all 'notify-send --urgency=low "Tmux" "Environment saved"' set -g @resurrect-hook-pre-restore-all 'notify-send --urgency=normal "Tmux" "Starting restore..."' ``` -------------------------------- ### Configure tmux-resurrect for Neovim Session Strategy Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/docs/restoring_vim_and_neovim_sessions.md Add this to your .tmux.conf to enable session saving for Neovim. ```tmux set -g @resurrect-strategy-nvim 'session' ``` -------------------------------- ### List Available Tmux Resurrect Strategies Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/INDEX.md Lists the available strategy scripts for customizing program restoration. These scripts are located in the specified directories. ```bash ls -1 ~/.tmux/resurrect/strategies/ ``` ```bash ls -1 ~/.tmux/resurrect/save_command_strategies/ ``` -------------------------------- ### Automatic Tmux Save Before Reboot (Linux) Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/integration-guide.md Configure sudoers to allow passwordless systemctl commands and create a script to signal tmux for saving before suspending or powering off. ```bash username ALL = NOPASSWD: /usr/bin/systemctl suspend, \ /usr/bin/systemctl hibernate, \ /usr/bin/systemctl poweroff ``` ```bash #!/bin/bash # Save tmux before sleep pkill -SIGUSR1 -u $USER tmux # Signal may trigger save if configured # Now suspend systemctl suspend ``` -------------------------------- ### File Details Summary Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/MANIFEST.md Provides a summary of each file included in the documentation set, detailing its size, line count, and primary purpose. This table offers a quick overview of the documentation's scope. ```markdown | File | Size | Lines | Purpose | |------|------|-------|---------| | **INDEX.md** | 11 KB | 280 | Quick navigation and fast lookup | | **README.md** | 16 KB | 620 | Architecture, quick start, overview | | **api-reference.md** | 23 KB | 780 | All exported functions with signatures | | **configuration.md** | 14 KB | 540 | Complete configuration reference | | **file-format.md** | 11 KB | 420 | Save file format specification | | **process-strategies.md** | 16 KB | 680 | Process restoration system details | | **integration-guide.md** | 14 KB | 540 | Installation, hooks, integration | **Totals:** 7 files, 112 KB, 3,783 lines ``` -------------------------------- ### save_all() Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/api-reference.md Main entry point that saves all tmux session state including panes, windows, grouped sessions, and state to a timestamped file. It also handles directory creation, post-save hooks, symlink updates, pane content capture, and cleanup of old backups. ```APIDOC ## save_all() ### Description Main entry point that saves all tmux session state (panes, windows, grouped sessions, state). ### Method Shell Function ### Parameters None ### Behavior 1. Creates resurrect directory if needed 2. Dumps grouped sessions, panes, windows, and state to timestamped file 3. Executes `post-save-layout` hook 4. Updates `last` symlink if state differs from previous save 5. Captures pane contents if enabled 6. Removes backups older than configured threshold (default 30 days) 7. Executes `post-save-all` hook ### Output Creates/updates files: - `{resurrect_dir}/tmux_resurrect_YYYYMMDDTHHMMSS.txt` - `{resurrect_dir}/last` (symlink) - `{resurrect_dir}/pane_contents.tar.gz` (if enabled) ``` -------------------------------- ### Configure gulp process restoration with yarn Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/docs/restoring_programs.md This configuration demonstrates how to restore gulp processes by prefixing the command with 'yarn', which helps tmux-resurrect manage the process correctly. ```shell set -g @resurrect-processes '"~yarn gulp test"' ``` -------------------------------- ### Verify tmux-resurrect Save File Creation Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/integration-guide.md Watch the `~/.tmux/resurrect/last` file for changes using `watch` or bind a tmux key to list its details. ```bash # Watch for new save files watch -n 1 'ls -lh ~/.tmux/resurrect/last' ``` ```tmux # Or in tmux with repeat: tmux bind -n M-r run-shell 'ls -lh ~/.tmux/resurrect/last' ``` -------------------------------- ### Configure Mosh Client Strategy and Processes Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/process-strategies.md Configure tmux-resurrect to recognize and use the 'default_strategy' for 'mosh-client' processes. ```tmux set -g @resurrect-processes 'mosh-client' set -g @resurrect-strategy-mosh-client 'default_strategy' ``` -------------------------------- ### Retrieve Full Pane Command Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/api-reference.md Retrieves the full command line running in a pane using a configurable strategy file. Requires the pane's process ID. ```bash pane_full_command() { local pane_pid="$1" local strategy_file="$(_save_command_strategy_file)" $strategy_file "$pane_pid" } ``` -------------------------------- ### pane_full_command(pane_pid) Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/api-reference.md Retrieves the full command line running in a specific tmux pane using a strategy-based approach. ```APIDOC ## pane_full_command(pane_pid) ### Description Retrieves the full command line running in a pane using a strategy. ### Method Shell Function ### Parameters #### Path Parameters - **pane_pid** (integer) - Required - Process ID of the pane ### Returns Full command string as it appears in the process table. ### Strategy Files `save_command_strategies/{ps,pgrep,linux_procfs,gdb}.sh` ``` -------------------------------- ### Enable Pane Content Capture Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/docs/restoring_pane_contents.md Add this line to your `.tmux.conf` to enable saving and restoring pane contents. ```tmux set -g @resurrect-capture-pane-contents 'on' ``` -------------------------------- ### Import Tmux Session from Backup Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/_autodocs/integration-guide.md Restore a Tmux session from a backup file. This script copies the specified backup file to the 'last' file and then triggers the restore key binding. ```bash #!/bin/bash # Restore from backup file backup_file="$1" cp "$backup_file" ~/.tmux/resurrect/last # Trigger restore tmux send-keys -t session "C-r" # Or custom restore key ``` -------------------------------- ### Configure tmux-resurrect for Vim Session Strategy Source: https://github.com/tmux-plugins/tmux-resurrect/blob/master/docs/restoring_vim_and_neovim_sessions.md Add this to your .tmux.conf to enable session saving for Vim. ```tmux set -g @resurrect-strategy-vim 'session' ```