Created
November 19, 2025 18:21
-
-
Save GabrielVidal1/0597bacc7d7ceac5fbd501a98c9738e6 to your computer and use it in GitHub Desktop.
fcat, cat for llms
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # detect type based on extension | |
| get_type() { | |
| local file="$1" | |
| case "$file" in | |
| *.py) echo "python" ;; | |
| *.sh) echo "shell" ;; | |
| *.c) echo "c" ;; | |
| *.cpp|*.cc|*.cxx) echo "cpp" ;; | |
| *.js) echo "javascript" ;; | |
| *.jsx) echo "jsx" ;; | |
| *.ts) echo "typescript" ;; | |
| *.tsx) echo "tsx" ;; | |
| *.java) echo "java" ;; | |
| *.go) echo "go" ;; | |
| *.rb) echo "ruby" ;; | |
| *.php) echo "php" ;; | |
| *.html|*.htm) echo "html" ;; | |
| *.css) echo "css" ;; | |
| *.json) echo "json" ;; | |
| *.yaml|*.yml) echo "yaml" ;; | |
| *.md) echo "markdown" ;; | |
| *) detect_from_shebang "$file" ;; | |
| esac | |
| } | |
| # detect from shebang if no extension matched | |
| detect_from_shebang() { | |
| local file="$1" | |
| if [ -f "$file" ]; then | |
| local firstline | |
| firstline=$(head -n 1 "$file") | |
| case "$firstline" in | |
| *python*) echo "python" ;; | |
| *bash*|*sh) echo "shell" ;; | |
| *node*|*deno*) echo "javascript" ;; | |
| *ruby*) echo "ruby" ;; | |
| *php*) echo "php" ;; | |
| *perl*) echo "perl" ;; | |
| *go*) echo "go" ;; | |
| *) echo "text" ;; | |
| esac | |
| else | |
| echo "text" | |
| fi | |
| } | |
| # choose comment style | |
| get_comment_prefix() { | |
| local type="$1" | |
| case "$type" in | |
| python|shell|ruby|perl) echo "#" ;; | |
| *) echo "//" ;; | |
| esac | |
| } | |
| # collect files from args or stdin | |
| files=() | |
| if [ "$#" -gt 0 ]; then | |
| files=("$@") | |
| else | |
| while IFS= read -r line; do | |
| [ -n "$line" ] && files+=("$line") | |
| done | |
| fi | |
| for f in "${files[@]}"; do | |
| [ -d "$f" ] && { continue; } | |
| [ -f "$f" ] || { echo "Skipping missing file: $f" >&2; continue; } | |
| [ "$f" != "${files[0]}" ] && echo | |
| type=$(get_type "$f") | |
| prefix=$(get_comment_prefix "$type") | |
| echo "\`\`\`$type" | |
| echo "$prefix path: $f" | |
| cat "$f" | |
| echo "\`\`\`" # blank line separator | |
| done |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
fcat.sh
fcatprints files wrapped in Markdown code fences, with automatic language detection.I made this to easily put whole files (with their path) into LLMs.
Install
Make sure
~/.local/binis in yourPATH.Use