Commit b21e30f8d12feb56ebbe0e0a5849471304bc2607 Parent: 9782d9926f4f394cc331178b6c50ace4585bbc0d Author: Matt Colligan <matt@edra.ai> Date: 2026-02-25 19:49:27 +0000 Committer: Matt Colligan <matt@edra.ai> Committed: 2026-02-25 19:49:27 +0000 more p
git-worktrees.zsh Modified
@@ -1,3 +1,15 @@ +case "${WAYLAND_DISPLAY:+wayland}${DISPLAY:+x11}$OSTYPE" in + wayland*) + _copy='wl-copy' + ;; + x11*) + _copy='xclip -selection clipboard' + ;; + darwin*) + _copy=pbcopy + ;; +esac + # Add a worktree - creates branch from main if it doesn't exist gw() { local input="$1" @@ -8,6 +20,7 @@ local branch="${input##origin/}" local folder="${branch//\//-}" + echo -n "$folder" | $_copy local target="../$folder" # Check if worktree already exists @@ -35,8 +48,28 @@ git worktree add -b "$branch" "$target" main && cd "$target" } +# cd to top-level folder of a worktree if we're inside a subfolder, otherwise cd to main +gw_top_level() { + local root="${HOME}/git/$1" + + # Check if we're inside a subfolder of the repo + if [[ "$PWD" == "$root"/* ]]; then + # Extract path relative to root, then get first component + local relative="${PWD#$root/}" + local subfolder="${relative%%/*}" + cd "$root/$subfolder" + else + cd "$root/main" + fi +} + # Remove a worktree gwr() { + if [[ "$(git rev-parse --is-inside-work-tree)" != "true" ]]; then + echo "Not in a worktree" + return 1 + fi + cd $(git rev-parse --show-toplevel) local target="${1:-$(basename "$PWD")}" if [[ "$target" == "main" ]]; then
aliases Modified
@@ -15,7 +15,6 @@ alias _='sudo' alias p='ps aux | grep -v grep | grep -i' alias import='echo you forgot to enter python' -alias rg='grep -r' alias pth='echo "${PATH//:/\n}"' vgr() { nvim `grep -lri "$@"`; } alias va="source venv/bin/activate" @@ -25,6 +24,7 @@ alias fv="fzf --print0 | xargs -0 -o nvim" alias cat=bat alias vi=vim +alias t="vim ~/tasks.rst" if [[ -n "$WAYLAND_DISPLAY" ]] then @@ -37,7 +37,7 @@ alias copy=pbcopy fi -alias grep='grep --exclude-dir=__pycache__ --exclude-dir=.terraform --exclude-dir=.git --exclude-dir=.venv --exclude-dir=.tox --exclude-dir=tags --exclude-dir=.eggs --exclude-dir=.mypy_cache' +alias grep='grep --exclude-dir=__pycache__ --exclude-dir=.terraform --exclude-dir=.git --exclude-dir=.venv --exclude-dir=.tox --exclude=tags --exclude-dir=.eggs --exclude-dir=.mypy_cache' # systemd alias sc='systemctl' @@ -170,8 +170,26 @@ | column -t -s $'\t' } pshpr() { - psh && gh pr create --fill + psh && gh pr create --fill | tail -n 1 | xargs open } +alias cmx='cm fix' +alias cmxp='cm fix && psh' + +vin() { vim "$@" } +_vin_git_modified() { + local repo_root files file rel + repo_root=$(git rev-parse --show-toplevel 2>/dev/null) || return + files=(${(f)"$(git status --porcelain --untracked-files=no 2>/dev/null | awk '/^ M/{print $2}')"}) + for i in {1..$#files}; do + file="$repo_root/${files[$i]}" + rel=${file:#$PWD/} + files[$i]="${rel#$PWD/}" + done + compadd -U -a files +} +compdef _vin_git_modified vin + + # tools