22 Commits

Author SHA1 Message Date
47db8198d3 v2.1.0 2015-02-12 03:45:15 +01:00
c4375bf642 Enable 'full restore' by overwriting a single pane 2015-02-10 15:16:26 +01:00
ddf9c5ef87 Reorder function in restore script 2015-02-10 13:44:14 +01:00
442b3ed244 v2.0.0 2015-02-10 12:57:24 +01:00
b91e18cb0e Remove deprecated and key bindings 2015-02-10 12:56:23 +01:00
869be6fa5a Update readme
Fixes #71
2015-02-10 12:48:53 +01:00
028e7b7c2e Refactoring: prefer using variable with tab character 2015-02-10 12:48:53 +01:00
b502572a07 Restore active and alternate windows only if they are present in the 'last' file 2015-02-10 12:48:53 +01:00
1c8efb034a If there are no grouped sessions, do not output empty line 2015-02-10 12:48:53 +01:00
95ec3c1d9b Save and restore active and alternate windows for grouped sessions 2015-02-10 12:48:53 +01:00
5dc22a4a9b Restore grouped sessions 2015-02-10 12:48:53 +01:00
bfc625e13f Save grouped sessions
Grouped sessions are session started with the command
`tmux new-session -t <existing-session-name>`

Those sessions share the panes and windows with the existing, original
session.
We're making sure to identify and save grouped sessions.
On the other hand, we don't want to save panes and windows twice
2015-02-10 12:48:53 +01:00
3244b809eb Merge pull request #67 from SilentGob/master
Correct ps flag for OpenBSD
2015-01-16 00:25:50 +01:00
a9ac17a8f8 Correct ps flag for OpenBSD
Same flag as FreeBSD is needed
2015-01-15 23:20:29 +01:00
9eae48b87e Update README 2014-11-21 14:47:57 +01:00
e8401ba305 Merge pull request #56 from cunha/master
allow relative paths in @resurrect-dir
2014-11-09 20:25:26 +01:00
e770c87e10 v1.5.0 2014-11-09 16:43:44 +01:00
601366be6d Support for restoring neovim sessions 2014-11-09 16:42:53 +01:00
831fc5a458 allow relative paths in @resurrect-dir
this has been tested to work with set -g @resurrect-dir '.tmux/resu rrect'
2014-11-07 11:52:21 -02:00
059686ab6c Merge pull request #55 from rburny/master
Fixes to #51 and #52
2014-10-26 16:59:41 +01:00
488f086fa5 Add a note about HISTCONTROL to README. 2014-10-26 02:17:12 +02:00
fcf7ca13f0 Only save pane history if its not running any program (other than Bash
shell). Fixes a bug where 'history -w' was sent to pane running Bash
script.
2014-10-26 01:30:00 +02:00
8 changed files with 270 additions and 56 deletions

View File

@ -2,6 +2,23 @@
### master ### master
### v2.1.0, 2015-02-12
- if restore is started when there's only **1 pane in the whole tmux server**,
assume the users wants the "full restore" and overrwrite that pane.
### v2.0.0, 2015-02-10
- add link to the wiki page for "first pane/window issue" to the README as well
as other tweaks
- save and restore grouped sessions (used with multi-monitor workflow)
- save and restore active and alternate windows in grouped sessions
- if there are no grouped sessions, do not output empty line to "last" file
- restore active and alternate windows only if they are present in the "last" file
- refactoring: prefer using variable with tab character
- remove deprecated `M-s` and `M-r` key bindings (breaking change)
### v1.5.0, 2014-11-09
- add support for restoring neovim sessions
### v1.4.0, 2014-10-25 ### v1.4.0, 2014-10-25
- plugin now uses strategies when fetching pane full command. Implemented - plugin now uses strategies when fetching pane full command. Implemented
'default' strategy. 'default' strategy.

View File

