about summary refs log tree commit diff
path: root/nixos/scripts/get-brightness
diff options
context:
space:
mode:
Diffstat (limited to 'nixos/scripts/get-brightness')
-rwxr-xr-xnixos/scripts/get-brightness22
1 files changed, 22 insertions, 0 deletions
diff --git a/nixos/scripts/get-brightness b/nixos/scripts/get-brightness
new file mode 100755
index 0000000..4531c16
--- /dev/null
+++ b/nixos/scripts/get-brightness
@@ -0,0 +1,22 @@
+#!/bin/sh
+
+# Get the current brightness level as a percentage
+brightness=$(brightnessctl g)
+max_brightness=$(brightnessctl m)
+
+# Perform float division and store the result with 2 decimal points
+result=$(awk "BEGIN { printf \"%.2f\", $brightness / $max_brightness }")
+
+# Convert the result to a percentage (multiply by 100) and round to the nearest whole number
+percentage=$(awk "BEGIN { printf \"%.0f\", $result * 100 }")
+
+# Set the icon based on the brightness level
+if [ $percentage -le 33 ]; then
+    icon="󰃞"
+elif [ $percentage -le 66 ]; then
+    icon="󰃟"
+else
+    icon="󰃠"
+fi
+
+echo "$icon $percentage%"