{pkgs, ...}: let
  brightness-ctrl = pkgs.writeShellScriptBin "brightness-ctrl" ''
    #!/bin/bash

    # Function to check if ddcutil is running
    is_ddcutil_running() {
      pgrep ddcutil > /dev/null 2>&1
    }

    # Loop until ddcutil is not running
    while is_ddcutil_running; do
      sleep 1
    done

    # Determine action based on argument
    case "$1" in
      up)
        ddcutil --display 2 setvcp 10 + 10 && ddcutil --display 1 setvcp 10 + 10
        ;;
      down)
        ddcutil --display 2 setvcp 10 - 10 && ddcutil --display 1 setvcp 10 - 10
        ;;
      full)
        ddcutil --display 2 setvcp 10 100 && ddcutil --display 1 setvcp 10 100
        ;;
      status)
        ddcutil --display 2 getvcp 10 && ddcutil --display 1 getvcp 10
        ;;
      set)
        if [ -z "$2" ]; then
          echo "Usage: brightness-ctrl set <value>"
          exit 1
        fi
        ddcutil --display 2 setvcp 10 $2 && ddcutil --display 1 setvcp 10 $2
        ;;
      *)
        echo "Usage: brightness-ctrl {up|down|full|status|set}"
        exit 1
        ;;
    esac
  '';
in {
  environment.systemPackages = [brightness-ctrl];
}
