#!/usr/bin/env bash

function SetKeyboardBrightness() {
  echo $1 | sudo tee /sys/class/leds/asus\:\:kbd_backlight/brightness
}

min_brightness="0"
max_brightness=$(cat /sys/class/leds/asus\:\:kbd_backlight/max_brightness)
current_brightness=$(cat /sys/class/leds/asus\:\:kbd_backlight/brightness)

case "$1" in
  "up")
    if [ "$current_brightness" != "$max_brightness" ]; then
      let 'current_brightness+=1'
    fi
    ;;

  "down")
    if [ "$current_brightness" != "$bin_brightness" ]; then
      let 'current_brightness-=1'
    fi
    ;;

  *)
    echo "Usage: $0 {up|down}"
    exit 1
    ;;
esac

SetKeyboardBrightness $current_brightness
