···11-{ pkgs, ... }:
22-31{
44- home.packages = [
55- (pkgs.writeShellScriptBin "adjust-brightness" ''
66-#!/bin/sh
22+ pkgs ? import <nixpkgs> { },
33+}:
7488-# Check if the correct number of arguments is provided
99-if [ "$#" -ne 2 ]; then
1010- echo "Usage: $0 <display_number> <brightness_value_or_adjustment>"
1111- exit 1
1212-fi
55+pkgs.writeShellScriptBin "adjust-brightness" ''
66+ #!/bin/sh
1371414-DISPLAY=$1
1515-VALUE_OR_ADJUSTMENT=$2
88+ # Check if the correct number of arguments is provided
99+ if [ "$#" -ne 2 ]; then
1010+ echo "Usage: $0 <display_number> <brightness_value_or_adjustment>"
1111+ exit 1
1212+ fi
16131717-# Get the current brightness value
1818-CURRENT=$(ddcutil getvcp 10 --display=$DISPLAY | grep -oP 'current value =\s*\K\d+')
1414+ DISPLAY=$1
1515+ VALUE_OR_ADJUSTMENT=$2
19162020-# Check if the adjustment is relative (+ or -)
2121-if [[ "$VALUE_OR_ADJUSTMENT" =~ ^[+-] ]]; then
2222- # Calculate the new brightness value
2323- NEW_BRIGHTNESS=$((CURRENT + VALUE_OR_ADJUSTMENT))
2424-else
2525- # Set the brightness to the specified value
2626- NEW_BRIGHTNESS=$VALUE_OR_ADJUSTMENT
2727-fi
1717+ # Get the current brightness value
1818+ CURRENT=$(ddcutil getvcp 10 --display=$DISPLAY | grep -oP 'current value =\s*\K\d+')
28192929-# Ensure the new brightness is within the valid range (0-100)
3030-if [ "$NEW_BRIGHTNESS" -lt 0 ]; then
3131- NEW_BRIGHTNESS=0
3232-elif [ "$NEW_BRIGHTNESS" -gt 100 ]; then
3333- NEW_BRIGHTNESS=100
3434-fi
2020+ # Check if the adjustment is relative (+ or -)
2121+ if [[ "$VALUE_OR_ADJUSTMENT" =~ ^[+-] ]]; then
2222+ # Calculate the new brightness value
2323+ NEW_BRIGHTNESS=$((CURRENT + VALUE_OR_ADJUSTMENT))
2424+ else
2525+ # Set the brightness to the specified value
2626+ NEW_BRIGHTNESS=$VALUE_OR_ADJUSTMENT
2727+ fi
2828+2929+ # Ensure the new brightness is within the valid range (0-100)
3030+ if [ "$NEW_BRIGHTNESS" -lt 0 ]; then
3131+ NEW_BRIGHTNESS=0
3232+ elif [ "$NEW_BRIGHTNESS" -gt 100 ]; then
3333+ NEW_BRIGHTNESS=100
3434+ fi
35353636-# Set the new brightness value
3737-ddcutil setvcp 10 $NEW_BRIGHTNESS --display=$DISPLAY
3636+ # Set the new brightness value
3737+ ddcutil setvcp 10 $NEW_BRIGHTNESS --display=$DISPLAY
38383939-echo "Brightness for display $DISPLAY changed to $NEW_BRIGHTNESS"
4040- '')
4141- ];
4242-}
3939+ echo "Brightness for display $DISPLAY changed to $NEW_BRIGHTNESS"
4040+''