Unverified Commit 74773bed authored by Bruno Sutic's avatar Bruno Sutic
Browse files

Save pane contents only if pane not blank

parent aa0b424c
......@@ -10,6 +10,8 @@
- bugfix for pane contents restoration
- expand tilde char `~` if used with `@resurrect-dir`
- 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
- add "tmux-test"
......
......@@ -92,6 +92,11 @@ pane_contents_file() {
echo "$(resurrect_dir)/pane_contents-${pane_id}"
}
pane_contents_file_exists() {
local pane_id="$1"
[ -f "$(pane_contents_file "$pane_id")" ]
}
resurrect_history_file() {
local pane_id="$1"
echo "$(resurrect_dir)/bash_history-${pane_id}"
......
......@@ -117,7 +117,8 @@ new_window() {
local window_name="$3"
local dir="$4"
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")"
tmux new-window -d -t "${session_name}:${window_number}" -n "$window_name" -c "$dir" "$pane_creation_command"
else
......@@ -131,7 +132,8 @@ new_session() {
local window_name="$3"
local dir="$4"
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")"
TMUX="" tmux -S "$(tmux_socket)" new-session -d -s "$session_name" -n "$window_name" -c "$dir" "$pane_creation_command"
else
......@@ -150,7 +152,8 @@ new_pane() {
local window_name="$3"
local dir="$4"
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")"
tmux split-window -t "${session_name}:${window_number}" -c "$dir" "$pane_creation_command"
else
......
......@@ -110,14 +110,36 @@ pane_full_command() {
$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() {
local pane_id="$1"
local start_line="-$2"
local pane_contents_area="$3"
if [ "$pane_contents_area" = "visible" ]; then
start_line="0"
if pane_has_any_content "$pane_id"; then
if [ "$pane_contents_area" = "visible" ]; then
start_line="0"
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")"
fi
printf '%s\n' "$(tmux capture-pane -epJ -S "$start_line" -t "$pane_id")" > "$(pane_contents_file "$pane_id")"
}
save_shell_history() {
......
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