Skip to content

Instantly share code, notes, and snippets.

@danielhaim1
Last active March 19, 2023 22:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielhaim1/96594f1e6c6569c72a44ec2e9cc33378 to your computer and use it in GitHub Desktop.
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.
#!/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