Skip to content

Instantly share code, notes, and snippets.

@fusion809
Last active February 8, 2026 12:52
Show Gist options
  • Select an option

  • Save fusion809/792853d1f26679eef86fc9f8735ce096 to your computer and use it in GitHub Desktop.

Select an option

Save fusion809/792853d1f26679eef86fc9f8735ce096 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# Capture all available commands
commlist=$(compgen -c | sort -u | xargs -n 100 brl which 2>/dev/null)
nocomm=$(echo "$commlist" | tr ' ' '\n' | wc -l)
# Run calculation in R
function Rcalc {
out=$(R -q -e "$1")
echo "$out" | head -n 2 | tail -n 1 | sed -E 's/^\[1\]\s//g'
}
# Get the list of strata
stratList=$(brl list | grep -v bedrock; echo global)
stratList=$(echo "$stratList" | tr ' ' '\n' | sort -u)
# Print table header
printf "%-10s | %10s\n" "Source" "% of commands"
printf "%s\n" "-----------+---------------"
# Iterate and calculate percentages
for s in $stratList; do
no=$(echo "$commlist" | tr ' ' '\n' | grep "$s" | wc -l)
perc=$(Rcalc "100*$no/$nocomm")
printf "%-10s | %10.6f%%\n" "${s^}" "$perc"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment