add wt - alias to switch between git worktrees
This commit is contained in:
parent
6faed4df92
commit
93108710e4
30
.zshrc
30
.zshrc
@ -133,6 +133,36 @@ alias rm=trash
|
|||||||
|
|
||||||
alias gst="git status"
|
alias gst="git status"
|
||||||
alias gwt="git worktree"
|
alias gwt="git worktree"
|
||||||
|
|
||||||
|
do_cd_worktree() {
|
||||||
|
# Must be in a git repo
|
||||||
|
if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
|
||||||
|
echo "Not in a git repository"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Get worktree root (handles being in subdirectory of worktree)
|
||||||
|
local wt_root=$(git rev-parse --show-toplevel 2>/dev/null)
|
||||||
|
local project_root=$(dirname "$wt_root")
|
||||||
|
|
||||||
|
# If we're in the bare repo root, project_root is parent
|
||||||
|
if [[ -d "$wt_root/.bare" ]]; then
|
||||||
|
project_root="$wt_root"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Get worktree directories (exclude bare repo)
|
||||||
|
local selected=$(git worktree list --porcelain | \
|
||||||
|
grep '^worktree ' | \
|
||||||
|
cut -d' ' -f2- | \
|
||||||
|
grep -v '\.bare$' | \
|
||||||
|
xargs -I{} basename {} | \
|
||||||
|
fzf --height 10% --color=light,hl:196,hl+:196)
|
||||||
|
|
||||||
|
if [[ -n "$selected" ]]; then
|
||||||
|
cd "${project_root}/${selected}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
alias wt="do_cd_worktree"
|
||||||
alias gdf="gdifftool"
|
alias gdf="gdifftool"
|
||||||
alias fuck="init_thefuck"
|
alias fuck="init_thefuck"
|
||||||
alias nvm="fnm"
|
alias nvm="fnm"
|
||||||
|
|||||||
@ -8,7 +8,8 @@
|
|||||||
"editor.fontWeight": "normal",
|
"editor.fontWeight": "normal",
|
||||||
"window.titleBarStyle": "native",
|
"window.titleBarStyle": "native",
|
||||||
"window.commandCenter": false,
|
"window.commandCenter": false,
|
||||||
"window.nativeTabs": true,
|
"window.nativeTabs": false,
|
||||||
|
"workbench.editor.showTabs": "single",
|
||||||
"workbench.editor.showIcons": false,
|
"workbench.editor.showIcons": false,
|
||||||
"workbench.layoutControl.enabled": false,
|
"workbench.layoutControl.enabled": false,
|
||||||
"workbench.colorTheme": "MacOS Modern Light - Ventura Xcode Default",
|
"workbench.colorTheme": "MacOS Modern Light - Ventura Xcode Default",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user