mirror of
https://github.com/tmux-plugins/tmux-resurrect.git
synced 2024-11-22 04:18:48 +00:00
Save pane contents only if pane not blank
This commit is contained in:
parent
aa0b424ca6
commit
74773bed62
@ -10,6 +10,8 @@
|
|||||||
- bugfix for pane contents restoration
|
- bugfix for pane contents restoration
|
||||||
- expand tilde char `~` if used with `@resurrect-dir`
|
- expand tilde char `~` if used with `@resurrect-dir`
|
||||||
- do not save empty trailing lines when pane content is saved
|
- do not save empty trailing lines when pane content is saved
|
||||||
|
- do not save pane contents if pane is empty (only for 'save pane contents'
|
||||||
|
feature)
|
||||||
|
|
||||||
### v2.4.0, 2015-02-23
|
### v2.4.0, 2015-02-23
|
||||||
- add "tmux-test"
|
- add "tmux-test"
|
||||||
|
@ -92,6 +92,11 @@ pane_contents_file() {
|
|||||||
echo "$(resurrect_dir)/pane_contents-${pane_id}"
|
echo "$(resurrect_dir)/pane_contents-${pane_id}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pane_contents_file_exists() {
|
||||||
|
local pane_id="$1"
|
||||||
|
[ -f "$(pane_contents_file "$pane_id")" ]
|
||||||
|
}
|
||||||
|
|
||||||
resurrect_history_file() {
|
resurrect_history_file() {
|
||||||
local pane_id="$1"
|
local pane_id="$1"
|
||||||
echo "$(resurrect_dir)/bash_history-${pane_id}"
|
echo "$(resurrect_dir)/bash_history-${pane_id}"
|
||||||
|
@ -117,7 +117,8 @@ new_window() {
|
|||||||
local window_name="$3"
|
local window_name="$3"
|
||||||
local dir="$4"
|
local dir="$4"
|
||||||
local pane_index="$5"
|
local pane_index="$5"
|
||||||
if is_restoring_pane_contents; then
|
local pane_id="${session_name}:${window_number}.${pane_index}"
|
||||||
|
if is_restoring_pane_contents && pane_contents_file_exists "$pane_id"; then
|
||||||
local pane_creation_command="$(pane_creation_command "$session_name" "$window_number" "$pane_index")"
|
local pane_creation_command="$(pane_creation_command "$session_name" "$window_number" "$pane_index")"
|
||||||
tmux new-window -d -t "${session_name}:${window_number}" -n "$window_name" -c "$dir" "$pane_creation_command"
|
tmux new-window -d -t "${session_name}:${window_number}" -n "$window_name" -c "$dir" "$pane_creation_command"
|
||||||
else
|
else
|
||||||
@ -131,7 +132,8 @@ new_session() {
|
|||||||
local window_name="$3"
|
local window_name="$3"
|
||||||
local dir="$4"
|
local dir="$4"
|
||||||
local pane_index="$5"
|
local pane_index="$5"
|
||||||
if is_restoring_pane_contents; then
|
local pane_id="${session_name}:${window_number}.${pane_index}"
|
||||||
|
if is_restoring_pane_contents && pane_contents_file_exists "$pane_id"; then
|
||||||
local pane_creation_command="$(pane_creation_command "$session_name" "$window_number" "$pane_index")"
|
local pane_creation_command="$(pane_creation_command "$session_name" "$window_number" "$pane_index")"
|
||||||
TMUX="" tmux -S "$(tmux_socket)" new-session -d -s "$session_name" -n "$window_name" -c "$dir" "$pane_creation_command"
|
TMUX="" tmux -S "$(tmux_socket)" new-session -d -s "$session_name" -n "$window_name" -c "$dir" "$pane_creation_command"
|
||||||
else
|
else
|
||||||
@ -150,7 +152,8 @@ new_pane() {
|
|||||||
local window_name="$3"
|
local window_name="$3"
|
||||||
local dir="$4"
|
local dir="$4"
|
||||||
local pane_index="$5"
|
local pane_index="$5"
|
||||||
if is_restoring_pane_contents; then
|
local pane_id="${session_name}:${window_number}.${pane_index}"
|
||||||
|
if is_restoring_pane_contents && pane_contents_file_exists "$pane_id"; then
|
||||||
local pane_creation_command="$(pane_creation_command "$session_name" "$window_number" "$pane_index")"
|
local pane_creation_command="$(pane_creation_command "$session_name" "$window_number" "$pane_index")"
|
||||||
tmux split-window -t "${session_name}:${window_number}" -c "$dir" "$pane_creation_command"
|
tmux split-window -t "${session_name}:${window_number}" -c "$dir" "$pane_creation_command"
|
||||||
else
|
else
|
||||||
|
@ -110,14 +110,36 @@ pane_full_command() {
|
|||||||
$strategy_file "$pane_pid"
|
$strategy_file "$pane_pid"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
number_nonempty_lines_on_screen() {
|
||||||
|
local pane_id="$1"
|
||||||
|
tmux capture-pane -pJ -t "$pane_id" |
|
||||||
|
sed '/^$/d' |
|
||||||
|
wc -l |
|
||||||
|
sed 's/ //g'
|
||||||
|
}
|
||||||
|
|
||||||
|
# tests if there was any command output in the current pane
|
||||||
|
pane_has_any_content() {
|
||||||
|
local pane_id="$1"
|
||||||
|
local history_size="$(tmux display -p -t "$pane_id" -F "#{history_size}")"
|
||||||
|
local cursor_y="$(tmux display -p -t "$pane_id" -F "#{cursor_y}")"
|
||||||
|
# doing "cheap" tests first
|
||||||
|
[ "$history_size" -gt 0 ] || # history has any content?
|
||||||
|
[ "$cursor_y" -gt 0 ] || # cursor not in first line?
|
||||||
|
[ "$(number_nonempty_lines_on_screen "$pane_id")" -gt 1 ]
|
||||||
|
}
|
||||||
|
|
||||||
capture_pane_contents() {
|
capture_pane_contents() {
|
||||||
local pane_id="$1"
|
local pane_id="$1"
|
||||||
local start_line="-$2"
|
local start_line="-$2"
|
||||||
local pane_contents_area="$3"
|
local pane_contents_area="$3"
|
||||||
|
if pane_has_any_content "$pane_id"; then
|
||||||
if [ "$pane_contents_area" = "visible" ]; then
|
if [ "$pane_contents_area" = "visible" ]; then
|
||||||
start_line="0"
|
start_line="0"
|
||||||
fi
|
fi
|
||||||
|
# the printf hack below removes *trailing* empty lines
|
||||||
printf '%s\n' "$(tmux capture-pane -epJ -S "$start_line" -t "$pane_id")" > "$(pane_contents_file "$pane_id")"
|
printf '%s\n' "$(tmux capture-pane -epJ -S "$start_line" -t "$pane_id")" > "$(pane_contents_file "$pane_id")"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
save_shell_history() {
|
save_shell_history() {
|
||||||
|
Loading…
Reference in New Issue
Block a user