Created
April 14, 2021 20:24
-
-
Save atondwal/1fb835b9d5d577853f56f4e95d764fc8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env nix-shell | |
#! nix-shell -i runhaskell -p "haskellPackages.ghcWithPackages (pkgs: [pkgs.shqq])" | |
{-# LANGUAGE QuasiQuotes #-} | |
import System.ShQQ (sh) | |
import System.Environment (getArgs) | |
parseOp :: Num a => Char -> a -> a -> a | |
parseOp '+' = (+) | |
parseOp '-' = (-) | |
parseOp '=' = flip const | |
parseOp op = error $ "invalid operation: " ++ [op] | |
main = do | |
actBrightness <- read <$> readFile "/sys/class/backlight/intel_backlight/actual_brightness" | |
maxBrightness <- read <$> readFile "/sys/class/backlight/intel_backlight/max_brightness" | |
let curBrightness = actBrightness / maxBrightness | |
args <- concat <$> getArgs | |
if args == "-get" | |
then print $ round $ curBrightness * 100 | |
else do | |
(op:magn) <- [sh| echo ${args} | sed -e 's/-inc/+/g' -e 's/-dec/-/g' -e 's/-set/=/g'|] | |
let newBrightness = round $ (maxBrightness *) $ parseOp op curBrightness (read magn/100) :: Int | |
-- [sh| gksudo -\\- bash -c "echo ${newBrightness} > /sys/class/backlight/intel_backlight/brightness" |] | |
writeFile "/sys/class/backlight/intel_backlight/brightness" (show newBrightness) | |
return () |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment