Created
January 3, 2024 13:07
-
-
Save armchair-traveller/d9210b9858b2f6dc5611d5d84e7164fd to your computer and use it in GitHub Desktop.
File Content Extractor (to markdown)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Just run this straight in fish shell! | |
# Define the output file | |
set output_file "output.md" | |
# Empty the output file if it already exists | |
if test -f $output_file | |
echo "" > $output_file | |
end | |
# Find all files in the src directory and its subdirectories | |
find ./src -type f | while read -l file | |
# Extract the extension of the file | |
set extension (string match -r '\.([^.]+)$' -- $file)[2] | |
# Append the file path as a markdown header | |
echo "/$file" >> $output_file | |
echo "```$extension" >> $output_file | |
# Append the contents of the file | |
cat $file >> $output_file | |
# Close the code block and add two lines for spacing | |
echo "```" >> $output_file | |
echo "" >> $output_file | |
echo "" >> $output_file | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment