Skip to content

Instantly share code, notes, and snippets.

@shospodarets
Last active July 17, 2024 03:36
Show Gist options
  • Save shospodarets/fade28c8d398a3a86334 to your computer and use it in GitHub Desktop.
Save shospodarets/fade28c8d398a3a86334 to your computer and use it in GitHub Desktop.
Script finds all SCSS variables (e.g. $some_variable-NAME1) which are used in code only once (e.g. declaration or using variable from some framework). Tested on MAC and Linux.
#!/usr/bin/env bash
# HOW TO USE
# Save code to file
# Run as "SCRIPT_FILE_NAME SASS_DIRECTORY"
# e.g "./find_unused_variables.sh ./sass"
VAR_NAME_CHARS='A-Za-z0-9_-'
find "$1" -type f -name "*.scss" -exec grep -o "\$[$VAR_NAME_CHARS]*" {} ';' | sort | uniq -u
@DanielApt
Copy link

Worked like a charm, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment