prompts

 1#!/bin/bash
 2
 3# This script manages prompt overrides for the Zed editor.
 4#
 5# It provides functionality to:
 6# 1. Link the current repository's prompt templates to Zed's configuration.
 7# 2. Create and link a separate Git worktree for prompt management.
 8# 3. Unlink previously linked prompt overrides.
 9#
10# Usage:
11#   ./script_name.sh link             # Link current repo's prompts
12#   ./script_name.sh link --worktree  # Create and link a separate worktree
13#   ./script_name.sh unlink           # Remove existing prompt override link
14#
15# The script ensures proper Git branch and worktree setup when using the
16# --worktree option. It also provides informative output and error handling.
17
18if [ "$1" = "link" ]; then
19    # Remove existing link
20    rm -f ~/.config/zed/prompt_overrides
21    if [ "$2" = "--worktree" ]; then
22        # Check if 'prompts' branch exists, create if not
23        if ! git show-ref --quiet refs/heads/prompts; then
24            git branch prompts
25        fi
26        # Check if 'prompts' worktree exists
27        if git worktree list | grep -q "../zed_prompts"; then
28            echo "Worktree already exists at ../zed_prompts."
29        else
30            # Create worktree if it doesn't exist
31            git worktree add ../zed_prompts prompts || git worktree add ../zed_prompts -b prompts
32        fi
33        ln -sf "$(pwd)/../zed_prompts/assets/prompts" ~/.config/zed/prompt_overrides
34        echo "Linked $(realpath "$(pwd)/../zed_prompts/assets/prompts") to ~/.config/zed/prompt_overrides"
35        echo -e "\033[0;31mDon't forget you have it linked, or your prompts will go stale\033[0m"
36    else
37        ln -sf "$(pwd)/assets/prompts" ~/.config/zed/prompt_overrides
38        echo "Linked $(pwd)/assets/prompts to ~/.config/zed/prompt_overrides"
39    fi
40elif [ "$1" = "unlink" ]; then
41    # Remove symbolic link
42    rm ~/.config/zed/prompt_overrides
43    echo "Unlinked ~/.config/zed/prompt_overrides"
44else
45    echo "This script helps you manage prompt overrides for Zed."
46    echo "You can link this directory to have Zed use the contents of your current repo templates as your active prompts,"
47    echo "or store your modifications in a separate Git worktree."
48    echo
49    echo "Usage: $0 [link [--worktree]|unlink]"
50    echo
51    echo "Options:"
52    echo "  link               Create a symbolic link from ./assets/prompts to ~/.config/zed/prompt_overrides"
53    echo "  link --worktree    Create a 'prompts' Git worktree in ../prompts, then link ../prompts/assets/prompts"
54    echo "                     to ~/.config/zed/prompt_overrides"
55    echo "  unlink             Remove the symbolic link at ~/.config/zed/prompt_overrides"
56    exit 1
57fi