Prelude is an extremely simple tool to help you make context prompts for LLMs with long context windows. It is useful when using LLMs to improve code that is distributed over multiple files and directories. Prelude generates a prompt containing the file tree and concatenated file contents of a specified directory. The prompt is automatically copied to the clipboard and optionally saved to a file.
prelude [-P <relative_path>] [-F <output_filename>] [-M <match_pattern>] [--help] [--manual]
Files and directories that are to be excluded can be listed in a .preludeignore file in the directory where you run prelude. Prelude will also ignore anything in the .gitignore.
brew tap aerugo/prelude
brew install prelude
-P <relative_path>
: Specify a relative path to include only files below that path. If not specified, the script will include all files in the current directory and its subdirectories.-F <output_filename>
: Specify a filename to save the generated prompt. If not specified, the prompt will only be copied to the clipboard.-M <match_pattern>
: Specify pattern(s) to match filenames and only include those files. Use '|' as a delimiter for multiple patterns.--help
: Display help information.--manual
: Display the manual.
This script generates a prompt containing the file tree and concatenated file contents of a specified directory. The prompt can be copied to the clipboard and optionally saved to a file.
-P <relative_path>
: Specify a relative path to include only files below that path. If not specified, the script will include all files in the current directory and its subdirectories.-F <output_filename>
: Specify a filename to save the generated prompt. If not specified, the prompt will only be copied to the clipboard.-M <match_pattern>
: Specify pattern(s) to match filenames. Uses tree's pattern matching syntax. For multiple patterns, separate them with '|'. Use '*' for wildcards. The matching is case-insensitive by default.--help
: Display help information.--manual
: Display the manual.
./prelude
: Generate a prompt for all files in the current directory and copy it to the clipboard../prelude -P src
: Generate a prompt for all files below the specified path and copy it to the clipboard../prelude -F prompt.txt
: Generate a prompt for all files in the current directory and save it to a file../prelude -P src -F prompt.txt
: Generate a prompt for all files below the specified path and save it to a file../prelude -M "*.txt|*.py"
: Generate a prompt for all .txt and .py files../prelude -M "test*"
: Generate a prompt for all files starting with 'test'.
- The script checks for the presence of clipboard commands (
pbcopy
,xclip
,xsel
,clip
) and uses the first one found to copy the prompt to the clipboard. If none are found, an error is displayed. - The script reads
.gitignore
and.preludeignore
files to exclude specified patterns from the file tree.
tree
: Ensure that thetree
command is installed and available in the system.
- If the specified path does not exist or is not a directory, an error message is displayed, and the script exits.
- If no clipboard command is found, an error message is displayed, and the script exits.
- The script copies the generated prompt to the clipboard and optionally saves it to a specified file.
- A message is printed to indicate the completion, listing the files included in the prompt.
Prelude comes with a comprehensive test suite using the Bats (Bash Automated Testing System) framework. The tests cover various scenarios including:
- Running the script without arguments
- Using different flags (-P, -F, -M)
- Respecting .gitignore and .preludeignore files
- Handling invalid inputs and edge cases
To run the tests, make sure you have Bats installed and then run:
bats test_prelude.bats
This will execute all the tests and provide a summary of the results, ensuring the reliability and correctness of the Prelude tool.