Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
d0f6f6ca30 | |||
34a1b4647d | |||
a68a786a73 | |||
19c981545e | |||
571bcb8173 | |||
2b259cf11a | |||
f9ad59900a | |||
beb54b62fb | |||
bd095e739d |
@ -2,6 +2,14 @@
|
|||||||
|
|
||||||
### master
|
### master
|
||||||
|
|
||||||
|
### v1.0.0, 2014-08-30
|
||||||
|
- show spinner during the save process
|
||||||
|
- add screencast script
|
||||||
|
- make default program running list even more conservative
|
||||||
|
|
||||||
|
### v0.4.0, 2014-08-29
|
||||||
|
- change plugin name to `tmux-resurrect`. Change all the variable names.
|
||||||
|
|
||||||
### v0.3.0, 2014-08-29
|
### v0.3.0, 2014-08-29
|
||||||
- bugfix: when top is running the pane `$PWD` can't be saved. This was causing
|
- bugfix: when top is running the pane `$PWD` can't be saved. This was causing
|
||||||
issues during the restore and is now fixed.
|
issues during the restore and is now fixed.
|
||||||
|
@ -6,7 +6,7 @@ Code contributions are welcome!
|
|||||||
|
|
||||||
If you find a bug please report it in the issues. When reporting a bug please
|
If you find a bug please report it in the issues. When reporting a bug please
|
||||||
attach:
|
attach:
|
||||||
- a file symlinked to `~/.tmux/sessions/last`.
|
- a file symlinked to `~/.tmux/resurrect/last`.
|
||||||
- your `.tmux.conf`
|
- your `.tmux.conf`
|
||||||
- if you're getting an error paste it to a [gist](https://gist.github.com/) and
|
- if you're getting an error paste it to a [gist](https://gist.github.com/) and
|
||||||
link it in the issue
|
link it in the issue
|
||||||
|
37
README.md
37
README.md
@ -1,6 +1,6 @@
|
|||||||
# Tmux Session Saver
|
# Tmux Resurrect
|
||||||
|
|
||||||
Persists `tmux` environment across system restarts.
|
Restore `tmux` environment after a system restart.
|
||||||
|
|
||||||
Tmux is great, except when you have to restart the computer. You loose all the
|
Tmux is great, except when you have to restart the computer. You loose all the
|
||||||
running programs, working directories, pane layouts etc.
|
running programs, working directories, pane layouts etc.
|
||||||
@ -8,11 +8,16 @@ There are helpful management tools out there, but they require initial
|
|||||||
configuration and continuous updates as your workflow evolves or you start new
|
configuration and continuous updates as your workflow evolves or you start new
|
||||||
projects.
|
projects.
|
||||||
|
|
||||||
`tmux-session-saver` saves all the little details from tmux environment so it
|
`tmux-resurrect` saves all the little details from tmux environment so it
|
||||||
can be easily restored after system restart. No configuration is required.
|
can be completely restored after a system restart (or when you feel like it).
|
||||||
|
No configuration is required. You should feel like you never quit tmux.
|
||||||
|
|
||||||
It even (optionally) [restores vim sessions](#restoring-vim-sessions)!
|
It even (optionally) [restores vim sessions](#restoring-vim-sessions)!
|
||||||
|
|
||||||
|
### Screencast
|
||||||
|
|
||||||
|
[](https://vimeo.com/104763018)
|
||||||
|
|
||||||
### Key bindings
|
### Key bindings
|
||||||
|
|
||||||
- `prefix + Alt-s` - save
|
- `prefix + Alt-s` - save
|
||||||
@ -43,7 +48,7 @@ Add plugin to the list of TPM plugins in `.tmux.conf`:
|
|||||||
|
|
||||||
set -g @tpm_plugins " \
|
set -g @tpm_plugins " \
|
||||||
tmux-plugins/tpm \
|
tmux-plugins/tpm \
|
||||||
tmux-plugins/tmux-session-saver \
|
tmux-plugins/tmux-resurrect \
|
||||||
"
|
"
|
||||||
|
|
||||||
Hit `prefix + I` to fetch the plugin and source it. You should now be able to
|
Hit `prefix + I` to fetch the plugin and source it. You should now be able to
|
||||||
@ -53,11 +58,11 @@ use the plugin.
|
|||||||
|
|
||||||
Clone the repo:
|
Clone the repo:
|
||||||
|
|
||||||
$ git clone https://github.com/tmux-plugins/tmux-session-saver ~/clone/path
|
$ git clone https://github.com/tmux-plugins/tmux-resurrect ~/clone/path
|
||||||
|
|
||||||
Add this line to the bottom of `.tmux.conf`:
|
Add this line to the bottom of `.tmux.conf`:
|
||||||
|
|
||||||
run-shell ~/clone/path/session_saver.tmux
|
run-shell ~/clone/path/resurrect.tmux
|
||||||
|
|
||||||
Reload TMUX environment:
|
Reload TMUX environment:
|
||||||
|
|
||||||
@ -71,37 +76,37 @@ You should now be able to use the plugin.
|
|||||||
Configuration is not required - but it enables extra features.
|
Configuration is not required - but it enables extra features.
|
||||||
|
|
||||||
Only a conservative list of programs is restored by default:<br/>
|
Only a conservative list of programs is restored by default:<br/>
|
||||||
`vi vim emacs man less more tail top htop irssi irb pry "~rails console"`.
|
`vi vim emacs man less more tail top htop irssi`.
|
||||||
Open a github issue if you think some other program should be on the default list.
|
Open a github issue if you think some other program should be on the default list.
|
||||||
|
|
||||||
- Restore additional programs with the setting in `.tmux.conf`:
|
- Restore additional programs with the setting in `.tmux.conf`:
|
||||||
|
|
||||||
set -g @session-saver-processes 'ssh psql mysql sqlite3'
|
set -g @resurrect-processes 'ssh psql mysql sqlite3'
|
||||||
|
|
||||||
- Programs with arguments should be double quoted:
|
- Programs with arguments should be double quoted:
|
||||||
|
|
||||||
set -g @session-saver-processes 'some_program "git log"'
|
set -g @resurrect-processes 'some_program "git log"'
|
||||||
|
|
||||||
- Start with tilde to restore a program whose process contains target name:
|
- Start with tilde to restore a program whose process contains target name:
|
||||||
|
|
||||||
set -g @session-saver-processes 'some_program "~rails server"'
|
set -g @resurrect-processes 'irb pry "~rails server" "~rails console"'
|
||||||
|
|
||||||
- Don't restore any programs:
|
- Don't restore any programs:
|
||||||
|
|
||||||
set -g @session-saver-processes 'false'
|
set -g @resurrect-processes 'false'
|
||||||
|
|
||||||
- Restore **all** programs (be careful with this!):
|
- Restore **all** programs (be careful with this!):
|
||||||
|
|
||||||
set -g @session-saver-processes ':all:'
|
set -g @resurrect-processes ':all:'
|
||||||
|
|
||||||
#### Restoring vim sessions
|
#### Restoring vim sessions
|
||||||
|
|
||||||
- save vim sessions - I recommend [tpope/vim-obsession](tpope/vim-obsession)
|
- save vim sessions. I recommend [tpope/vim-obsession](tpope/vim-obsession).
|
||||||
- in `.tmux.conf`:
|
- in `.tmux.conf`:
|
||||||
|
|
||||||
set -g @session-saver-strategy-vim "session"
|
set -g @resurrect-strategy-vim "session"
|
||||||
|
|
||||||
`tmux-session-saver` will now restore vim sessions if `Sessions.vim` file is
|
`tmux-resurrect` will now restore vim sessions if `Sessions.vim` file is
|
||||||
present.
|
present.
|
||||||
|
|
||||||
### Reporting bugs and contributing
|
### Reporting bugs and contributing
|
||||||
|
@ -9,7 +9,7 @@ set_save_bindings() {
|
|||||||
local key_bindings=$(get_tmux_option "$save_option" "$default_save_key")
|
local key_bindings=$(get_tmux_option "$save_option" "$default_save_key")
|
||||||
local key
|
local key
|
||||||
for key in $key_bindings; do
|
for key in $key_bindings; do
|
||||||
tmux bind-key "$key" run-shell "$CURRENT_DIR/scripts/session_saver.sh"
|
tmux bind-key "$key" run-shell "$CURRENT_DIR/scripts/save.sh"
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -17,7 +17,7 @@ set_restore_bindings() {
|
|||||||
local key_bindings=$(get_tmux_option "$restore_option" "$default_restore_key")
|
local key_bindings=$(get_tmux_option "$restore_option" "$default_restore_key")
|
||||||
local key
|
local key
|
||||||
for key in $key_bindings; do
|
for key in $key_bindings; do
|
||||||
tmux bind-key "$key" run-shell "$CURRENT_DIR/scripts/session_restorer.sh"
|
tmux bind-key "$key" run-shell "$CURRENT_DIR/scripts/restore.sh"
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
@ -1,6 +1,5 @@
|
|||||||
# configurable constants
|
default_resurrect_dir="$HOME/.tmux/resurrect"
|
||||||
default_sessions_dir="$HOME/.tmux/sessions"
|
resurrect_dir_option="@resurrect-dir"
|
||||||
sessions_dir_option="@session-saver-dir"
|
|
||||||
|
|
||||||
SUPPORTED_VERSION="1.9"
|
SUPPORTED_VERSION="1.9"
|
||||||
|
|
||||||
@ -52,15 +51,15 @@ remove_first_char() {
|
|||||||
|
|
||||||
# path helpers
|
# path helpers
|
||||||
|
|
||||||
sessions_dir() {
|
resurrect_dir() {
|
||||||
echo $(get_tmux_option "$sessions_dir_option" "$default_sessions_dir")
|
echo $(get_tmux_option "$resurrect_dir_option" "$default_resurrect_dir")
|
||||||
}
|
}
|
||||||
|
|
||||||
session_path() {
|
resurrect_file_path() {
|
||||||
local timestamp="$(date +"%Y-%m-%dT%H:%M:%S")"
|
local timestamp="$(date +"%Y-%m-%dT%H:%M:%S")"
|
||||||
echo "$(sessions_dir)/tmux_session_${timestamp}.txt"
|
echo "$(resurrect_dir)/tmux_resurrect_${timestamp}.txt"
|
||||||
}
|
}
|
||||||
|
|
||||||
last_session_path() {
|
last_resurrect_file() {
|
||||||
echo "$(sessions_dir)/last"
|
echo "$(resurrect_dir)/last"
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ source "$CURRENT_DIR/process_restore_helpers.sh"
|
|||||||
source "$CURRENT_DIR/spinner_helpers.sh"
|
source "$CURRENT_DIR/spinner_helpers.sh"
|
||||||
|
|
||||||
# Global variable.
|
# Global variable.
|
||||||
# Used during the restoration: if a pane already exists from before, it is
|
# Used during the restore: if a pane already exists from before, it is
|
||||||
# saved in the array in this variable. Later, process running in existing pane
|
# saved in the array in this variable. Later, process running in existing pane
|
||||||
# is also not restored. That makes the restoration process more idempotent.
|
# is also not restored. That makes the restoration process more idempotent.
|
||||||
EXISTING_PANES_VAR=""
|
EXISTING_PANES_VAR=""
|
||||||
@ -21,9 +21,9 @@ is_line_type() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
check_saved_session_exists() {
|
check_saved_session_exists() {
|
||||||
local saved_session="$(last_session_path)"
|
local resurrect_file="$(last_resurrect_file)"
|
||||||
if [ ! -f $saved_session ]; then
|
if [ ! -f $resurrect_file ]; then
|
||||||
display_message "Saved tmux session not found!"
|
display_message "Tmux resurrect file not found!"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@ -137,13 +137,13 @@ restore_all_panes() {
|
|||||||
if is_line_type "pane" "$line"; then
|
if is_line_type "pane" "$line"; then
|
||||||
restore_pane "$line"
|
restore_pane "$line"
|
||||||
fi
|
fi
|
||||||
done < $(last_session_path)
|
done < $(last_resurrect_file)
|
||||||
}
|
}
|
||||||
|
|
||||||
restore_all_pane_processes() {
|
restore_all_pane_processes() {
|
||||||
if restore_pane_processes_enabled; then
|
if restore_pane_processes_enabled; then
|
||||||
local pane_full_command
|
local pane_full_command
|
||||||
awk 'BEGIN { FS="\t"; OFS="\t" } /^pane/ && $11 !~ "^:$" { print $2, $3, $7, $8, $11; }' $(last_session_path) |
|
awk 'BEGIN { FS="\t"; OFS="\t" } /^pane/ && $11 !~ "^:$" { print $2, $3, $7, $8, $11; }' $(last_resurrect_file) |
|
||||||
while IFS=$'\t' read session_name window_number pane_index dir pane_full_command; do
|
while IFS=$'\t' read session_name window_number pane_index dir pane_full_command; do
|
||||||
dir="$(remove_first_char "$dir")"
|
dir="$(remove_first_char "$dir")"
|
||||||
pane_full_command="$(remove_first_char "$pane_full_command")"
|
pane_full_command="$(remove_first_char "$pane_full_command")"
|
||||||
@ -153,14 +153,14 @@ restore_all_pane_processes() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
restore_pane_layout_for_each_window() {
|
restore_pane_layout_for_each_window() {
|
||||||
\grep '^window' $(last_session_path) |
|
\grep '^window' $(last_resurrect_file) |
|
||||||
while IFS=$'\t' read line_type session_name window_number window_active window_flags window_layout; do
|
while IFS=$'\t' read line_type session_name window_number window_active window_flags window_layout; do
|
||||||
tmux select-layout -t "${session_name}:${window_number}" "$window_layout"
|
tmux select-layout -t "${session_name}:${window_number}" "$window_layout"
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
restore_active_pane_for_each_window() {
|
restore_active_pane_for_each_window() {
|
||||||
awk 'BEGIN { FS="\t"; OFS="\t" } /^pane/ && $9 == 1 { print $2, $3, $7; }' $(last_session_path) |
|
awk 'BEGIN { FS="\t"; OFS="\t" } /^pane/ && $9 == 1 { print $2, $3, $7; }' $(last_resurrect_file) |
|
||||||
while IFS=$'\t' read session_name window_number active_pane; do
|
while IFS=$'\t' read session_name window_number active_pane; do
|
||||||
tmux switch-client -t "${session_name}:${window_number}"
|
tmux switch-client -t "${session_name}:${window_number}"
|
||||||
tmux select-pane -t "$active_pane"
|
tmux select-pane -t "$active_pane"
|
||||||
@ -168,14 +168,14 @@ restore_active_pane_for_each_window() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
restore_zoomed_windows() {
|
restore_zoomed_windows() {
|
||||||
awk 'BEGIN { FS="\t"; OFS="\t" } /^window/ && $5 ~ /Z/ { print $2, $3; }' $(last_session_path) |
|
awk 'BEGIN { FS="\t"; OFS="\t" } /^window/ && $5 ~ /Z/ { print $2, $3; }' $(last_resurrect_file) |
|
||||||
while IFS=$'\t' read session_name window_number; do
|
while IFS=$'\t' read session_name window_number; do
|
||||||
tmux resize-pane -t "${session_name}:${window_number}" -Z
|
tmux resize-pane -t "${session_name}:${window_number}" -Z
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
restore_active_and_alternate_windows() {
|
restore_active_and_alternate_windows() {
|
||||||
awk 'BEGIN { FS="\t"; OFS="\t" } /^window/ && $5 ~ /[*-]/ { print $2, $4, $3; }' $(last_session_path) |
|
awk 'BEGIN { FS="\t"; OFS="\t" } /^window/ && $5 ~ /[*-]/ { print $2, $4, $3; }' $(last_resurrect_file) |
|
||||||
sort -u |
|
sort -u |
|
||||||
while IFS=$'\t' read session_name active_window window_number; do
|
while IFS=$'\t' read session_name active_window window_number; do
|
||||||
tmux switch-client -t "${session_name}:${window_number}"
|
tmux switch-client -t "${session_name}:${window_number}"
|
||||||
@ -187,12 +187,12 @@ restore_active_and_alternate_sessions() {
|
|||||||
if is_line_type "state" "$line"; then
|
if is_line_type "state" "$line"; then
|
||||||
restore_state "$line"
|
restore_state "$line"
|
||||||
fi
|
fi
|
||||||
done < $(last_session_path)
|
done < $(last_resurrect_file)
|
||||||
}
|
}
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
if supported_tmux_version_ok && check_saved_session_exists; then
|
if supported_tmux_version_ok && check_saved_session_exists; then
|
||||||
start_spinner
|
start_spinner "Restoring..." "Tmux restore complete!"
|
||||||
restore_all_panes
|
restore_all_panes
|
||||||
restore_pane_layout_for_each_window >/dev/null 2>&1
|
restore_pane_layout_for_each_window >/dev/null 2>&1
|
||||||
restore_all_pane_processes
|
restore_all_pane_processes
|
||||||
@ -202,7 +202,7 @@ main() {
|
|||||||
restore_active_and_alternate_windows
|
restore_active_and_alternate_windows
|
||||||
restore_active_and_alternate_sessions
|
restore_active_and_alternate_sessions
|
||||||
stop_spinner
|
stop_spinner
|
||||||
display_message "Restored all Tmux sessions!"
|
display_message "Tmux restore complete!"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
main
|
main
|
@ -2,7 +2,9 @@
|
|||||||
|
|
||||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||||
|
|
||||||
|
source "$CURRENT_DIR/scripts/variables.sh"
|
||||||
source "$CURRENT_DIR/helpers.sh"
|
source "$CURRENT_DIR/helpers.sh"
|
||||||
|
source "$CURRENT_DIR/spinner_helpers.sh"
|
||||||
|
|
||||||
pane_format() {
|
pane_format() {
|
||||||
local delimiter=$'\t'
|
local delimiter=$'\t'
|
||||||
@ -88,19 +90,21 @@ dump_state() {
|
|||||||
tmux display-message -p "$(state_format)"
|
tmux display-message -p "$(state_format)"
|
||||||
}
|
}
|
||||||
|
|
||||||
save_all_sessions() {
|
save_all() {
|
||||||
local session_path="$(session_path)"
|
local resurrect_file_path="$(resurrect_file_path)"
|
||||||
mkdir -p "$(sessions_dir)"
|
mkdir -p "$(resurrect_dir)"
|
||||||
dump_panes > $session_path
|
dump_panes > $resurrect_file_path
|
||||||
dump_windows >> $session_path
|
dump_windows >> $resurrect_file_path
|
||||||
dump_state >> $session_path
|
dump_state >> $resurrect_file_path
|
||||||
ln -fs "$session_path" "$(last_session_path)"
|
ln -fs "$resurrect_file_path" "$(last_resurrect_file)"
|
||||||
display_message "Saved all Tmux sessions!"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
if supported_tmux_version_ok; then
|
if supported_tmux_version_ok; then
|
||||||
save_all_sessions
|
start_spinner "Saving..." "Tmux environment saved!"
|
||||||
|
save_all
|
||||||
|
stop_spinner
|
||||||
|
display_message "Tmux environment saved!"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
main
|
main
|
@ -1,5 +1,5 @@
|
|||||||
start_spinner() {
|
start_spinner() {
|
||||||
$CURRENT_DIR/tmux_spinner.sh "Restoring sessions..." "Restored all Tmux sessions!" &
|
$CURRENT_DIR/tmux_spinner.sh "$1" "$2" &
|
||||||
export SPINNER_PID=$!
|
export SPINNER_PID=$!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
# key bindings
|
# key bindings
|
||||||
default_save_key="M-s"
|
default_save_key="M-s"
|
||||||
save_option="@session-saver-save"
|
save_option="@resurrect-save"
|
||||||
|
|
||||||
default_restore_key="M-r"
|
default_restore_key="M-r"
|
||||||
restore_option="@session-saver-restore"
|
restore_option="@resurrect-restore"
|
||||||
|
|
||||||
# default processes that are restored
|
# default processes that are restored
|
||||||
default_proc_list_option="@session-saver-default-processes"
|
default_proc_list_option="@resurrect-default-processes"
|
||||||
default_proc_list='vi vim emacs man less more tail top htop irssi irb pry "~rails console"'
|
default_proc_list='vi vim emacs man less more tail top htop irssi'
|
||||||
|
|
||||||
# User defined processes that are restored
|
# User defined processes that are restored
|
||||||
# 'false' - nothing is restored
|
# 'false' - nothing is restored
|
||||||
@ -15,9 +15,9 @@ default_proc_list='vi vim emacs man less more tail top htop irssi irb pry "~rail
|
|||||||
#
|
#
|
||||||
# user defined list of programs that are restored:
|
# user defined list of programs that are restored:
|
||||||
# 'my_program foo another_program'
|
# 'my_program foo another_program'
|
||||||
restore_processes_option="@session-saver-processes"
|
restore_processes_option="@resurrect-processes"
|
||||||
restore_processes=""
|
restore_processes=""
|
||||||
|
|
||||||
# Defines part of the user variable. Example usage:
|
# Defines part of the user variable. Example usage:
|
||||||
# set -g @session-saver-strategy-vim "session"
|
# set -g @resurrect-strategy-vim "session"
|
||||||
restore_process_strategy_option="@session-saver-strategy-"
|
restore_process_strategy_option="@resurrect-strategy-"
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
#
|
#
|
||||||
# Restores a vim session from 'Session.vim' file, if it exists.
|
# Restores a vim session from 'Session.vim' file, if it exists.
|
||||||
# If 'Session.vim' does not exist, it falls back to invoking the original
|
# If 'Session.vim' does not exist, it falls back to invoking the original
|
||||||
# command (withouth the `-S` flag).
|
# command (without the `-S` flag).
|
||||||
|
|
||||||
ORIGINAL_COMMAND="$1"
|
ORIGINAL_COMMAND="$1"
|
||||||
DIRECTORY="$2"
|
DIRECTORY="$2"
|
||||||
@ -21,7 +21,7 @@ main() {
|
|||||||
if vim_session_file_exists; then
|
if vim_session_file_exists; then
|
||||||
echo "vim -S"
|
echo "vim -S"
|
||||||
elif original_command_contains_session_flag; then
|
elif original_command_contains_session_flag; then
|
||||||
# Session file does not exist, yet the orignal vim command contains
|
# Session file does not exist, yet the original vim command contains
|
||||||
# session flag `-S`. This will cause an error, so we're falling back to
|
# session flag `-S`. This will cause an error, so we're falling back to
|
||||||
# starting plain vim.
|
# starting plain vim.
|
||||||
echo "vim"
|
echo "vim"
|
||||||
|
BIN
video/screencast_img.png
Normal file
BIN
video/screencast_img.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 121 KiB |
110
video/script.md
Normal file
110
video/script.md
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
# Screencast script
|
||||||
|
|
||||||
|
1. Intro
|
||||||
|
========
|
||||||
|
Let's demo tmux resurrect plugin.
|
||||||
|
|
||||||
|
Tmux resurrect enables persisting tmux sessions, so it can survive the dreaded
|
||||||
|
system restarts.
|
||||||
|
|
||||||
|
The benefit is uninterrupted workflow with no configuration required.
|
||||||
|
|
||||||
|
2. Working session
|
||||||
|
==================
|
||||||
|
Script
|
||||||
|
------
|
||||||
|
Let me show you what I have in this tmux demo session.
|
||||||
|
|
||||||
|
First of all, I have vim open and it has a couple files loaded.
|
||||||
|
|
||||||
|
Then there's a tmux window with a couple splits in various directories across
|
||||||
|
the system.
|
||||||
|
|
||||||
|
Next window contains tmux man page,
|
||||||
|
and then there's `htop` program.
|
||||||
|
|
||||||
|
And this is just one of many projects I'm currently running.
|
||||||
|
|
||||||
|
Actions
|
||||||
|
-------
|
||||||
|
- blank tmux window
|
||||||
|
- vim
|
||||||
|
- `ls` to show open files
|
||||||
|
- multiple pane windows (3)
|
||||||
|
- man tmux
|
||||||
|
- htop
|
||||||
|
- psql
|
||||||
|
- show a list of session
|
||||||
|
|
||||||
|
3. Saving the environment
|
||||||
|
=========================
|
||||||
|
Script
|
||||||
|
------
|
||||||
|
With vanilla tmux, when I restart the computer this whole environment will be
|
||||||
|
lost and I'll have to invest time to restore it.
|
||||||
|
|
||||||
|
tmux resurrect gives you the ability to persist everything with
|
||||||
|
prefix plus alt-s.
|
||||||
|
|
||||||
|
Now tmux environment is saved and I can safely shut down tmux with a
|
||||||
|
kill server command.
|
||||||
|
|
||||||
|
Actions
|
||||||
|
-------
|
||||||
|
- prefix + M-s
|
||||||
|
- :kill-server
|
||||||
|
|
||||||
|
4. Restoring the environment
|
||||||
|
============================
|
||||||
|
Script
|
||||||
|
------
|
||||||
|
At this point restoring everything back is easy.
|
||||||
|
|
||||||
|
I'll fire up tmux again. Notice it's completely empty.
|
||||||
|
|
||||||
|
Now, I'll press prefix plus alt-r and everything will restore.
|
||||||
|
|
||||||
|
Let's see how things look now.
|
||||||
|
First of all, I'm back to the exact same window I was in when the environment
|
||||||
|
was saved. Second - you can see the `htop` program was restored.
|
||||||
|
|
||||||
|
Going back there's tmux man page
|
||||||
|
a window with multiple panes with the exact same layout as before
|
||||||
|
and vim.
|
||||||
|
|
||||||
|
|
||||||
|
tmux resurrect takes special care of vim. By leveraging vim's sessions, it
|
||||||
|
preserves vim's split windows, open files, even the list of files edited before.
|
||||||
|
|
||||||
|
Check out the project readme for more details about special treatment for vim.
|
||||||
|
|
||||||
|
That was just one of the restored tmux sessions. If I open tmux session list you
|
||||||
|
can see all the other projects are restored as well.
|
||||||
|
|
||||||
|
|
||||||
|
When you see all these programs running you might be concerned that this plugin
|
||||||
|
started a lot of potentially destructive processes.
|
||||||
|
|
||||||
|
For example, when you restore tmux you don't want to accidentally start backups,
|
||||||
|
resource intensive or sensitive programs.
|
||||||
|
|
||||||
|
There's no need to be worried though. By default, this plugin starts only a
|
||||||
|
conservative list of programs like vim, less, tail, htop and similar.
|
||||||
|
This list of programs restored by default is in the project readme. Also, you
|
||||||
|
can easily add more programs to it.
|
||||||
|
|
||||||
|
If you feel paranoid, there's an option that prevents restoring any program.
|
||||||
|
|
||||||
|
Actions
|
||||||
|
-------
|
||||||
|
- tmux
|
||||||
|
- prefix + M-r
|
||||||
|
|
||||||
|
- open previous windows
|
||||||
|
- in vim hit :ls
|
||||||
|
|
||||||
|
- prefix + s for a list of panes
|
||||||
|
|
||||||
|
5. Outro
|
||||||
|
========
|
||||||
|
That's it for this demo. I hope you'll find tmux resurrect useful.
|
Reference in New Issue
Block a user