You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
804 B
26 lines
804 B
#!/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 |