Skip to content

Instantly share code, notes, and snippets.

@ImBIOS
Last active July 15, 2024 06:48
Show Gist options
  • Save ImBIOS/044993843e29cd1f3e078478450a63b6 to your computer and use it in GitHub Desktop.
Save ImBIOS/044993843e29cd1f3e078478450a63b6 to your computer and use it in GitHub Desktop.
Automatically Add fill="currentColor" to SVG Files. This shell script recursively scans through a directory and its subdirectories to find all SVG files and adds fill="currentColor" to all path elements that don't already have a fill attribute. This is particularly useful for ensuring that SVG icons inherit the current text color when used in we…
#!/bin/bash
# Ensure the script runs in the directory where SVG files are located
cd /path/to/your/svg/files
# Loop through all SVG files in the current directory
for file in *.svg; do
# Add fill="currentColor" to each SVG file using sed
sed -i 's/<svg /<svg fill="currentColor" /g' "$file"
done
echo "fill=\"currentColor\" added to all SVG files."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment