Created
September 10, 2024 22:01
-
-
Save larkinwc/7b601fdea6ef5386c054e2719d747c58 to your computer and use it in GitHub Desktop.
Bash script to copy all .md in the current directory. Useful to have Claude summarize notes from Obsidian
This file contains hidden or 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 | |
# Create a temporary file | |
temp_file=$(mktemp) | |
# Concatenate all non-empty .md files in the current directory, adding titles and separators | |
for file in *.md; do | |
if [ -f "$file" ] && [ -s "$file" ] && ! [ -z "$(grep -v '^[[:space:]]*$' "$file")" ]; then | |
echo -e "\n====== $file ======\n" >> "$temp_file" | |
cat "$file" >> "$temp_file" | |
echo -e "\n" >> "$temp_file" | |
fi | |
done | |
# Function to check if running in WSL | |
is_wsl() { | |
if [ -f /proc/version ]; then | |
if grep -qi microsoft /proc/version; then | |
return 0 | |
fi | |
fi | |
return 1 | |
} | |
# Copy the concatenated content to clipboard | |
if is_wsl; then | |
# Running in WSL, use clip.exe | |
cat "$temp_file" | clip.exe | |
echo "Copied to Windows clipboard using clip.exe" | |
elif command -v xclip > /dev/null; then | |
xclip -selection clipboard < "$temp_file" | |
echo "Copied to clipboard using xclip" | |
elif command -v pbcopy > /dev/null; then | |
pbcopy < "$temp_file" | |
echo "Copied to clipboard using pbcopy" | |
elif command -v clip > /dev/null; then | |
clip < "$temp_file" | |
echo "Copied to clipboard using clip" | |
else | |
echo "Error: No suitable clipboard command found." | |
rm "$temp_file" | |
exit 1 | |
fi | |
# Remove the temporary file | |
rm "$temp_file" | |
echo "All non-empty .md files have been concatenated with titles, and the result has been copied to the clipboard." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment