From 1f725a50492a06a7671d8bf9da473708cdf20053 Mon Sep 17 00:00:00 2001 From: jmbeach Date: Sun, 31 Aug 2025 15:24:02 -0700 Subject: [PATCH] Create the default .tmux/resurrect dir if not exists Small change to create the resurrect folder if it doesn't exist. Without this, the resurrect folder might get created in a folder the user doesn't expect. Ex: for me on my mac, the resurrect folder gets created at: `.local/share/tmux/resurrect`, but I thought it would be at `~/.tmux/resurrect` I also got rid of the logic to fallback to `"${XDG_DATA_HOME:-$HOME/.local/share}"/tmux/resurrect` if `default_resurrect_dir` doesn't exist since it would make the logic a little more complicated to implement: ```diff @@ -1,8 +1,4 @@ -if [ -d "$HOME/.tmux/resurrect" ]; then - default_resurrect_dir="$HOME/.tmux/resurrect" -else - default_resurrect_dir="${XDG_DATA_HOME:-$HOME/.local/share}"/tmux/resurrect -fi +default_resurrect_dir="$HOME/.tmux/resurrect" ```` The problem is that the default folder only doesn't exist because it hasn't ever been created. I figure this isn't really an issue though since users can already override the default by setting the `@resurrect-dir` setting. --- scripts/helpers.sh | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/scripts/helpers.sh b/scripts/helpers.sh index 20d87dcd..fa85cb72 100644 --- a/scripts/helpers.sh +++ b/scripts/helpers.sh @@ -1,8 +1,4 @@ -if [ -d "$HOME/.tmux/resurrect" ]; then - default_resurrect_dir="$HOME/.tmux/resurrect" -else - default_resurrect_dir="${XDG_DATA_HOME:-$HOME/.local/share}"/tmux/resurrect -fi +default_resurrect_dir="$HOME/.tmux/resurrect" resurrect_dir_option="@resurrect-dir" SUPPORTED_VERSION="1.9" @@ -98,9 +94,15 @@ pane_content_files_restore_from_archive() { resurrect_dir() { if [ -z "$_RESURRECT_DIR" ]; then - local path="$(get_tmux_option "$resurrect_dir_option" "$default_resurrect_dir")" + local path + path="$(get_tmux_option "$resurrect_dir_option" "$default_resurrect_dir")" # expands tilde, $HOME and $HOSTNAME if used in @resurrect-dir - echo "$path" | sed "s,\$HOME,$HOME,g; s,\$HOSTNAME,$(hostname),g; s,\~,$HOME,g" + local path_expanded + path_expanded=$(echo "$path" | sed "s,\$HOME,$HOME,g; s,\$HOSTNAME,$(hostname),g; s,\~,$HOME,g") + if [ ! -d "$path_expanded" ]; then + mkdir -p "$path_expanded" + fi + echo "$path_expanded" else echo "$_RESURRECT_DIR" fi