A simple Node.js command-line tool for macOS that reads the contents of one or more files (supports glob patterns), formats them, outputs the result to the console, and automatically copies it to your clipboard. This is useful when you want to copy the content of multiple files to a single location, like an LLM chat message.
- inline-copy
- Read Multiple Files: Include one or more files or glob patterns in a single command.
- Glob Pattern Support: Use glob patterns to specify files.
- Formatted Output: Outputs file contents with clear separators and file names.
- Clipboard Integration: Automatically copies the formatted output to your clipboard.
- Console Output: Displays the formatted content in your terminal.
-
Node.js: Ensure that Node.js is installed on your macOS system.
node -v
If Node.js is not installed, download it from the official website or install it via Homebrew:
brew install node
Clone this repository to your scripts directory:
git clone https://github.com/sebastienfi/inline-copy.git ~/scripts/inline-copy
Navigate to the project directory and install the required modules:
cd ~/scripts/inline-copy
npm install
chmod +x inline-copy
This allows you to run inline-copy
from anywhere without moving the script.
sudo ln -s ~/scripts/inline-copy/inline-copy /usr/local/bin/inline-copy
-
Edit Your Shell Profile:
-
For bash:
nano ~/.bash_profile
-
For zsh (default shell in newer macOS versions):
nano ~/.zshrc
-
-
Add the Following Line:
export PATH="$PATH:$HOME/scripts/inline-copy"
-
Reload Your Shell Configuration:
-
For bash:
source ~/.bash_profile
-
For zsh:
source ~/.zshrc
-
inline-copy "<file-pattern-1>" "<file-pattern-2>" "<file-pattern-3>" ...
- Replace
<file-pattern-n>
with the relative or absolute file paths or glob patterns. - Enclose patterns with spaces in quotes.
The script outputs formatted content to the console and copies it to your clipboard. The format is:
###
---
File: "file-n"
<file-contents>
---
###
- Each file's content is enclosed between
---
separators. - The entire output is enclosed between
###
separators. - File contents are wrapped in code blocks using triple backticks for better readability.
inline-copy "example.txt"
Output:
###
---
File: "example.txt"
<contents of example.txt>
---
###
inline-copy "*.js" "src/**/*.css" "README.md"
Explanation:
*.js
: All.js
files in the current directory.src/**/*.css
: All.css
files in any subdirectory ofsrc
.README.md
: Includes theREADME.md
file.
Output:
###
---
File: "app.js"
<contents of app.js>
---
---
File: "utils/helper.js"
<contents of utils/helper.js>
---
---
File: "src/styles/main.css"
<contents of src/styles/main.css>
---
---
File: "README.md"
<contents of README.md>
---
###
- Glob Patterns: The script supports glob patterns for flexible file selection.
- Clipboard Copy: The script uses the
pbcopy
command, which is available by default on macOS, to copy the output to the clipboard. - Error Handling: If a pattern matches no files, the script will display an error message but continue processing other patterns.
- Relative Paths: The script resolves file paths relative to the current working directory.
- Dependencies: The script uses the
glob
module for pattern matching.
This project is licensed under the MIT License.
Feel free to customize the script or reach out if you have any questions!
Updating the Script:
To update the script with the latest changes from the repository, navigate to the directory and pull the latest commits:
cd ~/scripts/inline-copy
git pull
-
Include all JavaScript files in the current directory:
inline-copy "*.js"
-
Include all Markdown files in
docs
directory:inline-copy "docs/**/*.md"
-
Include specific files:
inline-copy "inline-copy" "README.md"
Feel free to open an issue on the repository or reach out if you have any questions!