@ -12,7 +12,7 @@ projects.
can be completely restored after a system restart (or when you feel like it). 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. 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 and neovim sessions](#restoring-vim-and-neovim-sessions)!
### Screencast ### Screencast
@ -23,8 +23,6 @@ It even (optionally) [restores vim sessions](#restoring-vim-sessions)!
- `prefix + Ctrl-s` - save - `prefix + Ctrl-s` - save
- `prefix + Ctrl-r` - restore - `prefix + Ctrl-r` - restore
`prefix + Alt-s` and `prefix + Alt-r` key bindings are now deprecated.
For custom key bindings, add to `.tmux.conf`: For custom key bindings, add to `.tmux.conf`:
set -g @resurrect-save 'S' set -g @resurrect-save 'S'
@ -42,17 +40,21 @@ This plugin goes to great lengths to save and restore all the details from your
- active and alternative window for each session - active and alternative window for each session
- windows with focus - windows with focus
- active pane for each window - active pane for each window
- "grouped sessions" (useful feature when using tmux with multiple monitors)
- programs running within a pane! More details in the - programs running within a pane! More details in the
[configuration section](#configuration). [configuration section](#configuration).
- restoring vim sessions (optional). More details in - restoring vim/neovim sessions (optional). More details in
[restoring vim sessions](#restoring-vim-sessions). [restoring vim and neovim sessions](#restoring-vim-and-neovim-sessions).
- restoring bash history (optional, *experimental*). More details in - restoring bash history (optional, \*experimental*). More details in
[restoring bash history](#restoring-bash-history-experimental). [restoring bash history](#restoring-bash-history-experimental).
Requirements / dependencies: `tmux 1.9` or higher, `bash`. Requirements / dependencies: `tmux 1.9` or higher, `bash`.
`tmux-resurrect` is idempotent! It will not try to restore panes or windows that `tmux-resurrect` is idempotent! It will not try to restore panes or windows that
already exist. already exist.<br/>
The single exception to this is when tmux is started with only 1 pane in order
to restore previous tmux env. In this case only will this single pane be
overwritten.
### Installation with [Tmux Plugin Manager](https://github.com/tmux-plugins/tpm) (recommended) ### Installation with [Tmux Plugin Manager](https://github.com/tmux-plugins/tpm) (recommended)
@ -88,7 +90,7 @@ 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`. `vi vim nvim emacs man less more tail top htop irssi`.
- Restore additional programs with the setting in `.tmux.conf`: - Restore additional programs with the setting in `.tmux.conf`:
@ -115,15 +117,20 @@ Only a conservative list of programs is restored by default:<br/>
set -g @resurrect-processes ':all:' set -g @resurrect-processes ':all:'
#### Restoring vim sessions #### Restoring vim and neovim sessions
- save vim sessions. I recommend [tpope/vim-obsession](https://github.com/tpope/vim-obsession). - save vim/neovim sessions. I recommend
[tpope/vim-obsession](https://github.com/tpope/vim-obsession) (as almost every
plugin, it works for both vim and neovim).
- in `.tmux.conf`: - in `.tmux.conf`:
# for vim
set -g @resurrect-strategy-vim 'session' set -g @resurrect-strategy-vim 'session'
# for neovim
set -g @resurrect-strategy-nvim 'session'
`tmux-resurrect` will now restore vim sessions if `Sessions.vim` file is `tmux-resurrect` will now restore vim and neovim sessions if `Sessions.vim` file
present. is present.
#### Resurrect save dir #### Resurrect save dir
@ -136,11 +143,13 @@ Change this with:
In `.tmux.conf`: In `.tmux.conf`:
set -g @resurrect-save-bash-history 'on' set -g @resurrect-save-bash-history 'on'
Bash `history` for individual panes will now be saved and restored. Due to Bash `history` for individual panes will now be saved and restored. Due to
technical limitations, this only works for panes which have Bash running in technical limitations, this only works for panes which have no program running in
foreground (as opposed to e.g. vi or top) when saving. foreground when saving. `tmux-resurrect` will send history write command
to each such pane. To prevent these commands from being added to history themselves,
add `HISTCONTROL=ignoreboth` to your `.bashrc` (this is set by default in Ubuntu).
### Other goodies ### Other goodies
@ -159,7 +168,7 @@ Both contributing and bug reports are welcome. Please check out
### Credits ### Credits
[Mislav Marohnić](https://github.com/mislav) - the idea for the plugin came from his [Mislav Marohnić](https://github.com/mislav) - the idea for the plugin came from his
[tmux-session script](https://github.com/mislav/dotfiles/blob/master/bin/tmux-session). [tmux-session script](https://github.com/mislav/dotfiles/blob/2036b5e03fb430bbcbc340689d63328abaa28876/bin/tmux-session).
### Other ### Other

View File

@ -13,6 +13,7 @@ exit_safely_if_empty_ppid() {
ps_command_flags() { ps_command_flags() {
case $(uname -s) in case $(uname -s) in
FreeBSD) echo "-ao" ;; FreeBSD) echo "-ao" ;;
OpenBSD) echo "-ao" ;;
*) echo "-eo" ;; *) echo "-eo" ;;
esac esac
} }

View File

@ -3,6 +3,8 @@ resurrect_dir_option="@resurrect-dir"
SUPPORTED_VERSION="1.9" SUPPORTED_VERSION="1.9"
d=$'\t'
# helper functions # helper functions
get_tmux_option() { get_tmux_option() {
local option="$1" local option="$1"
@ -54,6 +56,16 @@ save_bash_history_option_on() {
[ "$option" == "on" ] [ "$option" == "on" ]
} }
get_grouped_sessions() {
local grouped_sessions_dump="$1"
export GROUPED_SESSIONS="${d}$(echo "$grouped_sessions_dump" | cut -f2 -d"$d" | tr "\\n" "$d")"
}
is_session_grouped() {
local session_name="$1"
[[ "$GROUPED_SESSIONS" == *"${d}${session_name}${d}"* ]]
}
# path helpers # path helpers
resurrect_dir() { resurrect_dir() {
@ -73,10 +85,3 @@ resurrect_history_file() {
local pane_id="$1" local pane_id="$1"
echo "$(resurrect_dir)/bash_history-${pane_id}" echo "$(resurrect_dir)/bash_history-${pane_id}"
} }
restore_zoomed_windows() {
awk 'BEGIN { FS="\t"; OFS="\t" } /^pane/ && $6 ~ /Z/ && $9 == 1 { print $2, $3; }' $(last_resurrect_file) |
while IFS=$'\t' read session_name window_number; do
tmux resize-pane -t "${session_name}:${window_number}" -Z
done
}

View File

@ -7,12 +7,17 @@ source "$CURRENT_DIR/helpers.sh"
source "$CURRENT_DIR/process_restore_helpers.sh" source "$CURRENT_DIR/process_restore_helpers.sh"
source "$CURRENT_DIR/spinner_helpers.sh" source "$CURRENT_DIR/spinner_helpers.sh"
# delimiter
d=$'\t'
# Global variable. # Global variable.
# Used during the restore: 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=""
RESTORING_FROM_SCRATCH="false"
is_line_type() { is_line_type() {
local line_type="$1" local line_type="$1"
local line="$2" local line="$2"
@ -53,6 +58,14 @@ is_pane_registered_as_existing() {
[[ "$EXISTING_PANES_VAR" =~ "$pane_custom_id" ]] [[ "$EXISTING_PANES_VAR" =~ "$pane_custom_id" ]]
} }
restore_from_scratch_true() {
RESTORING_FROM_SCRATCH="true"
}
is_restoring_from_scratch() {
[ "$RESTORING_FROM_SCRATCH" == "true" ]
}
window_exists() { window_exists() {
local session_name="$1" local session_name="$1"
local window_number="$2" local window_number="$2"
@ -106,14 +119,22 @@ new_pane() {
restore_pane() { restore_pane() {
local pane="$1" local pane="$1"
while IFS=$'\t' read line_type session_name window_number window_name window_active window_flags pane_index dir pane_active pane_command pane_full_command; do while IFS=$d read line_type session_name window_number window_name window_active window_flags pane_index dir pane_active pane_command pane_full_command; do
dir="$(remove_first_char "$dir")" dir="$(remove_first_char "$dir")"
window_name="$(remove_first_char "$window_name")" window_name="$(remove_first_char "$window_name")"
pane_full_command="$(remove_first_char "$pane_full_command")" pane_full_command="$(remove_first_char "$pane_full_command")"
if pane_exists "$session_name" "$window_number" "$pane_index"; then if pane_exists "$session_name" "$window_number" "$pane_index"; then
# Pane exists, no need to create it! if is_restoring_from_scratch; then
# Pane existence is registered. Later, it's process also isn't restored. # overwrite the pane
register_existing_pane "$session_name" "$window_number" "$pane_index" # happens only for the first pane if it's the only registered pane for the whole tmux server
local pane_id="$(tmux display-message -p -F "#{pane_id}" -t "$session_name:$window_number")"
new_pane "$session_name" "$window_number" "$window_name" "$dir"
tmux kill-pane -t "$pane_id"
else
# Pane exists, no need to create it!
# Pane existence is registered. Later, its process also won't be restored.
register_existing_pane "$session_name" "$window_number" "$pane_index"
fi
elif window_exists "$session_name" "$window_number"; then elif window_exists "$session_name" "$window_number"; then
new_pane "$session_name" "$window_number" "$window_name" "$dir" new_pane "$session_name" "$window_number" "$window_name" "$dir"
elif session_exists "$session_name"; then elif session_exists "$session_name"; then
@ -127,13 +148,54 @@ restore_pane() {
restore_state() { restore_state() {
local state="$1" local state="$1"
echo "$state" | echo "$state" |
while IFS=$'\t' read line_type client_session client_last_session; do while IFS=$d read line_type client_session client_last_session; do
tmux switch-client -t "$client_last_session" tmux switch-client -t "$client_last_session"
tmux switch-client -t "$client_session" tmux switch-client -t "$client_session"
done done
} }
restore_grouped_session() {
local grouped_session="$1"
echo "$grouped_session" |
while IFS=$d read line_type grouped_session original_session alternate_window active_window; do
TMUX="" tmux -S "$(tmux_socket)" new-session -d -s "$grouped_session" -t "$original_session"
done
}
restore_active_and_alternate_windows_for_grouped_sessions() {
local grouped_session="$1"
echo "$grouped_session" |
while IFS=$d read line_type grouped_session original_session alternate_window_index active_window_index; do
alternate_window_index="$(remove_first_char "$alternate_window_index")"
active_window_index="$(remove_first_char "$active_window_index")"
if [ -n "$alternate_window_index" ]; then
tmux switch-client -t "${grouped_session}:${alternate_window_index}"
fi
if [ -n "$active_window_index" ]; then
tmux switch-client -t "${grouped_session}:${active_window_index}"
fi
done
}
never_ever_overwrite() {
local overwrite_option_value="$(get_tmux_option "$overwrite_option" "")"
[ -n "$overwrite_option_value" ]
}
detect_if_restoring_from_scratch() {
if never_ever_overwrite; then
return
fi
local total_number_of_panes="$(tmux list-panes -a | wc -l | sed 's/ //g')"
if [ "$total_number_of_panes" -eq 1 ]; then
restore_from_scratch_true
fi
}
# functions called from main (ordered)
restore_all_panes() { restore_all_panes() {
detect_if_restoring_from_scratch
while read line; do while read line; do
if is_line_type "pane" "$line"; then if is_line_type "pane" "$line"; then
restore_pane "$line" restore_pane "$line"
@ -141,9 +203,16 @@ restore_all_panes() {
done < $(last_resurrect_file) done < $(last_resurrect_file)
} }
restore_pane_layout_for_each_window() {
\grep '^window' $(last_resurrect_file) |
while IFS=$d read line_type session_name window_number window_active window_flags window_layout; do
tmux select-layout -t "${session_name}:${window_number}" "$window_layout"
done
}
restore_shell_history() { restore_shell_history() {
awk 'BEGIN { FS="\t"; OFS="\t" } /^pane/ { print $2, $3, $7, $10; }' $(last_resurrect_file) | awk 'BEGIN { FS="\t"; OFS="\t" } /^pane/ { print $2, $3, $7, $10; }' $(last_resurrect_file) |
while IFS=$'\t' read session_name window_number pane_index pane_command; do while IFS=$d read session_name window_number pane_index pane_command; do
if ! is_pane_registered_as_existing "$session_name" "$window_number" "$pane_index"; then if ! is_pane_registered_as_existing "$session_name" "$window_number" "$pane_index"; then
if [ "$pane_command" = "bash" ]; then if [ "$pane_command" = "bash" ]; then
local pane_id="$session_name:$window_number.$pane_index" local pane_id="$session_name:$window_number.$pane_index"
@ -160,7 +229,7 @@ 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_resurrect_file) | 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=$d 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")"
restore_pane_process "$pane_full_command" "$session_name" "$window_number" "$pane_index" "$dir" restore_pane_process "$pane_full_command" "$session_name" "$window_number" "$pane_index" "$dir"
@ -168,25 +237,34 @@ restore_all_pane_processes() {
fi fi
} }
restore_pane_layout_for_each_window() {
\grep '^window' $(last_resurrect_file) |
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"
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_resurrect_file) | 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=$d 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"
done done
} }
restore_zoomed_windows() {
awk 'BEGIN { FS="\t"; OFS="\t" } /^pane/ && $6 ~ /Z/ && $9 == 1 { print $2, $3; }' $(last_resurrect_file) |
while IFS=$d read session_name window_number; do
tmux resize-pane -t "${session_name}:${window_number}" -Z
done
}
restore_grouped_sessions() {
while read line; do
if is_line_type "grouped_session" "$line"; then
restore_grouped_session "$line"
restore_active_and_alternate_windows_for_grouped_sessions "$line"
fi
done < $(last_resurrect_file)
}
restore_active_and_alternate_windows() { restore_active_and_alternate_windows() {
awk 'BEGIN { FS="\t"; OFS="\t" } /^window/ && $5 ~ /[*-]/ { print $2, $4, $3; }' $(last_resurrect_file) | 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=$d read session_name active_window window_number; do
tmux switch-client -t "${session_name}:${window_number}" tmux switch-client -t "${session_name}:${window_number}"
done done
} }
@ -211,6 +289,7 @@ main() {
# below functions restore exact cursor positions # below functions restore exact cursor positions
restore_active_pane_for_each_window restore_active_pane_for_each_window
restore_zoomed_windows restore_zoomed_windows
restore_grouped_sessions # also restores active and alt windows for grouped sessions
restore_active_and_alternate_windows restore_active_and_alternate_windows
restore_active_and_alternate_sessions restore_active_and_alternate_sessions
stop_spinner stop_spinner

View File

@ -6,8 +6,23 @@ source "$CURRENT_DIR/variables.sh"
source "$CURRENT_DIR/helpers.sh" source "$CURRENT_DIR/helpers.sh"
source "$CURRENT_DIR/spinner_helpers.sh" source "$CURRENT_DIR/spinner_helpers.sh"
# delimiters
d=$'\t'
delimiter=$'\t'
grouped_sessions_format() {
local format
format+="#{session_grouped}"
format+="${delimiter}"
format+="#{session_group}"
format+="${delimiter}"
format+="#{session_id}"
format+="${delimiter}"
format+="#{session_name}"
echo "$format"
}
pane_format() { pane_format() {
local delimiter=$'\t'
local format local format
format+="pane" format+="pane"
format+="${delimiter}" format+="${delimiter}"
@ -34,7 +49,6 @@ pane_format() {
} }
window_format() { window_format() {
local delimiter=$'\t'
local format local format
format+="window" format+="window"
format+="${delimiter}" format+="${delimiter}"
@ -51,7 +65,6 @@ window_format() {
} }
state_format() { state_format() {
local delimiter=$'\t'
local format local format
format+="state" format+="state"
format+="${delimiter}" format+="${delimiter}"
@ -65,6 +78,10 @@ dump_panes_raw() {
tmux list-panes -a -F "$(pane_format)" tmux list-panes -a -F "$(pane_format)"
} }
dump_windows_raw(){
tmux list-windows -a -F "$(window_format)"
}
_save_command_strategy_file() { _save_command_strategy_file() {
local save_command_strategy="$(get_tmux_option "$save_command_strategy_option" "$default_save_command_strategy")" local save_command_strategy="$(get_tmux_option "$save_command_strategy_option" "$default_save_command_strategy")"
local strategy_file="$CURRENT_DIR/../save_command_strategies/${save_command_strategy}.sh" local strategy_file="$CURRENT_DIR/../save_command_strategies/${save_command_strategy}.sh"
@ -86,7 +103,8 @@ pane_full_command() {
save_shell_history() { save_shell_history() {
local pane_id="$1" local pane_id="$1"
local pane_command="$2" local pane_command="$2"
if [ "$pane_command" = "bash" ]; then local full_command="$3"
if [ "$pane_command" = "bash" ] && [ "$full_command" = ":" ]; then
# leading space prevents the command from being saved to history # leading space prevents the command from being saved to history
# (assuming default HISTCONTROL settings) # (assuming default HISTCONTROL settings)
local write_command=" history -w '$(resurrect_history_file "$pane_id")'" local write_command=" history -w '$(resurrect_history_file "$pane_id")'"
@ -96,12 +114,56 @@ save_shell_history() {
fi fi
} }
get_active_window_index() {
local session_name="$1"
tmux list-windows -t "$session_name" -F "#{window_flags} #{window_index}" |
awk '$1 ~ /\*/ { print $2; }'
}
get_alternate_window_index() {
local session_name="$1"
tmux list-windows -t "$session_name" -F "#{window_flags} #{window_index}" |
awk '$1 ~ /-/ { print $2; }'
}
dump_grouped_sessions() {
local current_session_group=""
local original_session
tmux list-sessions -F "$(grouped_sessions_format)" |
grep "^1" |
cut -c 3- |
sort |
while IFS=$d read session_group session_id session_name; do
if [ "$session_group" != "$current_session_group" ]; then
# this session is the original/first session in the group
original_session="$session_name"
current_session_group="$session_group"
else
# this session "points" to the original session
active_window_index="$(get_active_window_index "$session_name")"
alternate_window_index="$(get_alternate_window_index "$session_name")"
echo "grouped_session${d}${session_name}${d}${original_session}${d}:${alternate_window_index}${d}:${active_window_index}"
fi
done
}
fetch_and_dump_grouped_sessions(){
local grouped_sessions_dump="$(dump_grouped_sessions)"
get_grouped_sessions "$grouped_sessions_dump"
if [ -n "$grouped_sessions_dump" ]; then
echo "$grouped_sessions_dump"
fi
}
# translates pane pid to process command running inside a pane # translates pane pid to process command running inside a pane
dump_panes() { dump_panes() {
local full_command local full_command
local d=$'\t' # delimiter
dump_panes_raw | dump_panes_raw |
while IFS=$'\t' read line_type session_name window_number window_name window_active window_flags pane_index dir pane_active pane_command pane_pid; do while IFS=$d read line_type session_name window_number window_name window_active window_flags pane_index dir pane_active pane_command pane_pid; do
# not saving panes from grouped sessions
if is_session_grouped "$session_name"; then
continue
fi
# check if current pane is part of a maximized window and if the pane is active # check if current pane is part of a maximized window and if the pane is active
if [[ "${window_flags}" == *Z* ]] && [[ ${pane_active} == 1 ]]; then if [[ "${window_flags}" == *Z* ]] && [[ ${pane_active} == 1 ]]; then
# unmaximize the pane # unmaximize the pane
@ -113,7 +175,14 @@ dump_panes() {
} }
dump_windows() { dump_windows() {
tmux list-windows -a -F "$(window_format)" dump_windows_raw |
while IFS=$d read line_type session_name window_index window_active window_flags window_layout; do
# not saving windows from grouped sessions
if is_session_grouped "$session_name"; then
continue
fi
echo "${line_type}${d}${session_name}${d}${window_index}${d}${window_active}${d}${window_flags}${d}${window_layout}"
done
} }
dump_state() { dump_state() {
@ -121,19 +190,20 @@ dump_state() {
} }
dump_bash_history() { dump_bash_history() {
dump_panes_raw | dump_panes |
while IFS=$'\t' read line_type session_name window_number window_name window_active window_flags pane_index dir pane_active pane_command pane_pid; do while IFS=$d read line_type session_name window_number window_name window_active window_flags pane_index dir pane_active pane_command full_command; do
save_shell_history "$session_name:$window_number.$pane_index" "$pane_command" save_shell_history "$session_name:$window_number.$pane_index" "$pane_command" "$full_command"
done done
} }
save_all() { save_all() {
local resurrect_file_path="$(resurrect_file_path)" local resurrect_file_path="$(resurrect_file_path)"
mkdir -p "$(resurrect_dir)" mkdir -p "$(resurrect_dir)"
dump_panes > $resurrect_file_path fetch_and_dump_grouped_sessions > "$resurrect_file_path"
dump_windows >> $resurrect_file_path dump_panes >> "$resurrect_file_path"
dump_state >> $resurrect_file_path dump_windows >> "$resurrect_file_path"
ln -fs "$resurrect_file_path" "$(last_resurrect_file)" dump_state >> "$resurrect_file_path"
ln -fs "$(basename "$resurrect_file_path")" "$(last_resurrect_file)"
if save_bash_history_option_on; then if save_bash_history_option_on; then
dump_bash_history dump_bash_history
fi fi

View File

@ -1,13 +1,13 @@
# key bindings # key bindings
default_save_key="M-s C-s" default_save_key="C-s"
save_option="@resurrect-save" save_option="@resurrect-save"
default_restore_key="M-r C-r" default_restore_key="C-r"
restore_option="@resurrect-restore" restore_option="@resurrect-restore"
# default processes that are restored # default processes that are restored
default_proc_list_option="@resurrect-default-processes" default_proc_list_option="@resurrect-default-processes"
default_proc_list='vi vim emacs man less more tail top htop irssi' default_proc_list='vi vim nvim 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
@ -28,3 +28,6 @@ save_command_strategy_option="@resurrect-save-command-strategy"
default_save_command_strategy="ps" default_save_command_strategy="ps"
bash_history_option="@resurrect-save-bash-history" bash_history_option="@resurrect-save-bash-history"
# set to 'on' to ensure panes are never ever overwritten
overwrite_option="@resurrect-never-overwrite"

30
strategies/nvim_session.sh Executable file
View File

@ -0,0 +1,30 @@
#!/usr/bin/env bash
# "nvim session strategy"
#
# Same as vim strategy, see file 'vim_session.sh'
ORIGINAL_COMMAND="$1"
DIRECTORY="$2"
nvim_session_file_exists() {
[ -e "${DIRECTORY}/Session.vim" ]
}
original_command_contains_session_flag() {
[[ "$ORIGINAL_COMMAND" =~ "-S" ]]
}
main() {
if nvim_session_file_exists; then
echo "nvim -S"
elif original_command_contains_session_flag; then
# Session file does not exist, yet the original nvim command contains
# session flag `-S`. This will cause an error, so we're falling back to
# starting plain nvim.
echo "nvim"
else
echo "$ORIGINAL_COMMAND"
fi
}
main