12 Commits

Author SHA1 Message Date
db05b2133b v1.2.0 2014-09-01 20:32:54 +02:00
8368355240 Enable inline strategies when restoring programs 2014-09-01 20:32:27 +02:00
20c5fc40cc v1.1.0 2014-08-31 11:37:14 +02:00
af3cb5db2e ctrl key mappings; deprecate alt keys 2014-08-31 11:35:58 +02:00
deb3e9fdce Add a reference to other plugins in the readme 2014-08-31 01:38:51 +02:00
3682cf6170 Bugfix: sourcing variables file 2014-08-30 21:43:08 +02:00
6255154190 Readme tweak 2014-08-30 17:30:30 +02:00
a6eb17f8fd Fix a link to tpope/vim-obsession 2014-08-30 17:11:14 +02:00
27b9b41e21 Merge pull request #27 from michaelmior/patch-1
Minor README fixes
2014-08-30 16:25:38 +02:00
4d5557d599 Minor README fixes 2014-08-30 10:24:54 -04:00
f5cfa2daa7 Update readme 2014-08-30 14:41:26 +02:00
f2533ec0ef Mention alternative in the readme 2014-08-30 14:40:38 +02:00
5 changed files with 98 additions and 22 deletions

View File

@ -2,6 +2,13 @@
### master
### v1.2.0, 2014-09-01
- new feature: inline strategies when restoring a program
### v1.1.0, 2014-08-31
- bugfix: sourcing `variables.sh` file in save script
- add `Ctrl` key mappings, deprecate `Alt` keys mappings.
### v1.0.0, 2014-08-30
- show spinner during the save process
- add screencast script

View File

