Skip to content

Commit 2f18702

Browse files
committed
feat(git): add cdwt, change worktrees with fzf
1 parent 5ac6419 commit 2f18702

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

functions/git.functions.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,21 @@ gswpr() {
3535
git switch "$1"
3636
}
3737

38+
# Navigate between git worktrees with fzf, ordered by last commit date
39+
cdwt() {
40+
local worktree_info last_commit_date
41+
42+
worktree_info=$(git worktree list --porcelain | grep "worktree " | awk '{print $2}' | while read -r wt; do
43+
last_commit_date=$(cd "$wt" && git log -1 --format="%ct")
44+
echo "$last_commit_date $wt"
45+
done | sort -nr | awk '{print $2}' | fzf --height 40% --prompt="Select Worktree > ")
46+
47+
if [ -n "$worktree_info" ]; then
48+
cd "$worktree_info" || return 1
49+
fi
50+
}
51+
52+
3853
# Show previously used conventional commit scopes
3954
# Optional -n flag to sort numerically
4055
gscopes() {

0 commit comments

Comments
 (0)