This repository contains the get_multifile_prompt.sh
script and potentially other useful scripts in the future.
The get_multifile_prompt.sh
script concatenates the contents of multiple files, optionally searching in subdirectories, and copies the result to the clipboard. This script is particularly useful when working with large language models (LLMs).
Efficiently programming multifile projects:
LLMs are pretty powerful when they’re working with a project split up into multiple files. They’re great with simple files, even if there are many of them. By using gmfp
(get multifile prompt), you can easily prepare a comprehensive prompt for the LLM that includes all relevant code files, ensuring the model has all the context it needs to understand and work on your project effectively.
-
Make the script executable:
chmod +x get_multifile_prompt.sh
-
Create an alias for easy access:
Open your
.zshrc
(or.bashrc
if you're using Bash) file in a text editor:nano ~/.zshrc
Add the following line to create an alias:
alias gmfp='/path/to/get_multifile_prompt.sh'
Save the file and exit the text editor.
-
Reload the shell configuration:
source ~/.zshrc
You can now use the gmfp
command to run the script. Here are some examples:
-
Search only in the current directory for
.tsx
files:gmfp "*.tsx"
-
Search in the current directory and all subdirectories for
.tsx
files:gmfp -r "*.tsx"
-
Search in the current directory and all subdirectories for
.tsx
and.css
files:gmfp -r "*.tsx" "*.css"
-
Search for all files in the current directory only:
gmfp
-
Search for all files in the current directory and its subdirectories:
gmfp -r
Here is an example of how this script works and why it is useful when working with LLMs:
gmfp -r "*.py"
This command will find all Python files in the current directory and subdirectories, concatenate them into one prompt, and copy it to the clipboard. Each file's content is encapsulated in backticks along with its path, as shown below:
\```./folder1/script1.py
print("Hello from script1")
\```
```./folder2/script2.py
print("Hello from script2")
\```
I took the original version of this script from EasyModularScripts, but added subdirectories (recursion functionality).
-
For macOS users,
pbcopy
is typically pre-installed. -
For Linux users, install
xclip
if it is not already installed:sudo apt-get install xclip
Feel free to fork this repository, submit issues, and make pull requests. Contributions are welcome!