From b958637a9fb398292ea4979b55fe9790cf7bb290 Mon Sep 17 00:00:00 2001 From: kuderr Date: Wed, 25 Feb 2026 14:56:32 +0300 Subject: [PATCH 1/2] feat: add shell aliases for quick worktree navigation Adds aliases/git-wt.sh with shorthand functions: wtcd (cd into worktree), wto (cd to origin), wtn (new + cd), wtls, wtla, wtrm, wtopen, wtclean, wtpath. Includes tab completion for bash and zsh. Co-Authored-By: Claude Opus 4.6 --- CHANGELOG.md | 8 +++++ CLAUDE.md | 1 + README.md | 23 +++++++++++++ aliases/git-wt.sh | 77 ++++++++++++++++++++++++++++++++++++++++++ skills/git-wt/SKILL.md | 12 +++++++ 5 files changed, 121 insertions(+) create mode 100644 aliases/git-wt.sh diff --git a/CHANGELOG.md b/CHANGELOG.md index e8ad350..468fb7d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## [1.4.0] - 2026-02-25 + +### Added +- Shell aliases (`aliases/git-wt.sh`) — `wtcd`, `wto`, `wtn`, `wtls`, `wtla`, `wtrm`, `wtopen`, `wtclean`, `wtpath` +- `wtn` creates a worktree and `cd`s into it in one step +- `wtcd ` jumps into a worktree, `wto` jumps to the origin repo +- Tab completion for aliases (bash + zsh) + ## [1.3.0] - 2026-02-25 ### Added diff --git a/CLAUDE.md b/CLAUDE.md index 31b464b..0d26c0b 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -9,6 +9,7 @@ Wraps `git worktree` into an ergonomic CLI: `git wt `. ``` bin/git-wt — main executable (bash script) +aliases/git-wt.sh — optional shell aliases (wtcd, wto, wtn, etc.) completions/ git-wt.bash — bash completions _git-wt — zsh completions diff --git a/README.md b/README.md index ba7d995..b9251ba 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,29 @@ git wt open auth-refactor git wt rm auth-refactor ``` +### Shell Aliases + +Source the optional aliases file for shorter commands: + +```bash +# Add to ~/.bashrc or ~/.zshrc +source /path/to/git-wt/aliases/git-wt.sh +``` + +| Alias | Equivalent | Description | +|-------|-----------|-------------| +| `wtcd ` | `cd $(git wt path )` | cd into a worktree | +| `wto` | `cd $(git wt origin)` | cd into the origin (main) repo | +| `wtn [name]` | `git wt new` + `cd` | Create worktree and cd into it | +| `wtls` | `git wt list` | List worktrees | +| `wtla` | `git wt list-all` | List all worktrees | +| `wtrm ` | `git wt rm` | Remove a worktree | +| `wtopen ` | `git wt open` | Open worktree in editor | +| `wtclean` | `git wt clean` | Remove all worktrees | +| `wtpath ` | `git wt path` | Print worktree path | + +Tab completion is included for bash and zsh — worktree names autocomplete for `wtcd`, `wtrm`, `wtopen`, and `wtpath`. + ### Copying `.env` files Worktrees are separate directories — your `.env` files (gitignored) won't be there. diff --git a/aliases/git-wt.sh b/aliases/git-wt.sh new file mode 100644 index 0000000..e5c32b1 --- /dev/null +++ b/aliases/git-wt.sh @@ -0,0 +1,77 @@ +# git-wt shell aliases & functions +# Source this file in your .bashrc / .zshrc: +# source ~/.git-wt/git-wt/aliases/git-wt.sh +# — or wherever you keep this file — + +# cd into a worktree by name +# wtcd my-feature +wtcd() { + local path + path=$(git wt path "$1" 2>/dev/null) || { echo "error: worktree '$1' not found" >&2; return 1; } + cd "$path" || return 1 +} + +# cd into the origin (main) repo from any worktree +# wto +wto() { + local path + path=$(git wt origin 2>/dev/null) || { echo "error: not in a git repo" >&2; return 1; } + cd "$path" || return 1 +} + +# Create a new worktree and cd into it +# wtn my-feature +# wtn (auto-generated name) +# wtn -b main hotfix +wtn() { + local output + output=$(git wt new "$@") || return 1 + echo "$output" + local path + path=$(echo "$output" | grep 'Path:' | awk '{print $2}') + [[ -n "$path" ]] && cd "$path" || return 1 +} + +# List worktrees (current repo) +alias wtls='git wt list' + +# List all worktrees (all repos) +alias wtla='git wt list-all' + +# Remove a worktree +alias wtrm='git wt rm' + +# Open worktree in editor +alias wtopen='git wt open' + +# Remove all worktrees for current repo +alias wtclean='git wt clean' + +# Print worktree path (for scripting) +alias wtpath='git wt path' + +# --- Completions for aliases --- +if [[ -n "${ZSH_VERSION:-}" ]]; then + # zsh: reuse git-wt completions for worktree-name arguments + _wtcd() { compadd -- $(git wt _names 2>/dev/null); } + _wtn() { _arguments '*:branch:_git_branch_names'; } + _wtrm() { compadd -- $(git wt _names 2>/dev/null); } + _wtopen() { compadd -- $(git wt _names 2>/dev/null); } + _wtpath() { compadd -- $(git wt _names 2>/dev/null); } + + compdef _wtcd wtcd + compdef _wtrm wtrm + compdef _wtopen wtopen + compdef _wtpath wtpath +elif [[ -n "${BASH_VERSION:-}" ]]; then + # bash + _wt_alias_complete() { + local cur="${COMP_WORDS[COMP_CWORD]}" + COMPREPLY=( $(compgen -W "$(git wt _names 2>/dev/null)" -- "$cur") ) + } + + complete -F _wt_alias_complete wtcd + complete -F _wt_alias_complete wtrm + complete -F _wt_alias_complete wtopen + complete -F _wt_alias_complete wtpath +fi diff --git a/skills/git-wt/SKILL.md b/skills/git-wt/SKILL.md index 93f1aa6..7c84dc3 100644 --- a/skills/git-wt/SKILL.md +++ b/skills/git-wt/SKILL.md @@ -106,6 +106,18 @@ Use `git wt adopt` when: - A worktree was created with `git worktree add` and you want git-wt to manage it - You want the worktree moved to `~/.git-wt/` for consistent management +## Shell Aliases + +Optional `aliases/git-wt.sh` provides shorter commands. Source it in `.bashrc`/`.zshrc`: + +| Alias | What it does | +|-------|-------------| +| `wtcd ` | `cd` into a worktree | +| `wto` | `cd` to the origin (main) repo | +| `wtn [name]` | Create worktree + `cd` into it | +| `wtls` / `wtla` | List / list-all | +| `wtrm` / `wtopen` / `wtclean` / `wtpath` | Shorthand for corresponding commands | + ## Workflow: Parallel Agent Isolation ```bash From f9905e46263177c9e79eb5e7a38e35832b16a8df Mon Sep 17 00:00:00 2001 From: kuderr Date: Wed, 25 Feb 2026 15:17:05 +0300 Subject: [PATCH 2/2] feat: add curl installer for shell aliases Downloads aliases/git-wt.sh to ~/.local/share/git-wt/ and auto-adds source line to .zshrc/.bashrc. Co-Authored-By: Claude Opus 4.6 --- README.md | 8 +++++- aliases/install.sh | 67 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 aliases/install.sh diff --git a/README.md b/README.md index b9251ba..03809b8 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,13 @@ git wt rm auth-refactor ### Shell Aliases -Source the optional aliases file for shorter commands: +Install the optional aliases for shorter commands: + +```bash +curl -fsSL https://raw.githubusercontent.com/kuderr/git-wt/main/aliases/install.sh | bash +``` + +Or source manually: ```bash # Add to ~/.bashrc or ~/.zshrc diff --git a/aliases/install.sh b/aliases/install.sh new file mode 100644 index 0000000..7793d71 --- /dev/null +++ b/aliases/install.sh @@ -0,0 +1,67 @@ +#!/usr/bin/env bash +# git-wt aliases installer +# Usage: curl -fsSL https://raw.githubusercontent.com/kuderr/git-wt/main/aliases/install.sh | bash + +# shellcheck disable=SC2059 # intentional: ANSI color codes in printf format strings +set -euo pipefail + +REPO="kuderr/git-wt" +BRANCH="main" +URL="https://raw.githubusercontent.com/${REPO}/${BRANCH}/aliases/git-wt.sh" +INSTALL_DIR="${HOME}/.local/share/git-wt" +INSTALL_PATH="${INSTALL_DIR}/aliases.sh" + +# Colors +if [[ -t 1 ]] && [[ -z "${NO_COLOR:-}" ]]; then + GREEN=$'\033[0;32m' DIM=$'\033[2m' BOLD=$'\033[1m' RESET=$'\033[0m' +else + GREEN='' DIM='' BOLD='' RESET='' +fi + +# Download helper +download() { + if command -v curl &>/dev/null; then + curl -fsSL "$1" + elif command -v wget &>/dev/null; then + wget -qO- "$1" + else + echo "Error: curl or wget required" >&2 + exit 1 + fi +} + +echo "" +printf "${BOLD}Installing git-wt aliases...${RESET}\n\n" + +# Download aliases file +mkdir -p "$INSTALL_DIR" +download "$URL" > "$INSTALL_PATH" +printf " ${GREEN}✓${RESET} Downloaded aliases to %s\n" "$INSTALL_PATH" + +# Detect shell rc file +if [[ "${SHELL:-}" == *"zsh"* ]]; then + RC_FILE="${HOME}/.zshrc" +elif [[ "${SHELL:-}" == *"bash"* ]]; then + RC_FILE="${HOME}/.bashrc" +else + RC_FILE="" +fi + +# Add source line if not already present +if [[ -n "$RC_FILE" ]]; then + if [[ -f "$RC_FILE" ]] && grep -qF "$INSTALL_PATH" "$RC_FILE" 2>/dev/null; then + printf " ${GREEN}✓${RESET} Already sourced in %s\n" "$RC_FILE" + else + printf '\n# git-wt aliases\nsource "%s"\n' "$INSTALL_PATH" >> "$RC_FILE" + printf " ${GREEN}✓${RESET} Added source line to %s\n" "$RC_FILE" + fi +else + echo "" + printf " Add to your shell profile:\n" + printf " ${DIM}source \"%s\"${RESET}\n" "$INSTALL_PATH" +fi + +echo "" +printf "${GREEN}Done!${RESET} Restart your shell or run:\n" +printf " ${DIM}source \"%s\"${RESET}\n" "$INSTALL_PATH" +echo ""