Created
March 11, 2025 14:55
-
-
Save blakedietz/76bdedf35a7b489daca3f722dad7699f to your computer and use it in GitHub Desktop.
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 create_jump_worktree --description "Create a new Jump App git worktree from a PR or new branch" | |
set -l branch_opt (fish_opt --short=b --long=branch --required-val) | |
argparse $branch_opt -- $argv | |
or return 1 | |
# Define base directories | |
set -l source_dir /Users/blakedietz/projects/Jump-App/Jump | |
set -l worktrees_dir /Users/blakedietz/projects/Jump-App/Jump-worktrees | |
# Determine if we're creating a new branch or selecting a PR | |
set -l pr_branch | |
set -l is_new_branch false | |
if set -q _flag_branch | |
set pr_branch $_flag_branch | |
set is_new_branch true | |
else | |
# Use gh cli to select a PR | |
set -l pr_data (gh pr list --json "number,title,headRefName" | jq -r '.[] | "\(.number)|\(.title)|\(.headRefName)"' | fzf) | |
if test -z "$pr_data" | |
echo "No PR selected. Exiting." | |
return 1 | |
end | |
# Extract PR details | |
set pr_branch (echo $pr_data | cut -d'|' -f3) | |
end | |
set -l worktree_path "$worktrees_dir/$pr_branch" | |
if test "$is_new_branch" = true | |
echo "Creating new branch '$pr_branch'..." | |
git worktree add -b "$pr_branch" "$worktree_path" | |
else | |
echo "Fetching latest changes from remote..." | |
git fetch --all | |
if test $status -ne 0 | |
echo "Error: Failed to fetch from remote" | |
return 1 | |
end | |
git worktree add -b "$pr_branch" "$worktree_path" "origin/$pr_branch" | |
end | |
if test $status -ne 0 | |
echo "Error: Failed to create git worktree" | |
return 1 | |
end | |
echo "New worktree created:" | |
echo "Path: $worktree_path" | |
cd "$worktree_path/api" | |
if make bootstrap | |
echo "Make setup completed successfully" | |
else | |
echo "Warning: Make setup failed" | |
end | |
echo "Creating symbolic links from source directory..." | |
# Link .env file | |
set -l env_source "$source_dir/.env" | |
set -l env_target "$worktree_path/.env" | |
if test -f $env_source | |
ln -sf $env_source $env_target | |
echo "Linked .env file" | |
else | |
echo "Warning: Source .env file not found at $env_source" | |
end | |
# Link SSL certificate files | |
set -l key_source "$source_dir/api/local/jumpapp.key" | |
set -l key_target "$worktree_path/api/local/jumpapp.key" | |
set -l crt_source "$source_dir/api/local/jumpapp.crt" | |
set -l crt_target "$worktree_path/api/local/jumpapp.crt" | |
if test -f $key_source | |
ln -sf $key_source $key_target | |
echo "Linked jumpapp.key file" | |
else | |
echo "Warning: Source key file not found at $key_source" | |
end | |
if test -f $crt_source | |
ln -sf $crt_source $crt_target | |
echo "Linked jumpapp.crt file" | |
else | |
echo "Warning: Source certificate file not found at $crt_source" | |
end | |
echo "Symlink creation complete" | |
return 0 | |
end | |
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 switch_worktree --description "Switch to a worktree's api directory using fzf" | |
set -l base_dir /Users/blakedietz/projects/Jump-App/Jump | |
# Get list of all worktrees | |
set -l worktree_list (git -C $base_dir worktree list | fzf) | |
if test -z "$worktree_list" | |
echo "No worktree selected. Exiting." | |
return 1 | |
end | |
# Extract the path from the worktree list output | |
# git worktree list output format is: "path branch [state]" | |
set -l selected_path (echo $worktree_list | awk '{print $1}') | |
# Change to the api directory of the selected worktree | |
set -l api_path "$selected_path/api" | |
if test -d $api_path | |
cd $api_path | |
echo "Switched to $api_path" | |
else | |
echo "Error: api directory not found at $api_path" | |
return 1 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment