bin/props @ 93820aa446f2

Make bash prompt more recognizable
author Steve Losh <steve@stevelosh.com>
date Fri, 24 Jan 2020 12:34:37 -0500
parents a81cac75b4d3
children d9ee2c4aa85b
#!/usr/bin/env bash

set -euo pipefail

OPTS=$(getopt --options hd:pP --long help,decimals:,percent,no-percent -n "$0" -- "$@")
eval set -- "$OPTS"

DECIMALS='5'
MUL='1.0'

while true; do
  case "$1" in
    -h | --help )
        echo "USAGE: $0 [-h|--help] [-n N | --decimals N] [--percent | --no-percent]"
        exit 0 ;;
    -d | --decimals )   DECIMALS="$2"; shift 2 ;;
    -p | --percent )    MUL='100.0';   shift ;;
    -P | --no-percent ) MUL='1.0';     shift ;;
    -- ) shift; break ;;
    * ) break ;;
  esac
done

awk '
    { c[$0]++ }
END { for (l in c) printf("%.'"$DECIMALS"'f %s\n", c[l] / NR * '"$MUL"', l) }
'