Last active
March 19, 2023 22:25
-
-
Save danielhaim1/96594f1e6c6569c72a44ec2e9cc33378 to your computer and use it in GitHub Desktop.
This script searches for unused Sass variables in a given directory by finding occurrences and counting them. Could benefit from optimization.
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 | |
# Usage: ./unused.sh | |
read -p "Enter a directory: " dir | |
if [ ! -d "$dir" ]; then | |
echo "Not a valid directory." | |
exit 1 | |
fi | |
echo "Finding unused variables. This might take some time..." | |
vars=$(grep -orh '\$\w\+' "$dir"/*.scss | sort -u) | |
for var in $vars; do | |
count=$(grep -roh "$var" "$dir"/*.scss | wc -l) | |
if [ "$count" -eq "1" ]; then | |
printf "Occurrences of \"%s\": %s\n" "$var" "$count" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment