Skip to content

Instantly share code, notes, and snippets.

@lvnilesh
Created March 22, 2025 21:44
Show Gist options
  • Select an option

  • Save lvnilesh/67d10ecc72d13a6d6145fa1b91ebfb35 to your computer and use it in GitHub Desktop.

Select an option

Save lvnilesh/67d10ecc72d13a6d6145fa1b91ebfb35 to your computer and use it in GitHub Desktop.

Revisions

  1. lvnilesh created this gist Mar 22, 2025.
    33 changes: 33 additions & 0 deletions brightness-control
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    ```
    #!/bin/bash

    # Get current brightness level
    current_brightness=$(xrandr --verbose | grep -m 1 -i brightness | awk '{print $2}')

    # Define step size for brightness change
    step=0.1

    # Adjust brightness based on argument
    if [ "$1" = "up" ]; then
    new_brightness=$(echo "$current_brightness + $step" | bc)
    elif [ "$1" = "down" ]; then
    new_brightness=$(echo "$current_brightness - $step" | bc)
    else
    echo "Usage: $0 up|down"
    exit 1
    fi

    # Ensure brightness stays within 0.1 to 1.0 range
    if (( $(echo "$new_brightness < 0.1" | bc -l) )); then
    new_brightness=0.1
    elif (( $(echo "$new_brightness > 1.0" | bc -l) )); then
    new_brightness=1.0
    fi

    # Apply new brightness value
    xrandr --output DP-4 --brightness "$new_brightness"
    xrandr --output DP-0 --brightness "$new_brightness"

    # Optional: Display new brightness
    echo "Brightness set to: $new_brightness"
    ```