#!/bin/sh -e

set -u

usage() {
  cat <<__EOF__
display [ status | help ]

commands:
  [s]tatus   - Status of displays.
  [h]elp     - Show usage.
  up         - Turn up the brightness.
  down       - Turn down the brightness.
__EOF__
}

turn_up() {
  osascript -e 'tell application "System Events"' -e 'key code 144' -e ' end tell'
}

turn_down() {
  osascript -e 'tell application "System Events"' -e 'key code 145' -e ' end tell'
}

if [ "$#" -eq 0 ]; then
  usage
  exit 1
fi

case "$1" in
  -h | --help)
    usage
    exit 0
    ;;
  h | help)
    usage
    exit 0
    ;;
  s | status)
    system_profiler SPDisplaysDataType
    ;;
  up)
    turn_up
    ;;
  down)
    turn_down
    ;;
  *)
    usage
    exit 1
    ;;
esac
