Skip to content

Commit

Permalink
save/dump_panes: Add override_worktree_path option
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
rbmarliere committed Dec 16, 2024
1 parent cff343c commit 6d8e13f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions scripts/helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ capture_pane_contents_option_on() {
[ "$option" == "on" ]
}

override_worktree_path_option_on() {
local option="$(get_tmux_option "$override_worktree_path" "off")"
[ "$option" == "on" ] && command -v git > /dev/null 2>&1
}

files_differ() {
! cmp -s "$1" "$2"
}
Expand Down
7 changes: 7 additions & 0 deletions scripts/save.sh
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,13 @@ dump_panes() {
continue
fi
full_command="$(pane_full_command $pane_pid)"
if override_worktree_path_option_on; then
git="git -C "${dir/:/}""
git_dir="$($git rev-parse --absolute-git-dir 2>/dev/null)"
if [[ -n $git_dir && $($git rev-parse --is-inside-work-tree) == "true" && $(git -C "$git_dir" rev-parse --is-bare-repository) == "true" ]]; then
dir=":$($git rev-parse --absolute-git-dir | sed 's#/worktrees/.*$##')"
fi
fi
dir=$(echo $dir | sed 's/ /\\ /') # escape all spaces in directory path
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}"
done
Expand Down
2 changes: 2 additions & 0 deletions scripts/variables.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,5 @@ hook_prefix="@resurrect-hook-"

delete_backup_after_option="@resurrect-delete-backup-after"
default_delete_backup_after="30" # days

override_worktree_path="@resurrect-override-worktree-path"

0 comments on commit 6d8e13f

Please sign in to comment.