This Bash script processes and concatenates text files from specified directories or individual files into a single Markdown-formatted output. It's useful for developers who need to compile multiple source files into a single document, while respecting .gitignore rules and handling various file types.
- Recursively processes files in a given directory or individual files.
- Respects
.gitignoreand other ignore files. - Custom ignore patterns using
--ignoreor forced inclusion using--force. - Handles binary files by listing only their paths (with optional binary types).
- Supports output to a file or directly to the clipboard.
- Formats output in Markdown for easy readability.
- Works across Linux, macOS, and Windows (with appropriate clipboard handling).
- Supports symbolic links for easy execution without
.shextension.
archivist [directories/files...] [options]--help: Show the help message and exit.--clipboard: Copy the result to the clipboard instead of creating a file.--output <file>: Specify a custom output file (default:files.txt).--supported-binary-files <types>: Specify additional supported binary file types (e.g.,'CSV|JSON').--ignore <paths>: Specify additional paths to ignore (space-separated).--force <paths>: Force inclusion of specified paths (even if ignored).--auto-confirm-git-init: Automatically initialize Git repositories if a.gitignoreis found in a directory without an initialized Git repository.--auto-continue-processing: Automatically continue processing files without user confirmation for warnings.
Process the current directory and save the output to the default file:
archivist .Process a specific directory and copy the output to the clipboard:
archivist /path/to/project --clipboardIgnore specific directories during processing:
archivist /path/to/project --ignore 'assets docs'Forcefully include specific directories even if they are ignored:
archivist /path/to/project --ignore 'node_modules dist' --force 'node_modules dist'To install the script globally and make it accessible from any directory, follow these steps based on your operating system.
git clone https://github.com/yourusername/archivist.gitYou can create a symbolic link directly to the script in the repository, so that any updates made by git pull are immediately reflected:
-
Navigate to the directory where you cloned the repository:
cd /path/to/archivist -
Create the symbolic link in
/usr/local/bin(or any directory in yourPATH):ln -s $(pwd)/archivist.sh /usr/local/bin/archivist -
Now you can run the script as
archivistfrom anywhere.
-
Navigate to the directory where you cloned the repository:
cd /path/to/archivist -
Create an alias by adding this to your
.bash_profileor.bashrc:alias archivist='bash /path/to/archivist/archivist.sh'
-
Reload the shell configuration:
source ~/.bash_profile # Or ~/.bashrc
-
Now you can run the script as
archivistfrom anywhere.
You can verify that the script is now accessible globally by running:
archivist --helpThis should display the help menu.
To update the script, follow these steps:
cd archivistgit pullSince the symbolic link is already in place, the updates will be immediately available.
Run the script again to ensure the update was successful:
archivist --helpThis project is licensed under the MIT License.
To my family, to my friends and special thanks to the open source community for the feedback and contributions.
Created with ❤️ by Fabricio Orrala