Created
July 29, 2019 14:56
-
-
Save lacostenycoder/f4ec2e4da09201e3ee922143f84adcfd to your computer and use it in GitHub Desktop.
Find used and unused environment variables in .env file
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
#!/usr/bin/env ruby | |
#Run this in the root of your local github repo to find used env vars located in .env file | |
vars = File.readlines('.env') | |
keys = vars.map{|e| e[/^\w+/]}.compact.sort | |
used_keys = keys.select{|k| !`git grep #{k}`.empty? rescue nil} | |
puts "THESE ARE USED IN THE PROJECT\n\n" | |
puts used_keys | |
puts "\nThese env vars NOT used in codebase\n\n" | |
puts keys - used_keys |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello, I propose ignoring the
.env
file itself from thegit grep
, or else everything is considered to be used in the project: