init
This commit is contained in:
6
README.md
Normal file
6
README.md
Normal 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
40
reccat
Executable 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"
|
Reference in New Issue
Block a user