Last active
January 8, 2026 00:44
-
-
Save armcknight/8588a00d6d5524c24bb8b64a4ed9dc3e to your computer and use it in GitHub Desktop.
LLM Fish shell automation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function work -d "Unified worktree and terminal session manager" | |
| if test (count $argv) -eq 0 | |
| echo "Usage: work <command> [args]" | |
| echo "Commands:" | |
| echo " start <branch> - Create worktree, copy .env files, and start tmux session" | |
| echo " term - Start tmux dev session named after current git branch" | |
| echo " finish <branch> - Complete worktree: cleanup .env files, remove worktree, and delete branch" | |
| return 1 | |
| end | |
| switch $argv[1] | |
| case "start" | |
| if test (count $argv) -ne 2 | |
| echo "Usage: work start <branch_name>" | |
| return 1 | |
| end | |
| if not git rev-parse --is-inside-work-tree >/dev/null 2>&1 | |
| echo "Not in a git repository" | |
| return 1 | |
| end | |
| set branch_name $argv[2] | |
| set worktree_path "worktrees/$branch_name" | |
| # Check if worktree already exists | |
| if test -d "$worktree_path" | |
| echo "Worktree $worktree_path already exists" | |
| return 1 | |
| end | |
| # Create worktree (this will create the branch automatically if it doesn't exist) | |
| echo "Creating worktree: $worktree_path" | |
| if git show-ref --verify --quiet "refs/heads/$branch_name" | |
| echo "Branch $branch_name already exists, using existing branch" | |
| git worktree add "$worktree_path" "$branch_name" | |
| else | |
| echo "Creating new branch: $branch_name" | |
| git worktree add -b "$branch_name" "$worktree_path" | |
| end | |
| # Copy .env files from root to worktree | |
| if test -f ".env" | |
| echo "Copying .env file to worktree..." | |
| cp ".env" "$worktree_path/.env" | |
| end | |
| if test -f "fastlane/.env" | |
| echo "Copying fastlane/.env file to worktree..." | |
| mkdir -p "$worktree_path/fastlane" | |
| cp "fastlane/.env" "$worktree_path/fastlane/.env" | |
| end | |
| # Change to worktree directory and start tmux | |
| echo "Changing to worktree directory and starting development session..." | |
| cd "$worktree_path" | |
| work term | |
| case "term" | |
| set current_branch (git branch --show-current 2>/dev/null) | |
| if test -z "$current_branch" | |
| echo "Not in a git repository" | |
| return 1 | |
| end | |
| # Slugify pwd: replace / with -, remove leading -, remove dots, lowercase | |
| set pwd_slug (string replace -a '/' '-' (pwd) | string replace -a '.' '' | string trim -c '-' | string lower) | |
| # Slugify branch name: replace / with -, lowercase | |
| set branch_slug (string replace -a '/' '-' $current_branch | string lower) | |
| # Create session name: pwd-slug_branch-slug | |
| set session_name "$pwd_slug"_"$branch_slug" | |
| # Create or attach to tmux session | |
| if tmux has-session -t "$session_name" 2>/dev/null | |
| tmux attach-session -t "$session_name" | |
| else | |
| tmuxinator start dev -n "$session_name" | |
| end | |
| case "finish" | |
| if test (count $argv) -ne 2 | |
| echo "Usage: work finish <branch_name>" | |
| return 1 | |
| end | |
| if not git rev-parse --is-inside-work-tree >/dev/null 2>&1 | |
| echo "Not in a git repository" | |
| return 1 | |
| case "*" | |
| echo "Unknown command: $argv[1]" | |
| echo "Available commands: start, term, finish" | |
| return 1 | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment