This commit is contained in:
anon
2023-05-21 13:14:00 +02:00
commit 012faac38d
2 changed files with 46 additions and 0 deletions

6
README.md Normal file
View File

@ -0,0 +1,6 @@
# Reccat
Recursively cat files with their names echod.
Simple script coded by AI to aid coding with AI.
Came useful when working with Terraform for example.

40
reccat Executable file
View File

@ -0,0 +1,40 @@
#!/bin/bash
function _reqcat() {
local directory="$1"
local prefix="$ cat $1"
shopt -s globstar
for file in "$directory"/**; do
if [[ -f "$file" ]]; then
echo "${prefix}${file}"
if [[ $(file -b --mime-encoding "$file") == *"binary"* ]]; then
echo "\tSkipping binary file."
else
cat "$file"
fi
fi
done
}
# Example: ./recursive_list_files.sh /path/to/directory
if (( $# > 1 )); then
echo "Usage: $0 <directory>"
exit 1
fi
directory=""
if (( $# < 1)); then
directory="./"
else
directory="$1"
fi
if [[ ! -d "$directory" ]]; then
echo "Error: $directory is not a valid directory."
exit 1
fi
_reqcat "$directory"