Restore all pane processes

Close #3
This commit is contained in:
Bruno Sutic 2014-08-27 00:11:13 +02:00
parent 2edd3ff98d
commit cbf58ac613
No known key found for this signature in database
GPG Key ID: 66D96E4F2F7EF26C
4 changed files with 43 additions and 4 deletions

View File

@ -1,6 +1,7 @@
# Changelog
### master
- restore pane processes
### v0.0.4, 2014-08-26
- restore pane layout for each window

View File

@ -2,6 +2,10 @@
Enables saving and restoring of tmux sessions.
Requirements / dependencies:
- `tmux 1.9` or higher
- `pgrep`
### Key bindings
- `prefix + M-s` - save

View File

@ -75,8 +75,9 @@ new_pane() {
restore_pane() {
local pane="$1"
echo "$pane" |
while IFS=$'\t' read line_type session_name window_number window_name window_active window_flags pane_index dir pane_active; do
window_name="$(remove_first_char $window_name)"
while IFS=$'\t' read line_type session_name window_number window_name window_active window_flags pane_index dir pane_active pane_command pane_full_command; do
window_name="$(remove_first_char "$window_name")"
pane_full_command="$(remove_first_char "$pane_full_command")"
if window_exists "$session_name" "$window_number"; then
new_pane "$session_name" "$window_number" "$window_name" "$dir"
elif session_exists "$session_name"; then
@ -104,6 +105,16 @@ restore_all_sessions() {
done < $(last_session_path)
}
restore_all_pane_processes() {
local pane_full_command
awk 'BEGIN { FS="\t"; OFS="\t" } /^pane/ && $11 !~ "^:$" { print $2, $3, $7, $11; }' $(last_session_path) |
while IFS=$'\t' read session_name window_number pane_index pane_full_command; do
pane_full_command="$(remove_first_char "$pane_full_command")"
tmux switch-client -t "${session_name}:${window_number}"
tmux send-keys -t "$pane_index" "$pane_full_command" "C-m"
done
}
restore_pane_layout_for_each_window() {
\grep '^window' $(last_session_path) |
while IFS=$'\t' read line_type session_name window_number window_active window_flags window_layout; do
@ -139,7 +150,9 @@ main() {
if supported_tmux_version_ok; then
check_saved_session_exists
restore_all_sessions
restore_pane_layout_for_each_window
restore_all_pane_processes
restore_pane_layout_for_each_window >/dev/null 2>&1
# below functions restore exact cursor positions
restore_active_pane_for_each_window
restore_active_and_alternate_windows
restore_active_and_alternate_sessions

View File

@ -24,6 +24,10 @@ pane_format() {
format+="#{pane_current_path}"
format+="${delimiter}"
format+="#{pane_active}"
format+="${delimiter}"
format+="#{pane_current_command}"
format+="${delimiter}"
format+="#{pane_pid}"
echo "$format"
}
@ -55,10 +59,27 @@ state_format() {
echo "$format"
}
dump_panes() {
dump_panes_raw() {
tmux list-panes -a -F "$(pane_format)"
}
pane_full_command() {
pane_pid="$1"
\pgrep -lf -P "$pane_pid" |
cut -d' ' -f2-
}
# translates pane pid to process command running inside a pane
dump_panes() {
local full_command
local d=$'\t' # delimiter
dump_panes_raw |
while IFS=$'\t' read line_type session_name window_number window_name window_active window_flags pane_index dir pane_active pane_command pane_pid; do
full_command="$(pane_full_command $pane_pid)"
echo "${line_type}${d}${session_name}${d}${window_number}${d}${window_name}${d}${window_active}${d}${window_flags}${d}${pane_index}${d}${dir}${d}${pane_active}${d}${pane_command}${d}:${full_command}"
done
}
dump_windows() {
tmux list-windows -a -F "$(window_format)"
}