-
Notifications
You must be signed in to change notification settings - Fork 119
/
Copy pathcapture_pane_helpers.sh
34 lines (31 loc) · 1.06 KB
/
capture_pane_helpers.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# Variables in this helper should be set in the file sourcing the helper.
# Required variables:
# - path_option & default_path
# - name_option & default_name
get_path() {
local path_template=$(get_tmux_option "$path_option" "$default_path")
local check_folder=$(tmux display-message -p "$path_template")
mkdir -p "${check_folder}"
echo "${check_folder}"
}
# `tmux save-buffer` command does not perform interpolation, so we're doing it
# "manually" with `display-message`
get_filename() {
local name_template=$(get_tmux_option "$name_option" "$default_name")
tmux display-message -p "$name_template"
}
capture_pane() {
local file="$(get_path)/$(get_filename)"
local capture_scope=$1
if [ $capture_scope == "History" ]; then
local history_limit="$(tmux display-message -p -F "#{history_limit}")"
tmux capture-pane -J -S "-${history_limit}" -p > "$file"
elif [[ $capture_scope == "Screen capture" ]]; then
tmux capture-pane -J -p > "$file"
else
# error
exit 1
fi
remove_empty_lines_from_end_of_file "$file"
display_message "$capture_scope saved to $file"
}