stdin-glob
v1.4.0
Published
Expand glob patterns and output file contents.
Downloads
697
Maintainers
Readme
stdin-glob
A simple CLI tool that expands glob patterns and outputs file contents or paths. Perfect for quickly previewing multiple files matching a pattern.
Why?
This tool solves a common pain point: aggregating file contents into a single, coherent output. Whether you're doing code reviews, documentation, or working with LLMs, having to manually copy-paste multiple files is tedious and error-prone.
I created this for my personal workflow when working with Large Language Models (LLMs). Combined with clipboard tools, it lets me instantly gather specific project context:
stdin-glob "src/**/*.ts" "src/**/*.tsx" | pbcopy # On macOS
# or
stdin-glob "src/**/*.js" | xclip -selection clipboard # On LinuxThis pipes all relevant TypeScript/TSX files directly into my clipboard, ready to paste into ChatGPT, Claude, or any other LLM. Perfect for getting targeted, comprehensive context without the friction of opening and copying files one by one.
Features
- Expand glob patterns to find matching files
- Output file contents with syntax highlighting markers
- Limit output to a specific number of lines per file with
--max-lines - Show line numbers with
--line-numbersfor better code reference - Auto-copy output directly to clipboard with
--copyflag - Support for absolute or relative paths
- Option to show only file paths without content
- Intelligent handling of binary files - shows metadata instead of attempting to display unreadable content
- Automatic .gitignore filtering - respects your project's ignore rules by default
- Written in TypeScript
Installation
npm install -g stdin-globUsage
stdin-glob [options] [patterns...]Options
| Option | Description |
| --------------------- | --------------------------------------------------------------------------- |
| --no-content | Do not show file contents, only list matching paths |
| --absolute | Show absolute paths for entries |
| -c, --copy | Copy the output to clipboard instead of printing to console |
| -m, --max-lines <n> | Show only the first N lines of each file (shows full file if omitted) |
| -n, --line-numbers | Display line numbers next to each line, like in IDE sidebars |
| --no-gitignore | Disable .gitignore filtering (include files that would normally be ignored) |
| -V, --version | Output the version number |
| -h, --help | Display help information |
Arguments
| Argument | Description |
| ---------- | ------------------------------------------ |
| patterns | Glob patterns to match files (one or more) |
Pattern Syntax
This tool uses fast-glob for pattern matching, which supports the feature set of picomatch. For detailed information about available globbing features and syntax options, refer to the picomatch globbing features documentation.
Examples
Basic usage
Display contents of all JavaScript files with syntax highlighting markers:
stdin-glob "src/**/*.js" --content
# or
stdin-glob "src/**/*.js"Output:
```js
// src/index.js
console.log('Hello, world!');
```
```js
// src/utils/helpers.js
function add(a, b) {
return a + b;
}
```Limit lines per file
Show only the first 10 lines of each TypeScript file - perfect for quick overviews:
stdin-glob "src/**/*.ts" --max-lines 10Output:
```ts
// src/index.ts
import { Command } from 'commander';
import { version } from '../package.json';
import { readFile } from 'fs/promises';
import glob from 'fast-glob';
import path from 'path';
import clipboard from 'clipboardy';
// ... (23 more lines truncated)
```Show line numbers
Display line numbers alongside the code, just like in your editor:
stdin-glob "src/**/*.js" --line-numbersOutput:
```js
// src/index.js
1 | import { Command } from 'commander';
2 | import { version } from '../package.json';
3 | import { readFile } from 'fs/promises';
4 | import glob from 'fast-glob';
5 | import path from 'path';
```Combine with line limits
Get a preview with line numbers for better context:
stdin-glob "src/**/*.ts" --max-lines 5 --line-numbersOutput:
```ts
// src/index.ts
1 | import { Command } from 'commander';
2 | import { version } from '../package.json';
3 | import { readFile } from 'fs/promises';
4 | import glob from 'fast-glob';
5 | import path from 'path';
// ... (23 more lines truncated)
```Copy to clipboard
Copy all TypeScript file contents directly to clipboard:
stdin-glob "src/**/*.ts" --copyThis will copy the formatted output to your clipboard without printing to console. You'll see a confirmation message:
-> Output copied to clipboard successfully!Now you can paste (Ctrl+V or Cmd+V) anywhere - perfect for sharing code in pull requests, documentation, or with LLMs.
Only list files
List all TypeScript files in the src directory without content:
stdin-glob "src/**/*.ts" --no-contentOutput:
src/index.ts
src/utils/helpers.ts
src/types/index.tsMultiple patterns
Match files with different extensions:
stdin-glob "src/**/*.ts" "src/**/*.js" --contentAbsolute paths
Show absolute paths instead of relative ones:
stdin-glob "src/**/*.ts" --absolute --no-contentOutput:
/home/pedrito/project/src/index.ts
/home/pedrito/project/src/utils/helpers.ts
/home/pedrito/project/src/types/index.tsBinary file handling
When encountering binary files (like images, compiled binaries, etc.), the tool safely displays metadata instead of attempting to show unreadable content:
```png
// assets/logo.png
// [BINARY FILE] - Size: 0.024 MB
```Integration with other commands
Use with grep to search for specific content:
stdin-glob "src/**/*.ts" | grep "function"Or combine with other clipboard tools for maximum flexibility:
# Copy without the confirmation message
stdin-glob "src/**/*.ts" --no-content | pbcopy
# Preview first, then copy if it looks good
stdin-glob "src/**/*.ts" --content
stdin-glob "src/**/*.ts" --copy.gitignore Support
By default, stdin-glob automatically respects your project's .gitignore rules. This means files and directories listed in .gitignore won't appear in the output. This is especially useful when you want to avoid including build artifacts, dependencies, or environment files in your context.
The gitignore pattern matching implementation is based on the official gitignore pattern format documentation, ensuring compatibility with how git itself handles ignore rules.
Including ignored files
If you need to include files that would normally be ignored, use the --no-gitignore flag:
stdin-glob "dist/**/*.js" --no-gitignoreThis disables all .gitignore filtering and includes every file matching your patterns.
