diff options
author | zachir <zachir@librem.one> | 2023-10-24 08:15:20 -0500 |
---|---|---|
committer | zachir <zachir@librem.one> | 2023-10-24 08:15:20 -0500 |
commit | 6bc13a61e63b5d0c049bd194f6d365f2f09d709c (patch) | |
tree | 261a826287a27963e78671cd5b9a354cb4d93c00 | |
parent | b0cedf115516103c9e02f1c4a506565da66aeb08 (diff) |
Including getopts, and defaults.
-rwxr-xr-x | bl | 122 |
1 files changed, 82 insertions, 40 deletions
@@ -2,46 +2,88 @@ ## Backlight controller generic: use either light or xbacklight -CMD=`crcparse bl` +#{{{ printhelp +printhelp () { + printf "Backlight control interface\n" + printf "bl -h\n" + printf "bl [-xX] [-idg]\n" + printf "bl [-xX] -I X\n" + printf "bl [-xX] -D X\n" + printf "bl [-xX] -s X\n" + printf "\t-i) \tincreases the backlight\n" + printf "\t-I) X\tincreases the backlight by X percent\n" + printf "\t-d) \tdecreases the backlight\n" + printf "\t-D) X\tdecreases the backlight by X percent\n" + printf "\t-s) X\tsets the backlight to X percent\n" + printf "\t-g) \tgets the backlight\n" + printf "\t-h) \tprints this help message.\n" + printf "\t-x) \tuse xbacklight instead of light.\n" + printf "\t-X) \tdon't use xbacklight instead of light.\n" +} +#}}} +#{{{ defaults +CMD="light" +ARG="get" +AMT="1" +#}}} + +#{{{ getopts2 +while getopts "hxXidgI:D:s:" o; do case "${o}" in + x) CMD="xbacklight" ;; + X) CMD="light" ;; + i) ARG="inc" ;; + d) ARG="dec" ;; + g) ARG="get" ;; + I) + ARG="inc" + AMT="$OPTARG" + ;; + D) + ARG="dec" + AMT="$OPTARG" + ;; + s) + ARG="set" + AMT="$OPTARG" + ;; + *) printhelp ;; +esac done +#}}} + +#{{{ main case "$CMD" in - "light") - case "$1" in - "-i") - light -A "${2:-1%}" - ;; - "-d") - light -U "${2:-1%}" - ;; - "-s") - light -S "$2" - ;; - "-g"|"") - light -G - ;; - "*") - printf "$CMD: $1 not understood. Treating it as a direct command." - light "$@" - ;; - esac - ;; - "xbacklight") - case "$1" in - "-i") - xbacklight -inc "${2:-1}" - ;; - "-d") - xbacklight -dec "${2:-1}" - ;; - "-s") - xbacklight -set "$2" - ;; - "-g"|"") - xbacklight -get - ;; - "*") - printf "$CMD: $1 not understood. Treating it as a direct command." - xbacklight "$@" - ;; - esac + "light") + case "$ARG" in + "inc") + light -A "$AMT%" + ;; + "dec") + light -U "$AMT%" + ;; + "set") + light -S "$AMT%" + ;; + "get") + light -G + ;; + esac + ;; + "xbacklight") + case "$ARG" in + "inc") + light -A "$AMT" + ;; + "dec") + light -U "$AMT" + ;; + "set") + light -S "$AMT" + ;; + "get") + light -G + ;; + esac + ;; esac +#}}} |