Restoring programs with arguments; improve process matching

Closes #20, closes #19
This commit is contained in:
Bruno Sutic 2014-08-28 23:39:53 +02:00
parent 093627ce0a
commit cfe8e7979b
No known key found for this signature in database
GPG Key ID: 66D96E4F2F7EF26C
5 changed files with 36 additions and 13 deletions

View File

@ -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

View File

@ -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'

View File

@ -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() {

View File

@ -1,6 +1,6 @@
# 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,13 +71,22 @@ _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
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")"

View File

@ -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"