Skip to content

Instantly share code, notes, and snippets.

@devnacho

devnacho/.zshrc Secret

Created October 22, 2025 12:45
Show Gist options
  • Select an option

  • Save devnacho/3ad0ecf9962569c63a1225e1b757f644 to your computer and use it in GitHub Desktop.

Select an option

Save devnacho/3ad0ecf9962569c63a1225e1b757f644 to your computer and use it in GitHub Desktop.
Worktrees `wt` shortcut
# Worktrees function START
# # Git worktree helper function: wt <feature-name>
wt() {
emulate -L zsh # localise options for zsh
set -e
local project_dir
project_dir=$(git rev-parse --show-toplevel 2>/dev/null) || {
echo "❌ Not inside a Git repository."
return 1
}
local project_name feature_name worktree_parent worktree_path
project_name="${project_dir:t}"
feature_name="$1"
if [[ -z "$feature_name" ]]; then
echo "❌ Usage: wt <feature-name>"
return 1
fi
worktree_parent="${project_dir:h}/${project_name}-worktrees"
worktree_path="${worktree_parent}/${feature_name}"
mkdir -p "$worktree_parent"
git -C "$project_dir" worktree add -b "$feature_name" "$worktree_path" || return 1
if [[ -f "$project_dir/.env" ]]; then
cp "$project_dir/.env" "$worktree_path/.env"
echo "πŸ“‹ Copied .env into worktree."
fi
if [[ -f "$project_dir/.local.env" ]]; then
cp "$project_dir/.local.env" "$worktree_path/.local.env"
echo "πŸ“‹ Copied .local.env into worktree."
fi
local hidden_dirs=(.instrumental .agent_os .claude)
for dir in $hidden_dirs; do
if [[ -d "$project_dir/$dir" ]]; then
cp -R "$project_dir/$dir" "$worktree_path/$dir"
echo "πŸ“‚ Copied $dir into worktree."
fi
done
cd "$worktree_path" || return 1
if command -v cursor &>/dev/null; then
cursor "$worktree_path" &
else
echo "πŸ’‘ Tip: Install Cursor or open manually in your editor."
fi
echo "βœ… Worktree '$feature_name' created at $worktree_path and checked out."
}
# Worktrees END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment