Unverified Commit cfe8e797 authored by Bruno Sutic's avatar Bruno Sutic
Browse files

Restoring programs with arguments; improve process matching

Closes #20, closes #19
parent 093627ce
......@@ -2,7 +2,9 @@
### master
- bugfix: with vim 'session' strategy, if the session file does not exist - make
sure wim does not contain `-S` flag
sure vim does not contain `-S` flag
- enable restoring programs with arguments (e.g. "rails console") and also
processes that contain program name
### v0.1.0, 2014-08-28
- refactor checking if saved tmux session exists
......
......@@ -67,13 +67,21 @@ You should now be able to use the plugin.
### Configuration
Only a conservative list of programs is restored by default:
`vi vim emacs man less more tail top htop irssi irb pry`.
`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.
- 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 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:
set -g @session-saver-processes 'false'
......
......@@ -46,6 +46,10 @@ supported_tmux_version_ok() {
$CURRENT_DIR/check_tmux_version.sh "$SUPPORTED_VERSION"
}
remove_first_char() {
echo "$1" | cut -c2-
}
# path helpers
sessions_dir() {
......
# 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"
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
......@@ -71,12 +71,21 @@ _restore_all_processes() {
_process_on_the_restore_list() {
local pane_full_command="$1"
local restore_list="$(_restore_list)"
# TODO: make this work without eval
eval set $(_restore_list)
local proc
for proc in $restore_list; do
# regex matching the command makes sure process is a "word"
if [[ "$pane_full_command" =~ (^${proc} ) ]] || [[ "$pane_full_command" =~ (^${proc}$) ]]; then
return 0
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
fi
done
return 1
......@@ -93,6 +102,10 @@ _restore_list() {
fi
}
_proc_starts_with_tildae() {
[[ "$1" =~ (^~) ]]
}
_strategy_exists() {
local pane_full_command="$1"
local strategy="$(_get_command_strategy "$pane_full_command")"
......
......@@ -41,10 +41,6 @@ tmux_socket() {
echo $TMUX | cut -d',' -f1
}
remove_first_char() {
echo "$1" | cut -c2-
}
new_window() {
local session_name="$1"
local window_number="$2"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment