zed/script/prompts
Nathan Sobo 355aebd0e4
Some checks are pending
CI / Check formatting and spelling (push) Waiting to run
CI / (macOS) Run Clippy and tests (push) Waiting to run
CI / (Linux) Run Clippy and tests (push) Waiting to run
CI / (Windows) Run Clippy and tests (push) Waiting to run
CI / Create a macOS bundle (push) Blocked by required conditions
CI / Create a Linux bundle (push) Blocked by required conditions
CI / Create arm64 Linux bundle (push) Blocked by required conditions
Deploy Docs / Deploy Docs (push) Waiting to run
Docs / Check formatting (push) Waiting to run
Introduce prompt override script and adjust names (#16094)
This PR introduces a new script for iterative development of prompt
overrides in Zed.

Just `script/prompts link` and your running Zed should start using
prompts from `zed/assets/prompts`. Use `script/prompts unlink` to undo.
You can also link with `script/prompts link --worktree` to store the
prompts to a `../zed_prompts` worktree that's a sibling of your repo, in
case you don't want to mess with your working copy. Just don't forget
about it!

Key changes:
- Add new `script/prompts` for managing prompt overrides
- Rename `prompt_templates_dir` to `prompt_overrides_dir` for clarity
- Update paths to use `~/.config/zed/prompt_overrides` instead of
`~/.config/zed/prompts/templates`
- Adjust `PromptBuilder` to use the new `prompt_overrides_dir` function

These changes simplify the process of customizing prompts and provide a
more intuitive naming convention for override-related functionality.

Release Notes:

- N/A
2024-08-11 17:21:17 -06:00

58 lines
2.6 KiB
Bash
Executable file

#!/bin/bash
# This script manages prompt overrides for the Zed editor.
#
# It provides functionality to:
# 1. Link the current repository's prompt templates to Zed's configuration.
# 2. Create and link a separate Git worktree for prompt management.
# 3. Unlink previously linked prompt overrides.
#
# Usage:
# ./script_name.sh link # Link current repo's prompts
# ./script_name.sh link --worktree # Create and link a separate worktree
# ./script_name.sh unlink # Remove existing prompt override link
#
# The script ensures proper Git branch and worktree setup when using the
# --worktree option. It also provides informative output and error handling.
if [ "$1" = "link" ]; then
# Remove existing link
rm -f ~/.config/zed/prompt_overrides
if [ "$2" = "--worktree" ]; then
# Check if 'prompts' branch exists, create if not
if ! git show-ref --quiet refs/heads/prompts; then
git branch prompts
fi
# Check if 'prompts' worktree exists
if git worktree list | grep -q "../zed_prompts"; then
echo "Worktree already exists at ../zed_prompts."
else
# Create worktree if it doesn't exist
git worktree add ../zed_prompts prompts || git worktree add ../zed_prompts -b prompts
fi
ln -sf "$(pwd)/../zed_prompts/assets/prompts" ~/.config/zed/prompt_overrides
echo "Linked $(realpath "$(pwd)/../zed_prompts/assets/prompts") to ~/.config/zed/prompt_overrides"
echo -e "\033[0;31mDon't forget you have it linked, or your prompts will go stale\033[0m"
else
ln -sf "$(pwd)/assets/prompts" ~/.config/zed/prompt_overrides
echo "Linked $(pwd)/assets/prompts to ~/.config/zed/prompt_overrides"
fi
elif [ "$1" = "unlink" ]; then
# Remove symbolic link
rm ~/.config/zed/prompt_overrides
echo "Unlinked ~/.config/zed/prompt_overrides"
else
echo "This script helps you manage prompt overrides for Zed."
echo "You can link this directory to have Zed use the contents of your current repo templates as your active prompts,"
echo "or store your modifications in a separate Git worktree."
echo
echo "Usage: $0 [link [--worktree]|unlink]"
echo
echo "Options:"
echo " link Create a symbolic link from ./assets/prompts to ~/.config/zed/prompt_overrides"
echo " link --worktree Create a 'prompts' Git worktree in ../prompts, then link ../prompts/assets/prompts"
echo " to ~/.config/zed/prompt_overrides"
echo " unlink Remove the symbolic link at ~/.config/zed/prompt_overrides"
exit 1
fi