Last active
August 16, 2018 06:15
-
-
Save atondwal/700285755a32aa49a48fa4f622a37639 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" |] | |
return () |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment