Skip to content

Commit 6d8e13f

Browse files
committed
save/dump_panes: Add override_worktree_path option
Let the user choose to override each pane CWD, if they are git worktrees, with their respective bare repositories paths. Signed-off-by: Ricardo B. Marliere <[email protected]>
1 parent cff343c commit 6d8e13f

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

scripts/helpers.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ capture_pane_contents_option_on() {
6464
[ "$option" == "on" ]
6565
}
6666

67+
override_worktree_path_option_on() {
68+
local option="$(get_tmux_option "$override_worktree_path" "off")"
69+
[ "$option" == "on" ] && command -v git > /dev/null 2>&1
70+
}
71+
6772
files_differ() {
6873
! cmp -s "$1" "$2"
6974
}

scripts/save.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,13 @@ dump_panes() {
195195
continue
196196
fi
197197
full_command="$(pane_full_command $pane_pid)"
198+
if override_worktree_path_option_on; then
199+
git="git -C "${dir/:/}""
200+
git_dir="$($git rev-parse --absolute-git-dir 2>/dev/null)"
201+
if [[ -n $git_dir && $($git rev-parse --is-inside-work-tree) == "true" && $(git -C "$git_dir" rev-parse --is-bare-repository) == "true" ]]; then
202+
dir=":$($git rev-parse --absolute-git-dir | sed 's#/worktrees/.*$##')"
203+
fi
204+
fi
198205
dir=$(echo $dir | sed 's/ /\\ /') # escape all spaces in directory path
199206
echo "${line_type}${d}${session_name}${d}${window_number}${d}${window_active}${d}${window_flags}${d}${pane_index}${d}${pane_title}${d}${dir}${d}${pane_active}${d}${pane_command}${d}:${full_command}"
200207
done

scripts/variables.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,5 @@ hook_prefix="@resurrect-hook-"
4646

4747
delete_backup_after_option="@resurrect-delete-backup-after"
4848
default_delete_backup_after="30" # days
49+
50+
override_worktree_path="@resurrect-override-worktree-path"

0 commit comments

Comments
 (0)