TrailMark is a utility that recursively processes files in a directory and adds their relative paths as comments at the top of each file. This makes it easier to identify file locations when viewing them in isolation, such as in search results or code snippets.
- Automatically adds path comments to files based on their extension
- Smart comment syntax based on file type
- Skips files that already have path comments
- Interactive directory selection mode
- Configurable directory exclusions via .trailmarkignore
- Available in both Python and Bash implementations
TrailMark processes files in the following way:
- Checks if the file already has a path comment at the top
- If a path comment exists (in any supported format), the file is skipped
- Path comments are identified by the presence of "Path:" (case insensitive)
- Determines the appropriate comment syntax based on file extension
- Adds the relative path as a comment at the top of the file
- Preserves the original file content
TrailMark automatically uses the appropriate comment syntax for different file types:
- Python/Shell/Ruby/Perl:
# Path: relative/path/to/file
- JavaScript/Java/C++/C#/PHP:
// Path: relative/path/to/file
- HTML/XML:
<!-- Path: relative/path/to/file -->
- CSS:
/* Path: relative/path/to/file */
TrailMark uses a .trailmarkignore
file to specify which directories should be excluded by default. The file can be placed in:
- The current directory
- Your home directory (
~/.trailmarkignore
) - The same directory as the script
The .trailmarkignore
file should contain one directory name per line. Lines starting with #
are treated as comments. Example:
# Package managers
node_modules
venv
vendor
# Version control
.git
.svn
# Build directories
dist
build
target
# Add your own exclusions here
If multiple .trailmarkignore
files exist, they will all be read and their exclusions combined.
- Download
trailmark.py
- Make it executable:
chmod +x trailmark.py
- Download
trailmark.sh
- Make it executable:
chmod +x trailmark.sh
Both versions support the same command-line options:
# Python version
./trailmark.py [options] [directory]
# Bash version
./trailmark.sh [options] [directory]
-i, --interactive
: Run in interactive mode to manually select directories to exclude-a, --all
: Process all directories (ignore .trailmarkignore)-e, --exclude
: Specify additional directories to exclude- Python: Space-separated list (
-e dist build temp
) - Bash: Comma-separated list (
-e dist,build,temp
)
- Python: Space-separated list (
-h, --help
: Show help message
By default (no flags), TrailMark will:
- Process the current directory if no directory is specified
- Exclude directories listed in .trailmarkignore
- Process all supported file types
- Skip files that already have path comments
- Add path comments to files that don't have them
- Process current directory using .trailmarkignore:
./trailmark.py
# or
./trailmark.sh
- Process specific directory:
./trailmark.py /path/to/project
# or
./trailmark.sh /path/to/project
- Interactive mode:
./trailmark.py -i
# or
./trailmark.sh -i
- Process all directories (ignore .trailmarkignore):
./trailmark.py -a
# or
./trailmark.sh -a
- Exclude additional directories:
# Python (space-separated)
./trailmark.py -e dist build temp
# Bash (comma-separated)
./trailmark.sh -e dist,build,temp
- Combine options:
# Python
./trailmark.py -i -e dist build /path/to/project
# Bash
./trailmark.sh -i -e dist,build /path/to/project
When running with the -i
flag, TrailMark provides an interactive interface to select directories to exclude:
- Use numbers to navigate into directories
- Use
0
to go up to parent directory - Use
e
to exclude/include the current directory - Use
f
to finish selection and start processing - Use
q
to quit without making changes
Before:
function hello() {
console.log("Hello, world!");
}
After:
// Path: src/utils/greeting.js
function hello() {
console.log("Hello, world!");
}
While both versions provide the same functionality, there are some implementation differences:
- More portable across operating systems
- Better handling of different text encodings
- More maintainable and easier to extend
- Uses space-separated lists for exclusions
- Faster execution for large directories
- Better integration with Unix tools
- Uses native file system operations
- Uses comma-separated lists for exclusions
- Create a .trailmarkignore file to define your standard exclusions
- Run in interactive mode first to see the directory structure and decide what to exclude
- Use the
-a
flag when you need to process everything, ignoring .trailmarkignore - Check the script output for any skipped files or errors
- Make sure you have appropriate permissions for all directories you want to process
Feel free to submit issues and enhancement requests!