Skip to content

Instantly share code, notes, and snippets.

@sent-hil
Last active December 11, 2015 18:28
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 sent-hil/4641437 to your computer and use it in GitHub Desktop.
Save sent-hil/4641437 to your computer and use it in GitHub Desktop.
zsh function to show specs to code ratio in a rails folder, anything over 0.75 is good.
prompt_rspec_stats() {
if [[ ((-d app || -d lib) && -d spec) ]]; then
if [[ (-d app) ]]; then
local app=`wc -l app/**/*.rb | grep -oE "[0-9]+" | tail -n 1`
else
local app=`wc -l lib/**/*.rb | grep -oE "[0-9]+" | tail -n 1`
fi
local spec=$((`wc -l spec/**/*.rb | grep -oE "[0-9]+" | tail -n 1`))+0.01
local ratio=`printf "%.2f\n" $((spec/app))`
[[ ratio -ge 0.75 ]] && prompt_segment cyan black "$ratio"
[[ ratio -ge 0.5 && ratio -lt 0.75 ]] && prompt_segment yellow black "$ratio"
[[ ratio -lt 0.5 ]] && prompt_segment red black "$ratio"
fi
}
@dritter
Copy link

dritter commented Apr 2, 2015

Nice piece of code! Just ported it to powerlevel9k-Theme:
Powerlevel9k/powerlevel9k#19

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