path-printer
v1.0.7
Published
PathPrinter is a CLI tool that reads one or more files and prints the content, with the file path as a comment on the first line. It can handle full file paths or recursively search for files in the current directory and its subdirectories based on the fi
Downloads
4
Readme
PathPrinter
PathPrinter is a CLI tool that reads one or more files and prints the content, with the file path as a comment on the first line. It can handle full file paths or recursively search for files in the current directory and its subdirectories based on the file name provided.
Installation
You can install PathPrinter globally using npm:
npm install -g path-printer
Usage
1. Single File:
You can provide either the full file path or just the file name. If a full path is provided, PathPrinter will output the file content directly. If only the file name is provided, it will recursively search for the file from the current directory.
pathprinter path/to/file.tsx
Or, if only the file name is provided:
pathprinter file.tsx
If the file is found, the output will look like:
// /absolute/path/to/file.tsx
<file content here>
2. Multiple Files:
You can specify multiple file paths or file names separated by commas. PathPrinter will either output the files directly (if paths are provided) or recursively search for them (if names are provided).
pathprinter path/to/file1.tsx,path/to/file2.tsx
If the files are found, the output will look like this:
// /absolute/path/to/file1.tsx
<file1 content here>
// /absolute/path/to/file2.tsx
<file2 content here>
You can also mix file paths and file names:
pathprinter path/to/file1.tsx,file2.tsx
If the file name is found after a recursive search, the content will be displayed as expected.
3. Handling Multiple Files with the Same Name:
If multiple files with the same name exist in different directories, PathPrinter will prompt you to select which file you want to output.
Example:
pathprinter index.tsx
Output:
Multiple files found:
1: /project/src/pages/index.tsx
2: /project/src/components/header/index.tsx
3: /project/src/admin/index.tsx
Please select the file number:
You can then select the appropriate file by entering the corresponding number (e.g., 1
).
4. Error Handling:
- If a provided path or file name is not found, PathPrinter will notify you that the file could not be located.
- If invalid input or file names are provided, the tool will return an error message and exit.
License
MIT