My zsh configuration
git clone https://github.com/m-col/zshrc
Files | Refs | Readme

Commit 9782d9926f4f394cc331178b6c50ace4585bbc0d
Parent: e9fbfb6eaaaaedb227840f772b4121401618efa0
Author: Matt Colligan <matt@edra.ai>
Date: 2025-12-06 11:44:28 +0000
Committer: Matt Colligan <matt@edra.ai>
Committed: 2025-12-06 11:44:28 +0000

git stuff

git-worktrees.zsh Added

@@ -0,0 +1,85 @@
+# Add a worktree - creates branch from main if it doesn't exist
+gw() {
+    local input="$1"
+    if [[ -z "$input" ]]; then
+	git worktree list
+        return 1
+    fi
+
+    local branch="${input##origin/}"
+    local folder="${branch//\//-}"
+    local target="../$folder"
+
+    # Check if worktree already exists
+    if [[ -d "$target" ]]; then
+        cd "$target"
+        return
+    fi
+    
+    # Check if branch exists locally
+    if git show-ref --verify --quiet "refs/heads/$branch"; then
+        git worktree add "$target" "$branch" && cd "$target"
+        return
+    fi
+    
+    # Try fetching from remote
+    if git fetch origin "$branch" 2>/dev/null && \
+       git worktree add "$target" "$branch" 2>/dev/null; then
+        cd "$target"
+        return
+    fi
+    
+    # Branch doesn't exist - create from main
+    echo "Branch '$branch' not found, creating from main..."
+    git fetch origin main:main 2>/dev/null || git fetch origin main
+    git worktree add -b "$branch" "$target" main && cd "$target"
+}
+
+# Remove a worktree
+gwr() {
+    local target="${1:-$(basename "$PWD")}"
+
+    if [[ "$target" == "main" ]]; then
+        echo "Refusing to remove main worktree"
+        return 1
+    fi
+
+    local branch
+    if [[ -z "$1" ]]; then
+        # Current directory - get branch before leaving
+        branch=$(git branch --show-current)
+        cd ../main && git worktree remove "../$target" && git branch -D "$branch"
+    else
+        # Named worktree - get its branch first
+        branch=$(git -C "../$target" branch --show-current 2>/dev/null)
+        git worktree remove "../$target" && [[ -n "$branch" ]] && git branch -D "$branch"
+    fi
+    git worktree list
+}
+
+# Interactive branch selection with fzf
+gwf() {
+    local branch=$(git branch -a --sort=-committerdate | \
+        grep -v HEAD | \
+        sed 's/^[* ]*//' | \
+        sed 's#remotes/origin/##' | \
+        awk '!seen[$0]++' | \
+        fzf --height 40% --reverse --preview 'git log --oneline -10 {}')
+    [[ -n "$branch" ]] && gwt "$branch"
+}
+
+# Completions
+_gw_branches() {
+    local branches
+    branches=(${(f)"$(git branch 2>/dev/null | sed 's/^[* ]*//' | sed 's/^[+ ]*//')"})
+    _describe 'branch' branches
+}
+
+_gwr_worktrees() {
+    local worktrees
+    worktrees=(${(f)"$(git worktree list --porcelain 2>/dev/null | grep '^worktree' | awk '{print $2}' | xargs -n1 basename)"})
+    _describe 'worktree' worktrees
+}
+
+compdef _gw_branches gw
+compdef _gwr_worktrees gwr

aliases Modified

@@ -37,7 +37,7 @@
     alias copy=pbcopy
 fi
 
-alias grep='grep --exclude-dir=__pycache__ --exclude-dir=.terraform --exclude-dir=.git --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-dir=tags --exclude-dir=.eggs --exclude-dir=.mypy_cache'
 
 # systemd
 alias sc='systemctl'
@@ -74,6 +74,7 @@
 alias ta='tmux attach'
 
 # git
+alias g='gita'
 alias gs='git status'
 alias ad='git add'
 alias adp='git add --patch'
@@ -116,28 +117,40 @@
 lg() { git log -${1:-1}; }
 lgo()  { git log --oneline -${1:-1}; }
 alias lgc="git log -1 | head -1 | awk '{print \$2}' | copy -n"
-newbr() {
-    branches=$(br | wc -l)
-    if (( branches != 2 ))
-    then
-	echo "$branches branches, can't continue"
-	return 0
-    fi
-    new_name="$1"
-    if [[ -z "$new_name" ]]
-    then
-	echo "no name given, pass in a name"
-	return 0
-    fi
-    ch main
-    br -D $(git branch --format='%(refname:short)' | grep -v main)
-    pl
-    ch -b matt/$new_name
-    echo
-    br
-    echo
-    gs
-}
+#newbr() {
+#    branches=$(br | wc -l)
+#    if (( branches != 2 ))
+#    then
+#	echo "$branches branches, can't continue"
+#	return 0
+#    fi
+#    new_name="$1"
+#    if [[ -z "$new_name" ]]
+#    then
+#	echo "no name given, pass in a name"
+#	return 0
+#    fi
+#    ch main
+#    br -D $(git branch --format='%(refname:short)' | grep -v main)
+#    pl
+#    ch -b matt/$new_name
+#    echo
+#    br
+#    echo
+#    gs
+#}
+#nobr() {
+#    branches=$(br | wc -l)
+#    if (( branches == 1 ))
+#    then
+#	return 0
+#    fi
+#    ch main
+#    br -D $(git branch --format='%(refname:short)' | grep -v main)
+#    pl
+#    gs
+#}
+
 
 pdif() {
     git diff --name-only --diff-filter=${1:-M}
@@ -156,6 +169,10 @@
       --jq '.[] | [.repository.name, "#\(.number)", .title, .url] | @tsv') \
       | column -t -s $'\t'
 }
+pshpr() {
+    psh && gh pr create --fill
+}
+
 
 # tools
 alias usync='rsync -avPzh --delete'