Memoize return of resurrect path functions

This commit is contained in:
Bruno Sutic 2017-06-01 17:03:39 +02:00
parent b7a4ee2a40
commit eef844c747
No known key found for this signature in database
GPG Key ID: CAFA7B1B2914ED81

View File

@ -2,6 +2,8 @@ default_resurrect_dir="$HOME/.tmux/resurrect"
resurrect_dir_option="@resurrect-dir" resurrect_dir_option="@resurrect-dir"
SUPPORTED_VERSION="1.9" SUPPORTED_VERSION="1.9"
_RESURRECT_DIR=""
_RESURRECT_FILE_PATH=""
d=$'\t' d=$'\t'
@ -94,13 +96,21 @@ pane_content_files_restore_from_archive() {
# path helpers # path helpers
resurrect_dir() { resurrect_dir() {
if [ -z "$_RESURRECT_DIR" ]; then
local path="$(get_tmux_option "$resurrect_dir_option" "$default_resurrect_dir")" local path="$(get_tmux_option "$resurrect_dir_option" "$default_resurrect_dir")"
echo "${path/#\~/$HOME}" # expands tilde if used with @resurrect-dir echo "${path/#\~/$HOME}" # expands tilde if used with @resurrect-dir
else
echo "$_RESURRECT_DIR"
fi
} }
resurrect_file_path() { resurrect_file_path() {
if [ -z "$_RESURRECT_FILE_PATH" ]; then
local timestamp="$(date +"%Y-%m-%dT%H:%M:%S")" local timestamp="$(date +"%Y-%m-%dT%H:%M:%S")"
echo "$(resurrect_dir)/tmux_resurrect_${timestamp}.txt" echo "$(resurrect_dir)/tmux_resurrect_${timestamp}.txt"
else
echo "$_RESURRECT_FILE_PATH"
fi
} }
last_resurrect_file() { last_resurrect_file() {