Last active
July 21, 2023 03:08
-
-
Save idkrn123/bd5f3809800023709f3c3044a9f52fd1 to your computer and use it in GitHub Desktop.
A simple command-line helper I use very often. Recursively loop through all files in the specified directory and its subdirectories, wrapping their contents in triple backticks. Clipboard automation with `xclip`.
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
#!/bin/bash | |
function process_directory { | |
for file in "$1"/*; do | |
if [ -d "$file" ]; then | |
process_directory "$file" | |
elif [ -f "$file" ]; then | |
/bin/cat << EOF | |
${file}: | |
\`\`\` | |
$(cat "${file}") | |
\`\`\` | |
EOF | |
if command -v xclip >/dev/null 2>&1; then | |
cat "${file}" | xclip -selection clipboard | |
echo "Copied ${file} contents to clipboard" | |
else | |
echo "xclip is not installed. Please install xclip to enable clipboard copying." | |
fi | |
fi | |
done | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment