mirror of
https://github.com/tmux-plugins/tmux-resurrect.git
synced 2024-11-22 04:18:48 +00:00
Enable selectively restoring processes
- user can restore all processes with ':all:' - user can selectively restore wanted processes Closes #13
This commit is contained in:
parent
7f50660918
commit
1e945c2cac
@ -3,6 +3,7 @@
|
|||||||
### master
|
### master
|
||||||
- restore pane processes
|
- restore pane processes
|
||||||
- user option for disabling pane process restoring
|
- user option for disabling pane process restoring
|
||||||
|
- enable whitelisting processes that will be restored
|
||||||
|
|
||||||
### v0.0.4, 2014-08-26
|
### v0.0.4, 2014-08-26
|
||||||
- restore pane layout for each window
|
- restore pane layout for each window
|
||||||
|
@ -2,9 +2,6 @@
|
|||||||
default_sessions_dir="$HOME/.tmux/sessions"
|
default_sessions_dir="$HOME/.tmux/sessions"
|
||||||
sessions_dir_option="@session-saver-dir"
|
sessions_dir_option="@session-saver-dir"
|
||||||
|
|
||||||
restore_processes_option="@session-saver-restore-processes"
|
|
||||||
default_restore_processes="true"
|
|
||||||
|
|
||||||
SUPPORTED_VERSION="1.9"
|
SUPPORTED_VERSION="1.9"
|
||||||
|
|
||||||
# helper functions
|
# helper functions
|
||||||
|
76
scripts/process_restore_helpers.sh
Normal file
76
scripts/process_restore_helpers.sh
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
# 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=""
|
||||||
|
|
||||||
|
restore_pane_processes_enabled() {
|
||||||
|
local restore_processes="$(get_tmux_option "$restore_processes_option" "$restore_processes")"
|
||||||
|
if [ $restore_processes == "false" ]; then
|
||||||
|
return 1
|
||||||
|
else
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
restore_pane_process() {
|
||||||
|
local pane_full_command="$1"
|
||||||
|
local session_name="$2"
|
||||||
|
local window_number="$3"
|
||||||
|
local pane_index="$4"
|
||||||
|
if _process_should_be_restored "$pane_full_command"; then
|
||||||
|
tmux switch-client -t "${session_name}:${window_number}"
|
||||||
|
tmux select-pane -t "$pane_index"
|
||||||
|
tmux send-keys "$pane_full_command" "C-m"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
_process_should_be_restored() {
|
||||||
|
local pane_full_command="$1"
|
||||||
|
if _restore_all_processes; then
|
||||||
|
return 0
|
||||||
|
elif _process_on_the_restore_list "$pane_full_command"; then
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
_restore_all_processes() {
|
||||||
|
local restore_processes="$(get_tmux_option "$restore_processes_option" "$restore_processes")"
|
||||||
|
if [ $restore_processes == ":all:" ]; then
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
_process_on_the_restore_list() {
|
||||||
|
local pane_full_command="$1"
|
||||||
|
local restore_list="$(_restore_list)"
|
||||||
|
local proc
|
||||||
|
for proc in $restore_list; do
|
||||||
|
if [[ "$pane_full_command" =~ (^$proc) ]]; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
_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")"
|
||||||
|
if [ -z $user_processes ]; then
|
||||||
|
# user didn't define any processes
|
||||||
|
echo "$default_processes"
|
||||||
|
else
|
||||||
|
echo "$default_processes $user_processes"
|
||||||
|
fi
|
||||||
|
}
|
@ -3,6 +3,7 @@
|
|||||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||||
|
|
||||||
source "$CURRENT_DIR/helpers.sh"
|
source "$CURRENT_DIR/helpers.sh"
|
||||||
|
source "$CURRENT_DIR/process_restore_helpers.sh"
|
||||||
|
|
||||||
is_line_type() {
|
is_line_type() {
|
||||||
local line_type="$1"
|
local line_type="$1"
|
||||||
@ -105,24 +106,6 @@ restore_all_sessions() {
|
|||||||
done < $(last_session_path)
|
done < $(last_session_path)
|
||||||
}
|
}
|
||||||
|
|
||||||
restore_pane_processes_enabled() {
|
|
||||||
local restore_processes="$(get_tmux_option "$restore_processes_option" "$default_restore_processes")"
|
|
||||||
if [ $restore_processes == "false" ]; then
|
|
||||||
return 1
|
|
||||||
else
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
restore_pane_process() {
|
|
||||||
local pane_full_command="$1"
|
|
||||||
local session_name="$2"
|
|
||||||
local window_number="$3"
|
|
||||||
local pane_index="$4"
|
|
||||||
tmux switch-client -t "${session_name}:${window_number}"
|
|
||||||
tmux send-keys -t "$pane_index" "$pane_full_command" "C-m"
|
|
||||||
}
|
|
||||||
|
|
||||||
restore_all_pane_processes() {
|
restore_all_pane_processes() {
|
||||||
if restore_pane_processes_enabled; then
|
if restore_pane_processes_enabled; then
|
||||||
local pane_full_command
|
local pane_full_command
|
||||||
|
Loading…
Reference in New Issue
Block a user