#!/bin/bash # Usage examples: # ./cat-md file1.txt file2.txt # Output multiple files as markdown # ./cat-md directory/ # Output all files in a directory # ./cat-md file.txt | xclip -selection clipboard # Copy output to X11 clipboard # ./cat-md file.txt | xsel --clipboard --input # Alternative using xsel for path in "$@"; do if [ -d "$path" ]; then # If it's a directory, call ourselves with each file in it (non-recursively) for file in "$path"/*; do if [ -f "$file" ]; then "$0" "$file" fi done elif [ -f "$path" ]; then # If it's a file, output the path and content echo "$path:" echo '```' cat "$path" echo echo '```' echo fi done