gemini/treer.sh

37 lines
815 B
Bash
Raw Normal View History

2024-11-16 14:56:27 -06:00
#!/bin/bash
# Check for directory argument
if [ -z "$1" ]; then
echo "Usage: $0 /path/to/directory filename.gmi"
exit 1
fi
# Define the directory you want to scan
DIRECTORY="$1"
# Output file
OUTPUT_FILE="$2"
# Start the .gmi file
echo "# Tree of files in $DIRECTORY" > "$OUTPUT_FILE"
echo "" >> "$OUTPUT_FILE"
# Function to recursively list files
list_files() {
local dir="$1"
local prefix="$2"
for file in "$dir"/*; do
if [ -d "$file" ]; then
echo "## $prefix${file##*/}" >> "$OUTPUT_FILE"
list_files "$file" "$prefix${file##*/}/"
elif [ -f "$file" ]; then
echo "=> $prefix${file##*/} ${file##*/}" >> "$OUTPUT_FILE"
fi
done
}
# Call the function
list_files "$DIRECTORY" ""
echo "Tree structure written to $OUTPUT_FILE"