Skip to content

Instantly share code, notes, and snippets.

@idkrn123
Last active July 21, 2023 03:08
Show Gist options
  • Save idkrn123/bd5f3809800023709f3c3044a9f52fd1 to your computer and use it in GitHub Desktop.
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`.
#!/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