@ -2,13 +2,13 @@
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 lose all the
running programs, working directories, pane layouts etc.
There are helpful management tools out there, but they require initial
configuration and continuous updates as your workflow evolves or you start new
projects.
`tmux-resurrect` saves all the little details from tmux environment so it
`tmux-resurrect` saves all the little details from your tmux environment so 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.
@ -20,8 +20,15 @@ It even (optionally) [restores vim sessions](#restoring-vim-sessions)!
### Key bindings
- `prefix + Alt-s` - save
- `prefix + Alt-r` - restore
- `prefix + Ctrl-s` or `prefix + Alt-s` - save
- `prefix + Ctrl-r` or `prefix + Alt-r` - restore
Some people can't get `Alt` key mappings to work so they are deprecated.
For custom key bindings, add to `.tmux.conf`:
set -g @resurrect-save "S"
set -g @resurrect-restore "R"
### About
@ -73,11 +80,11 @@ You should now be able to use the plugin.
### Configuration
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/>
`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`:
@ -91,6 +98,11 @@ Open a github issue if you think some other program should be on the default lis
set -g @resurrect-processes 'irb pry "~rails server" "~rails console"'
- If the wrong command is restored, try specifying inline strategy for the
program with `->`:
set -g @resurrect-processes 'some_program "grunt->grunt development"'
- Don't restore any programs:
set -g @resurrect-processes 'false'
@ -101,7 +113,7 @@ Open a github issue if you think some other program should be on the default lis
#### Restoring vim sessions
- save vim sessions. I recommend [tpope/vim-obsession](tpope/vim-obsession).
- save vim sessions. I recommend [tpope/vim-obsession](https://github.com/tpope/vim-obsession).
- in `.tmux.conf`:
set -g @resurrect-strategy-vim "session"
@ -109,6 +121,15 @@ Open a github issue if you think some other program should be on the default lis
`tmux-resurrect` will now restore vim sessions if `Sessions.vim` file is
present.
### Other goodies
- [tmux-copycat](https://github.com/tmux-plugins/tmux-copycat) - a plugin for
regex searches in tmux and fast match selection
- [tmux-yank](https://github.com/tmux-plugins/tmux-yank) - enables copying
highlighted text to system clipboard
- [tmux-open](https://github.com/tmux-plugins/tmux-open) - a plugin for quickly
opening highlighted file or a url
### Reporting bugs and contributing
Both contributing and bug reports are welcome. Please check out
@ -119,5 +140,12 @@ Both contributing and bug reports are welcome. Please check out
[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).
### Other
Here's another script that tries to solve the same problem:
[link](http://brainscraps.wikia.com/wiki/Resurrecting_tmux_Sessions_After_Reboot).
It even has the same name, even though I discovered it only after publishing
`v1.0` of this plugin.
### License
[MIT](LICENSE.md)

View File

@ -17,7 +17,11 @@ restore_pane_process() {
tmux switch-client -t "${session_name}:${window_number}"
tmux select-pane -t "$pane_index"
if _strategy_exists "$pane_full_command"; then
local inline_strategy="$(_get_inline_strategy "$pane_full_command")" # might not be defined
if [ -n "$inline_strategy" ]; then
# inline strategy exists
tmux send-keys "$inline_strategy" "C-m"
elif _strategy_exists "$pane_full_command"; then
local strategy_file="$(_get_strategy_file "$pane_full_command")"
local strategy_command="$($strategy_file "$pane_full_command" "$dir")"
tmux send-keys "$strategy_command" "C-m"
@ -62,23 +66,42 @@ _process_on_the_restore_list() {
# TODO: make this work without eval
eval set $(_restore_list)
local proc
local match
for proc in "$@"; do
if _proc_starts_with_tildae "$proc"; then
proc="$(remove_first_char "$proc")"
# regex matching the command makes sure `$proc` string is somewhere the command string
if [[ "$pane_full_command" =~ ($proc) ]]; then
return 0
fi
else
# regex matching the command makes sure process is a "word"
if [[ "$pane_full_command" =~ (^${proc} ) ]] || [[ "$pane_full_command" =~ (^${proc}$) ]]; then
return 0
fi
match="$(_get_proc_match_element "$proc")"
if _proc_matches_full_command "$pane_full_command" "$match"; then
return 0
fi
done
return 1
}
_proc_matches_full_command() {
local pane_full_command="$1"
local match="$2"
if _proc_starts_with_tildae "$match"; then
match="$(remove_first_char "$match")"
# regex matching the command makes sure `$match` string is somewhere in the command string
if [[ "$pane_full_command" =~ ($match) ]]; then
return 0
fi
else
# regex matching the command makes sure process is a "word"
if [[ "$pane_full_command" =~ (^${match} ) ]] || [[ "$pane_full_command" =~ (^${match}$) ]]; then
return 0
fi
fi
return 1
}
_get_proc_match_element() {
echo "$1" | sed "s/${inline_strategy_token}.*//"
}
_get_proc_restore_element() {
echo "$1" | sed "s/.*${inline_strategy_token}//"
}
_restore_list() {
local user_processes="$(get_tmux_option "$restore_processes_option" "$restore_processes")"
local default_processes="$(get_tmux_option "$default_proc_list_option" "$default_proc_list")"
@ -94,6 +117,22 @@ _proc_starts_with_tildae() {
[[ "$1" =~ (^~) ]]
}
_get_inline_strategy() {
local pane_full_command="$1"
# TODO: make this work without eval
eval set $(_restore_list)
local proc
local match
for proc in "$@"; do
if [[ "$proc" =~ "$inline_strategy_token" ]]; then
match="$(_get_proc_match_element "$proc")"
if _proc_matches_full_command "$pane_full_command" "$match"; then
echo "$(_get_proc_restore_element "$proc")"
fi
fi
done
}
_strategy_exists() {
local pane_full_command="$1"
local strategy="$(_get_command_strategy "$pane_full_command")"

View File

@ -2,7 +2,7 @@
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$CURRENT_DIR/scripts/variables.sh"
source "$CURRENT_DIR/variables.sh"
source "$CURRENT_DIR/helpers.sh"
source "$CURRENT_DIR/spinner_helpers.sh"

View File

@ -1,8 +1,8 @@
# key bindings
default_save_key="M-s"
default_save_key="M-s C-s"
save_option="@resurrect-save"
default_restore_key="M-r"
default_restore_key="M-r C-r"
restore_option="@resurrect-restore"
# default processes that are restored
@ -21,3 +21,5 @@ restore_processes=""
# Defines part of the user variable. Example usage:
# set -g @resurrect-strategy-vim "session"
restore_process_strategy_option="@resurrect-strategy-"
inline_strategy_token="->"