Compare commits

..

2 Commits

4 changed files with 55 additions and 1 deletions

2
.local/bin/git-cln Executable file
View File

@ -0,0 +1,2 @@
#!/usr/bin/env bash
sh ~/.local/bin/git-worktree-setup.sh "$@"

View File

@ -0,0 +1,21 @@
#!/usr/bin/env bash
set -e
url=$1
basename=${url##*/}
name=${2:-${basename%.*}}
mkdir -p "$name"
cd "$name"
git clone --bare "$url" .bare
echo "gitdir: ./.bare" > .git
git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
git fetch origin
default_branch=$(git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@')
git worktree add "$default_branch"
osascript -e "tell application \"Terminal\" to do script \"cd '$PWD/$default_branch' && clear\" in front window"

30
.zshrc
View File

@ -133,6 +133,36 @@ alias rm=trash
alias gst="git status"
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 fuck="init_thefuck"
alias nvm="fnm"

View File

@ -8,7 +8,8 @@
"editor.fontWeight": "normal",
"window.titleBarStyle": "native",
"window.commandCenter": false,
"window.nativeTabs": true,
"window.nativeTabs": false,
"workbench.editor.showTabs": "single",
"workbench.editor.showIcons": false,
"workbench.layoutControl.enabled": false,
"workbench.colorTheme": "MacOS Modern Light - Ventura Xcode Default",