Compare commits
11 Commits
Author | SHA1 | Date | |
---|---|---|---|
eca38175ff | |||
b8b87a6e29 | |||
8cbc18e130 | |||
cfe8e7979b | |||
093627ce0a | |||
0da279e4cd | |||
884a5e9c19 | |||
8cb5b21e2f | |||
ee1ab0c728 | |||
18f4d1099e | |||
655bdb9a75 |
11
CHANGELOG.md
11
CHANGELOG.md
@ -2,6 +2,17 @@
|
|||||||
|
|
||||||
### master
|
### master
|
||||||
|
|
||||||
|
### v0.2.0, 2014-08-29
|
||||||
|
- bugfix: with vim 'session' strategy, if the session file does not exist - make
|
||||||
|
sure vim does not contain `-S` flag
|
||||||
|
- enable restoring programs with arguments (e.g. "rails console") and also
|
||||||
|
processes that contain program name
|
||||||
|
- improve `irb` restore strategy
|
||||||
|
|
||||||
|
### v0.1.0, 2014-08-28
|
||||||
|
- refactor checking if saved tmux session exists
|
||||||
|
- spinner while tmux sessions are restored
|
||||||
|
|
||||||
### v0.0.5, 2014-08-28
|
### v0.0.5, 2014-08-28
|
||||||
- restore pane processes
|
- restore pane processes
|
||||||
- user option for disabling pane process restoring
|
- user option for disabling pane process restoring
|
||||||
|
12
CONTRIBUTING.md
Normal file
12
CONTRIBUTING.md
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
### Contributing
|
||||||
|
|
||||||
|
Code contributions are welcome!
|
||||||
|
|
||||||
|
### Reporting a bug
|
||||||
|
|
||||||
|
If you find a bug please report it in the issues. When reporting a bug please
|
||||||
|
attach:
|
||||||
|
- a file symlinked to `~/.tmux/sessions/last`.
|
||||||
|
- your `.tmux.conf`
|
||||||
|
- if you're getting an error paste it to a [gist](https://gist.github.com/) and
|
||||||
|
link it in the issue
|
22
README.md
22
README.md
@ -66,13 +66,21 @@ You should now be able to use the plugin.
|
|||||||
|
|
||||||
### Configuration
|
### Configuration
|
||||||
|
|
||||||
By default, only a conservative list of programs is restored:
|
Only a conservative list of programs is restored by default:
|
||||||
`vim emacs man less more tail top htop irssi`.
|
`vi vim emacs man less more tail top htop irssi irb pry "~rails console"`.
|
||||||
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 by putting the following in `.tmux.conf`:
|
- Restore additional programs with the setting in `.tmux.conf`:
|
||||||
|
|
||||||
set -g @session-saver-processes 'ssh telnet myprogram'
|
set -g @session-saver-processes 'ssh psql mysql sqlite3'
|
||||||
|
|
||||||
|
- Programs with arguments should be double quoted:
|
||||||
|
|
||||||
|
set -g @session-saver-processes 'some_program "git log"'
|
||||||
|
|
||||||
|
- Start with tilde to restore a program whose process contains target name:
|
||||||
|
|
||||||
|
set -g @session-saver-processes 'some_program "~rails server"'
|
||||||
|
|
||||||
- Don't restore any programs:
|
- Don't restore any programs:
|
||||||
|
|
||||||
@ -94,10 +102,8 @@ present.
|
|||||||
|
|
||||||
### Reporting bugs and contributing
|
### Reporting bugs and contributing
|
||||||
|
|
||||||
Code contributions are welcome!
|
Both contributing and bug reports are welcome. Please check out
|
||||||
|
[contributing guidelines](CONTRIBUTING.md).
|
||||||
If you find a bug please report it in the issues. When reporting a bug please
|
|
||||||
attach a file symlinked to `~/.tmux/sessions/last`.
|
|
||||||
|
|
||||||
### Credits
|
### Credits
|
||||||
|
|
||||||
|
@ -46,6 +46,10 @@ supported_tmux_version_ok() {
|
|||||||
$CURRENT_DIR/check_tmux_version.sh "$SUPPORTED_VERSION"
|
$CURRENT_DIR/check_tmux_version.sh "$SUPPORTED_VERSION"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
remove_first_char() {
|
||||||
|
echo "$1" | cut -c2-
|
||||||
|
}
|
||||||
|
|
||||||
# path helpers
|
# path helpers
|
||||||
|
|
||||||
sessions_dir() {
|
sessions_dir() {
|
||||||
|
@ -1,20 +1,3 @@
|
|||||||
# default processes that are restored
|
|
||||||
default_proc_list_option="@session-saver-default-processes"
|
|
||||||
default_proc_list="vim emacs man less more tail top htop irssi"
|
|
||||||
|
|
||||||
# User defined processes that are restored
|
|
||||||
# 'false' - nothing is restored
|
|
||||||
# ':all:' - all processes are restored
|
|
||||||
#
|
|
||||||
# user defined list of programs that are restored:
|
|
||||||
# 'my_program foo another_program'
|
|
||||||
restore_processes_option="@session-saver-processes"
|
|
||||||
restore_processes=""
|
|
||||||
|
|
||||||
# Defines part of the user variable. Example usage:
|
|
||||||
# set -g @session-saver-strategy-vim "session"
|
|
||||||
restore_process_strategy_option="@session-saver-strategy-"
|
|
||||||
|
|
||||||
restore_pane_processes_enabled() {
|
restore_pane_processes_enabled() {
|
||||||
local restore_processes="$(get_tmux_option "$restore_processes_option" "$restore_processes")"
|
local restore_processes="$(get_tmux_option "$restore_processes_option" "$restore_processes")"
|
||||||
if [ "$restore_processes" == "false" ]; then
|
if [ "$restore_processes" == "false" ]; then
|
||||||
@ -71,11 +54,21 @@ _restore_all_processes() {
|
|||||||
|
|
||||||
_process_on_the_restore_list() {
|
_process_on_the_restore_list() {
|
||||||
local pane_full_command="$1"
|
local pane_full_command="$1"
|
||||||
local restore_list="$(_restore_list)"
|
# TODO: make this work without eval
|
||||||
|
eval set $(_restore_list)
|
||||||
local proc
|
local proc
|
||||||
for proc in $restore_list; do
|
for proc in "$@"; do
|
||||||
if [[ "$pane_full_command" =~ (^$proc) ]]; then
|
if _proc_starts_with_tildae "$proc"; then
|
||||||
return 0
|
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
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
return 1
|
return 1
|
||||||
@ -92,6 +85,10 @@ _restore_list() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_proc_starts_with_tildae() {
|
||||||
|
[[ "$1" =~ (^~) ]]
|
||||||
|
}
|
||||||
|
|
||||||
_strategy_exists() {
|
_strategy_exists() {
|
||||||
local pane_full_command="$1"
|
local pane_full_command="$1"
|
||||||
local strategy="$(_get_command_strategy "$pane_full_command")"
|
local strategy="$(_get_command_strategy "$pane_full_command")"
|
||||||
|
@ -2,8 +2,10 @@
|
|||||||
|
|
||||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||||
|
|
||||||
|
source "$CURRENT_DIR/variables.sh"
|
||||||
source "$CURRENT_DIR/helpers.sh"
|
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"
|
||||||
|
|
||||||
is_line_type() {
|
is_line_type() {
|
||||||
local line_type="$1"
|
local line_type="$1"
|
||||||
@ -15,8 +17,8 @@ is_line_type() {
|
|||||||
check_saved_session_exists() {
|
check_saved_session_exists() {
|
||||||
local saved_session="$(last_session_path)"
|
local saved_session="$(last_session_path)"
|
||||||
if [ ! -f $saved_session ]; then
|
if [ ! -f $saved_session ]; then
|
||||||
display_message "Saved session not found!"
|
display_message "Saved tmux session not found!"
|
||||||
exit
|
return 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,10 +42,6 @@ tmux_socket() {
|
|||||||
echo $TMUX | cut -d',' -f1
|
echo $TMUX | cut -d',' -f1
|
||||||
}
|
}
|
||||||
|
|
||||||
remove_first_char() {
|
|
||||||
echo "$1" | cut -c2-
|
|
||||||
}
|
|
||||||
|
|
||||||
new_window() {
|
new_window() {
|
||||||
local session_name="$1"
|
local session_name="$1"
|
||||||
local window_number="$2"
|
local window_number="$2"
|
||||||
@ -149,8 +147,8 @@ restore_active_and_alternate_sessions() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
if supported_tmux_version_ok; then
|
if supported_tmux_version_ok && check_saved_session_exists; then
|
||||||
check_saved_session_exists
|
start_spinner
|
||||||
restore_all_sessions
|
restore_all_sessions
|
||||||
restore_all_pane_processes
|
restore_all_pane_processes
|
||||||
restore_pane_layout_for_each_window >/dev/null 2>&1
|
restore_pane_layout_for_each_window >/dev/null 2>&1
|
||||||
@ -158,6 +156,7 @@ main() {
|
|||||||
restore_active_pane_for_each_window
|
restore_active_pane_for_each_window
|
||||||
restore_active_and_alternate_windows
|
restore_active_and_alternate_windows
|
||||||
restore_active_and_alternate_sessions
|
restore_active_and_alternate_sessions
|
||||||
|
stop_spinner
|
||||||
display_message "Restored all Tmux sessions!"
|
display_message "Restored all Tmux sessions!"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
8
scripts/spinner_helpers.sh
Normal file
8
scripts/spinner_helpers.sh
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
start_spinner() {
|
||||||
|
$CURRENT_DIR/tmux_spinner.sh "Restoring sessions..." "Restored all Tmux sessions!" &
|
||||||
|
export SPINNER_PID=$!
|
||||||
|
}
|
||||||
|
|
||||||
|
stop_spinner() {
|
||||||
|
kill $SPINNER_PID
|
||||||
|
}
|
29
scripts/tmux_spinner.sh
Executable file
29
scripts/tmux_spinner.sh
Executable file
@ -0,0 +1,29 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# This script shows tmux spinner with a message. It is intended to be running
|
||||||
|
# as a background process which should be `kill`ed at the end.
|
||||||
|
#
|
||||||
|
# Example usage:
|
||||||
|
#
|
||||||
|
# ./tmux_spinner.sh "Working..." "End message!" &
|
||||||
|
# SPINNER_PID=$!
|
||||||
|
# ..
|
||||||
|
# .. execute commands here
|
||||||
|
# ..
|
||||||
|
# kill $SPINNER_PID # Stops spinner and displays 'End message!'
|
||||||
|
|
||||||
|
MESSAGE="$1"
|
||||||
|
END_MESSAGE="$2"
|
||||||
|
SPIN='-\|/'
|
||||||
|
|
||||||
|
trap "tmux display-message $END_MESSAGE; exit" SIGINT SIGTERM
|
||||||
|
|
||||||
|
main() {
|
||||||
|
local i=0
|
||||||
|
while true; do
|
||||||
|
i=$(( (i+1) %4 ))
|
||||||
|
tmux display-message " ${SPIN:$i:1} $MESSAGE"
|
||||||
|
sleep 0.1
|
||||||
|
done
|
||||||
|
}
|
||||||
|
main
|
23
scripts/variables.sh
Normal file
23
scripts/variables.sh
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
# key bindings
|
||||||
|
default_save_key="M-s"
|
||||||
|
save_option="@session-saver-save"
|
||||||
|
|
||||||
|
default_restore_key="M-r"
|
||||||
|
restore_option="@session-saver-restore"
|
||||||
|
|
||||||
|
# default processes that are restored
|
||||||
|
default_proc_list_option="@session-saver-default-processes"
|
||||||
|
default_proc_list='vi vim emacs man less more tail top htop irssi irb pry "~rails console"'
|
||||||
|
|
||||||
|
# User defined processes that are restored
|
||||||
|
# 'false' - nothing is restored
|
||||||
|
# ':all:' - all processes are restored
|
||||||
|
#
|
||||||
|
# user defined list of programs that are restored:
|
||||||
|
# 'my_program foo another_program'
|
||||||
|
restore_processes_option="@session-saver-processes"
|
||||||
|
restore_processes=""
|
||||||
|
|
||||||
|
# Defines part of the user variable. Example usage:
|
||||||
|
# set -g @session-saver-strategy-vim "session"
|
||||||
|
restore_process_strategy_option="@session-saver-strategy-"
|
@ -2,14 +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/scripts/helpers.sh"
|
source "$CURRENT_DIR/scripts/helpers.sh"
|
||||||
|
|
||||||
default_save_key="M-s"
|
|
||||||
save_option="@session-saver-save"
|
|
||||||
|
|
||||||
default_restore_key="M-r"
|
|
||||||
restore_option="@session-saver-restore"
|
|
||||||
|
|
||||||
set_save_bindings() {
|
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
|
||||||
@ -26,8 +21,13 @@ set_restore_bindings() {
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
set_default_strategies() {
|
||||||
|
tmux set-option -g "${restore_process_strategy_option}irb" "default_strategy"
|
||||||
|
}
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
set_save_bindings
|
set_save_bindings
|
||||||
set_restore_bindings
|
set_restore_bindings
|
||||||
|
set_default_strategies
|
||||||
}
|
}
|
||||||
main
|
main
|
||||||
|
23
strategies/irb_default_strategy.sh
Executable file
23
strategies/irb_default_strategy.sh
Executable file
@ -0,0 +1,23 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# "irb default strategy"
|
||||||
|
#
|
||||||
|
# Example irb process with junk variables:
|
||||||
|
# irb RBENV_VERSION=1.9.3-p429 GREP_COLOR=34;47 TERM_PROGRAM=Apple_Terminal
|
||||||
|
#
|
||||||
|
# When executed, the above will fail. This strategy handles that.
|
||||||
|
|
||||||
|
ORIGINAL_COMMAND="$1"
|
||||||
|
DIRECTORY="$2"
|
||||||
|
|
||||||
|
original_command_wo_junk_vars() {
|
||||||
|
echo "$ORIGINAL_COMMAND" |
|
||||||
|
sed 's/RBENV_VERSION[^ ]*//' |
|
||||||
|
sed 's/GREP_COLOR[^ ]*//' |
|
||||||
|
sed 's/TERM_PROGRAM[^ ]*//'
|
||||||
|
}
|
||||||
|
|
||||||
|
main() {
|
||||||
|
echo "$(original_command_wo_junk_vars)"
|
||||||
|
}
|
||||||
|
main
|
@ -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.
|
# command (withouth the `-S` flag).
|
||||||
|
|
||||||
ORIGINAL_COMMAND="$1"
|
ORIGINAL_COMMAND="$1"
|
||||||
DIRECTORY="$2"
|
DIRECTORY="$2"
|
||||||
@ -13,9 +13,18 @@ vim_session_file_exists() {
|
|||||||
[ -e "${DIRECTORY}/Session.vim" ]
|
[ -e "${DIRECTORY}/Session.vim" ]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
original_command_contains_session_flag() {
|
||||||
|
[[ "$ORIGINAL_COMMAND" =~ "-S" ]]
|
||||||
|
}
|
||||||
|
|
||||||
main() {
|
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
|
||||||
|
# Session file does not exist, yet the orignal vim command contains
|
||||||
|
# session flag `-S`. This will cause an error, so we're falling back to
|
||||||
|
# starting plain vim.
|
||||||
|
echo "vim"
|
||||||
else
|
else
|
||||||
echo "$ORIGINAL_COMMAND"
|
echo "$ORIGINAL_COMMAND"
|
||||||
fi
|
fi
|
||||||
|
Reference in New Issue
Block a user