Skip to content

Instantly share code, notes, and snippets.

@caherrerapa
Created October 11, 2025 09:18
Show Gist options
  • Save caherrerapa/0ab118b2fd63b0d1cc5c7499448d747e to your computer and use it in GitHub Desktop.
Save caherrerapa/0ab118b2fd63b0d1cc5c7499448d747e to your computer and use it in GitHub Desktop.
.zshrc
export ZSH="$HOME/.oh-my-zsh"
# Set name of the theme to load --- if set to "random", it will
# load a random theme each time Oh My Zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes
ZSH_THEME="robbyrussell"
# Set list of themes to pick from when loading at random
# Setting this variable when ZSH_THEME=random will cause zsh to load
# a theme from this variable instead of looking in $ZSH/themes/
# If set to an empty array, this variable will have no effect.
# ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" )
# Uncomment the following line to use case-sensitive completion.
# CASE_SENSITIVE="true"
# Uncomment the following line to use hyphen-insensitive completion.
# Case-sensitive completion must be off. _ and - will be interchangeable.
# HYPHEN_INSENSITIVE="true"
# Uncomment one of the following lines to change the auto-update behavior
# zstyle ':omz:update' mode disabled # disable automatic updates
# zstyle ':omz:update' mode auto # update automatically without asking
# zstyle ':omz:update' mode reminder # just remind me to update when it's time
# Uncomment the following line to change how often to auto-update (in days).
# zstyle ':omz:update' frequency 13
# Uncomment the following line if pasting URLs and other text is messed up.
# DISABLE_MAGIC_FUNCTIONS="true"
# Uncomment the following line to disable colors in ls.
# DISABLE_LS_COLORS="true"
# Uncomment the following line to disable auto-setting terminal title.
# DISABLE_AUTO_TITLE="true"
# Uncomment the following line to enable command auto-correction.
# ENABLE_CORRECTION="true"
# Uncomment the following line to display red dots whilst waiting for completion.
# You can also set it to another string to have that shown instead of the default red dots.
# e.g. COMPLETION_WAITING_DOTS="%F{yellow}waiting...%f"
# Caution: this setting can cause issues with multiline prompts in zsh < 5.7.1 (see #5765)
# COMPLETION_WAITING_DOTS="true"
# Uncomment the following line if you want to disable marking untracked files
# under VCS as dirty. This makes repository status check for large repositories
# much, much faster.
# DISABLE_UNTRACKED_FILES_DIRTY="true"
# Uncomment the following line if you want to change the command execution time
# stamp shown in the history command output.
# You can set one of the optional three formats:
# "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
# or set a custom format using the strftime function format specifications,
# see 'man strftime' for details.
# HIST_STAMPS="mm/dd/yyyy"
# Would you like to use another custom folder than $ZSH/custom?
# ZSH_CUSTOM=/path/to/new-custom-folder
# Which plugins would you like to load?
# Standard plugins can be found in $ZSH/plugins/
# Custom plugins may be added to $ZSH_CUSTOM/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(git)
source $ZSH/oh-my-zsh.sh
# User configuration
# export MANPATH="/usr/local/man:$MANPATH"
# You may need to manually set your language environment
# export LANG=en_US.UTF-8
# Preferred editor for local and remote sessions
# if [[ -n $SSH_CONNECTION ]]; then
# export EDITOR='vim'
# else
# export EDITOR='mvim'
# fi
# Compilation flags
# export ARCHFLAGS="-arch x86_64"
# Set personal aliases, overriding those provided by Oh My Zsh libs,
# plugins, and themes. Aliases can be placed here, though Oh My Zsh
# users are encouraged to define aliases within a top-level file in
# the $ZSH_CUSTOM folder, with .zsh extension. Examples:
# - $ZSH_CUSTOM/aliases.zsh
# - $ZSH_CUSTOM/macos.zsh
# For a full list of active aliases, run `alias`.
#
# Example aliases
# alias zshconfig="mate ~/.zshrc"
# alias ohmyzsh="mate ~/.oh-my-zsh"
# ============================================
# PATH Configuration
# ============================================
. /opt/homebrew/opt/asdf/libexec/asdf.sh
export WASMTIME_HOME="$HOME/.wasmtime"
export PATH="$WASMTIME_HOME/bin:$PATH"
export PATH="/opt/homebrew/opt/openjdk/bin:$PATH"
# ============================================
# Git Worktree Configuration Variables
# ============================================
# Set your default base branch here
export GWT_DEFAULT_BRANCH="develop"
# Set your PR template file path (relative to repo root)
export GWT_PR_TEMPLATE=".github/PULL_REQUEST_TEMPLATE.md"
# ============================================
# Aliases
# ============================================
# --- Git Rebase Aliases ---
alias grem="gco main && git pull && git checkout - && git rebase main"
alias gred="gco develop && git pull && git checkout - && git rebase develop"
alias grc="git rebase --continue"
alias gra="git rebase --abort"
alias gpf="git push --force"
# --- General Git Aliases ---
alias gs='git status'
alias ga='git add'
alias gaa='git add .'
alias gc='git commit'
alias gcm='git commit -m'
alias gp='git push'
alias gpl='git pull'
alias gb='git branch'
alias gba='git branch -a'
alias gco='git checkout'
alias gd='git diff'
alias gl='git log --oneline --graph --decorate'
alias gf='git fetch'
# --- Git Worktree Aliases ---
alias gwl='git worktree list'
alias gwx='git worktree prune'
alias gwm='cd $(git rev-parse --show-toplevel)'
# ============================================
# Functions
# ============================================
# --- Git Worktree Functions ---
function gwt() {
local branch_name="$1"
# If no argument provided, use current branch
if [ -z "$branch_name" ]; then
branch_name=$(git branch --show-current)
if [ -z "$branch_name" ]; then
echo "Not currently on any branch and no branch name provided"
echo "Usage: gwt [branch-name]"
return 1
fi
echo "Creating worktree from current branch: $branch_name"
fi
local repo_root=$(git rev-parse --show-toplevel)
local repo_name=$(basename "$repo_root")
local worktree_dir="$repo_root/../$repo_name-worktrees"
if [ ! -d "$worktree_dir" ]; then
mkdir -p "$worktree_dir"
echo "Created $worktree_dir directory"
fi
# Check if branch exists locally
if ! git show-ref --verify --quiet refs/heads/$branch_name; then
echo "Branch '$branch_name' not found locally"
# Try to fetch from remote
echo "Attempting to fetch from origin..."
if git fetch origin "$branch_name:$branch_name" 2>/dev/null; then
echo "Successfully fetched '$branch_name' from origin"
git worktree add "$worktree_dir/$branch_name" "$branch_name"
else
echo "Branch not found on remote either"
echo "Creating new local branch '$branch_name' from $GWT_DEFAULT_BRANCH"
git worktree add -b "$branch_name" "$worktree_dir/$branch_name" "$GWT_DEFAULT_BRANCH"
fi
else
# Branch exists locally
git worktree add "$worktree_dir/$branch_name" "$branch_name"
fi
cd "$worktree_dir/$branch_name"
}
function gwn() {
if [ -z "$1" ]; then
echo "Usage: gwn <new-branch-name> [base-branch]"
echo "Default base branch: $GWT_DEFAULT_BRANCH"
return 1
fi
local branch_name="$1"
local base_branch="${2:-$GWT_DEFAULT_BRANCH}"
local repo_root=$(git rev-parse --show-toplevel)
local repo_name=$(basename "$repo_root")
local worktree_dir="$repo_root/../$repo_name-worktrees"
if [ ! -d "$worktree_dir" ]; then
mkdir -p "$worktree_dir"
fi
git worktree add -b "$branch_name" "$worktree_dir/$branch_name" "$base_branch"
cd "$worktree_dir/$branch_name"
}
function gwp() {
if [ -z "$1" ]; then
echo "Usage: gwp <PR-number> [remote-name]"
echo "Example: gwp 123"
echo "Example: gwp 456 upstream"
return 1
fi
local pr_number="$1"
local remote="${2:-origin}"
local branch_name="pr-$pr_number"
local repo_root=$(git rev-parse --show-toplevel)
local repo_name=$(basename "$repo_root")
local worktree_dir="$repo_root/../$repo_name-worktrees"
if [ ! -d "$worktree_dir" ]; then
mkdir -p "$worktree_dir"
fi
echo "Fetching PR #$pr_number from $remote..."
git fetch "$remote" "pull/$pr_number/head:$branch_name"
if [ $? -eq 0 ]; then
echo "Creating worktree for PR #$pr_number..."
git worktree add "$worktree_dir/$branch_name" "$branch_name"
cd "$worktree_dir/$branch_name"
echo "Successfully checked out PR #$pr_number"
else
echo "Failed to fetch PR #$pr_number"
return 1
fi
}
function gwr() {
if [ -z "$1" ]; then
echo "Usage: gwr <branch-name>"
return 1
fi
local branch_name="$1"
local repo_root=$(git rev-parse --show-toplevel)
local repo_name=$(basename "$repo_root")
local worktree_dir="$repo_root/../$repo_name-worktrees"
git worktree remove "$worktree_dir/$branch_name"
}
function gwd() {
if [ -z "$1" ]; then
echo "Usage: gwd <branch-name>"
return 1
fi
local branch_name="$1"
local repo_root=$(git rev-parse --show-toplevel)
local repo_name=$(basename "$repo_root")
local worktree_dir="$repo_root/../$repo_name-worktrees"
echo "Removing worktree..."
git worktree remove "$worktree_dir/$branch_name"
echo "Deleting branch $branch_name..."
git branch -D "$branch_name"
echo "Worktree and branch removed"
}
function gws() {
echo "=== Current Worktrees ==="
git worktree list
echo ""
echo "=== Current Branch ==="
git branch --show-current
}
function gwc() {
echo "This will remove all worktrees. Are you sure? (y/n)"
read -r response
if [[ "$response" =~ ^[Yy]$ ]]; then
local repo_root=$(git rev-parse --show-toplevel 2>/dev/null)
if [ -z "$repo_root" ]; then
echo "Not in a git repository"
return 1
fi
local repo_name=$(basename "$repo_root")
local worktree_dir="$repo_root/../$repo_name-worktrees"
if [ -d "$worktree_dir" ]; then
cd "$repo_root"
for dir in "$worktree_dir"/*; do
if [ -d "$dir" ]; then
local branch=$(basename "$dir")
echo "Removing $branch..."
git worktree remove "$worktree_dir/$branch" 2>/dev/null || true
fi
done
git worktree prune
echo "All worktrees removed"
fi
else
echo "Cancelled"
fi
}
function gpr() {
if ! command -v gh &> /dev/null; then
echo "GitHub CLI (gh) is not installed"
echo "Install it from: https://cli.github.com"
return 1
fi
local current_branch=$(git branch --show-current)
local base_branch="${1:-$GWT_DEFAULT_BRANCH}"
local repo_root=$(git rev-parse --show-toplevel)
local template_file="$repo_root/$GWT_PR_TEMPLATE"
echo "Pushing $current_branch..."
git push -u origin "$current_branch"
if [ $? -ne 0 ]; then
echo "Failed to push branch"
return 1
fi
echo "Creating pull request to $base_branch..."
if [ -f "$template_file" ]; then
echo "Using template: $GWT_PR_TEMPLATE"
gh pr create --base "$base_branch" --body-file "$template_file" --fill
else
echo "Template not found: $GWT_PR_TEMPLATE"
echo "Creating PR without template..."
gh pr create --base "$base_branch" --fill
fi
if [ $? -eq 0 ]; then
echo "Pull request created successfully!"
else
echo "Failed to create pull request"
return 1
fi
}
function gwh() {
echo "=== Git Worktree Commands ==="
echo ""
echo "CREATE & SWITCH:"
echo " gwt [branch] - Create worktree (current branch if no arg)"
echo " gwn <branch> [base] - Create new branch + worktree (default base: $GWT_DEFAULT_BRANCH)"
echo " gwp <PR#> [remote] - Checkout PR to worktree"
echo ""
echo "MANAGE:"
echo " gwl - List all worktrees"
echo " gwr <branch> - Remove worktree"
echo " gwd <branch> - Delete worktree + branch"
echo " gwc - Clean all worktrees"
echo " gwx - Prune deleted worktrees"
echo ""
echo "NAVIGATE:"
echo " gwm - Go to main repository"
echo " gws - Show worktree status"
echo ""
echo "GIT FLOW:"
echo " gpr [base] - Push + create PR (default base: $GWT_DEFAULT_BRANCH)"
echo ""
echo "DEVELOPMENT:"
echo " fm [port] - Start foreman (auto port or specify)"
echo ""
echo "=== General Git Commands ==="
echo ""
echo "STATUS & INFO:"
echo " gs - git status"
echo " gb - git branch"
echo " gba - git branch -a (all branches)"
echo " gl - git log --oneline --graph --decorate"
echo " gd - git diff"
echo ""
echo "ADD & COMMIT:"
echo " ga - git add"
echo " gaa - git add ."
echo " gc - git commit"
echo " gcm - git commit -m"
echo ""
echo "SYNC:"
echo " gf - git fetch"
echo " gpl - git pull"
echo " gp - git push"
echo " gpf - git push --force"
echo ""
echo "BRANCH:"
echo " gco - git checkout"
echo ""
echo "REBASE:"
echo " grem - Rebase on main"
echo " gred - Rebase on develop"
echo " grc - git rebase --continue"
echo " gra - git rebase --abort"
echo ""
echo "HELP:"
echo " gwh - Show this help"
echo ""
echo "CONFIGURATION:"
echo " Default base branch: $GWT_DEFAULT_BRANCH"
echo " PR template: $GWT_PR_TEMPLATE"
}
# Smart foreman runner with auto port assignment
function fm() {
local port="$1"
# If no port specified, calculate based on worktree
if [ -z "$port" ]; then
local git_dir=$(git rev-parse --git-dir 2>/dev/null)
# Check if we're in a worktree
if [[ $git_dir == *".git/worktrees"* ]]; then
# Extract worktree name and generate port
local worktree_path=$(git rev-parse --show-toplevel)
local worktree_name=$(basename "$worktree_path")
# Simple hash: sum ASCII values of branch name and mod 100, then add 3000
local hash=0
for (( i=0; i<${#worktree_name}; i++ )); do
hash=$((hash + $(printf '%d' "'${worktree_name:$i:1}")))
done
port=$((3000 + (hash % 100)))
echo "Worktree detected: $worktree_name"
echo "Auto-assigned port: $port"
else
# Main repository, use default port
port=3000
echo "Main repository - using default port: $port"
fi
else
echo "Using specified port: $port"
fi
# Export port for Procfile to use
export PORT=$port
# Run foreman
foreman start -f Procfile.dev
}
function chpwd() {
if git rev-parse --is-inside-work-tree &>/dev/null; then
local gitdir=$(git rev-parse --git-dir)
if [[ $gitdir == *".git/worktrees"* ]]; then
echo "Worktree: $(git branch --show-current)"
fi
fi
}
echo "Git Worktree configuration loaded!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment