Browse Source

Update brightness script to proper standard

master
Riyyi 4 years ago
parent
commit
3cf6fb84d9
  1. 2
      .config/polybar/modules
  2. 2
      .config/sxhkd/sxhkdrc
  3. 85
      .scripts/brictl.sh
  4. 43
      .scripts/brightnesscontrol.sh

2
.config/polybar/modules

@ -56,7 +56,7 @@ label-muted = %percentage%%
type = internal/backlight
card = intel_backlight
format = %{A3:$HOME/.scripts/brightnesscontrol.sh s 30:}%{A4:$HOME/.scripts/brightnesscontrol.sh u 10:}%{A5:$HOME/.scripts/brightnesscontrol.sh d 10:}<ramp> <label>%{A}%{A}%{A}
format = %{A3:$HOME/.scripts/brictl.sh s 30:}%{A4:$HOME/.scripts/brictl.sh i 10:}%{A5:$HOME/.scripts/brictl.sh d 10:}<ramp> <label>%{A}%{A}%{A}
format-foreground = ${colors.white-bright}
ramp-0 = %{T3}%{T-}

2
.config/sxhkd/sxhkdrc

@ -34,7 +34,7 @@ super + shift + w
# Screen brightness
super + {F2,F3}
brightnesscontrol.sh {down,up} 10
brictl.sh {dec,inc} 10
# Screenshot (fullscreen, selection, focused window)
{_,shift,super} + @Print

85
.scripts/brictl.sh

@ -0,0 +1,85 @@
#!/bin/sh
# Control the display brightness
# Depends: brightnessctl
help() {
B=$(tput bold)
U=$(tput smul)
N=$(tput sgr0)
cat << EOF
${B}NAME${N}
brictl.sh - control the display brightness
${B}SYNOPSIS${N}
${B}brictl.sh${N} [${U}OPTION${N}] [${U}COMMAND${N}] [<${U}ARG${N}>]
${B}DESCRIPTION${N}
${B}brictl.sh${N} uses brightnessctl to change the brightness of the system.
Commands can be truncated, i.e. "${B}brictl.sh s${N}" for "${B}brictl.sh set${N}"
Arguments need to be of numeric value.
${B}OPTIONS${N}
${B}-h${N} Display usage message and exit.
${B}COMMANDS${N}
${B}i${N} <${U}AMOUNT${N}>, ${B}inc${N} <${U}AMOUNT${N}>
Increase brightness by ${U}AMOUNT${N}, default of 5.
${B}d${N} <${U}AMOUNT${N}>, ${B}dec${N} <${U}AMOUNT${N}>
Decrease brightness by ${U}AMOUNT${N}, default of 5.
${B}s${N} <${U}LEVEL${N}>, ${B}set${N} <${U}LEVEL${N}>
Set brightness to ${U}LEVEL${N}, default of 30.
${B}g${N}, ${B}get${N}
Get brightness level.
EOF
}
# Exit if no option is provided
[ "$#" -eq 0 ] && help && exit 1
SCRIPT="$(basename "$0")"
# Option handling
while getopts ':h?' opt; do
case $opt in
h)
help
exit 0
;;
\?)
echo "$SCRIPT: invalid option '$OPTARG'"
echo "Try '$SCRIPT -h' for more information."
exit 1
;;
esac
done
# Command handling
shift $((OPTIND - 1))
case "$1" in
i*)
NUM=${2:-5}
brightnessctl -q s +"$NUM"%
;;
d*)
NUM=${2:-5}
brightnessctl -q s "$NUM"%-
;;
s*)
NUM=${2:-30}
brightnessctl -q s "$NUM"%
;;
g*)
brightnessctl | awk '/%/ {print substr($4, 2, length($4) - 3)}'
;;
*)
echo "$SCRIPT: invalid command '$1'"
echo "Try '$SCRIPT -h' for more information."
exit 1
;;
esac

43
.scripts/brightnesscontrol.sh

@ -1,43 +0,0 @@
#!/bin/sh
# General brightness management
RELOAD="$HOME/.scripts/panel/brightness.sh"
[ -z "$2" ] && NUM="5" || NUM="$2"
help() {
B=$(tput bold)
N=$(tput sgr0)
cat << EOF
${B}NAME${N}
brightnesscontrol - control the volume of the system
${B}SYNOPSIS${N}
./brightnesscontrol.sh <command> [<arg1>]
${B}DESCRIPTION${N}
Commands can be truncated, i.e.
\`${B}brightnesscontrol.sh s${N}\` for \`${B}brightnesscontrol.sh set${N}\`
Arguments need to be of numeric value.
${B}COMMANDS${N}
${B}u*, up <amount>${N}
${B}d*, down <amount>${N}
${B}s*, set <volume>${N}
${B}g*, getbrightness${N}
EOF
}
case "$1" in
u*) brightnessctl -q s +"$NUM"% ; $RELOAD ;;
d*) brightnessctl -q s "$NUM"%- ; $RELOAD ;;
s*) brightnessctl -q s "$NUM"% ; $RELOAD ;;
g*) brightnessctl | awk '/%/ {print substr($4, 2, length($4) - 3)}' ;;
*) help ;;
esac
Loading…
Cancel
Save