<commit_before>#!/bin/sh
#
# $Header: /etc/acpi/default.sh                          Exp $
# $Author: (c) 2012-2015 -tclover <<EMAIL>> Exp $
# $License: MIT (or 2-clause/new/simplified BSD)         Exp $
# $Version: 2015/02/14 21:09:26                          Exp $
#

log() {
	logger -p daemon.notice "acpi: $*"
}
#
# Unhandled Events helper
#
uhd() {
	log "event unhandled: $*"
}
#
# (Intel GPU) Brightness helper
#
btn() {
	local BTF=/sys/class/backlight/intel_backlight/brightness
	[ -e $BTF ] || return
	local BTM=$(cat /sys/class/backlight/intel_backlight/max_brightness)
	local BTN=$(cat $BTF) NEW=0 STP=24

	case "$1" in
		up)   NEW=$(($BTN + $STP));;
		down) NEW=$(($BTN - $STP));;
		*)    return;;
	esac
	if [ $NEW -lt 0 ]; then
		NEW=0
	elif [ $NEW -gt $BTM ]; then
		NEW=$BTM
	fi
	echo $NEW >$BTF
}

set $*
group=${1%/*}
action=${1#*/}
device=$2
id=$3
value=$4

[ -d /dev/snd ] && alsa=true || alsa=false
[ -d /dev/oss ] && oss=true  || oss=false
amixer="amixer -q set Master"
ossmix="ossmix -- vmix0-outvol"

case $group in
	ac_adapter)
		case $value in
			*0) hprofile power.bat;;
			*1) hprofile power.adp;;
			*) uhd $*;;
		esac
		;;
	battery)
		case $value in
			*0|*1) hprofile power.adp;;
			*) uhd $*;;
		esac
		;;
	button)
		case $action in
			lid)
				case "$id" in
					close) hibernate-ram;;
					open) hprofile power;;
					*) uhd $*;;
				esac
				;;
			power) shutdown -H now;;
			sleep) hibernate-ram;;
			mute) 
				$alsa && $amixer toggle;;
			volumeup) 
				$alsa && $amixer 3dB+
				$oss && $ossmix +3;;
			volumedown) 
				$alsa && $amixer 3dB-
				$oss && $ossmix -3;;
			*) uhd $*;;
		esac
		;;
	cd)
		case $action in
			play|stop|next|prev) :;;
			*) uhd $*;;
		esac
		;;
	jack)
		case $id in
			*plug) :;;
			*) uhd $*;;
		esac
		;;
	video)
		case $action in
			displayoff) :;;
			brightness*) btn ${action#brightness};;
			*) uhd $*;;
		esac
		;;
	*) uhd $*;;
esac

unset alsa oss amixer ossmix group action device id

#
# vim:fenc=utf-8:ft=sh:ci:pi:sts=0:sw=4:ts=4:
#<commit_msg>etc/acpi/default.sh: Major refactorization and clean up<commit_after>#!/bin/sh
#
# $Header: /etc/acpi/default.sh                          Exp $
# $Author: (c) 2012-2015 -tclover <<EMAIL>> Exp $
# $License: MIT (or 2-clause/new/simplified BSD)         Exp $
# $Version: 2015/02/14 21:09:26                          Exp $
#

log_event() {
	logger -p daemon.notice "acpi: $*"
}
#
# Unhandled Events helper
#
unhandled_event() {
	log_event "event unhandled: $*"
}
#
# (Intel GPU) Brightness helper
#
brightness() {
	local cur FILE max step
	FILE=/sys/class/backlight/intel_backlight/brightness
	[ -e $FILE ] || return
	cur="$(cat $FILE)" max="$(cat ${FILE%/*}/max_brightness)"
	step="$(($max / 20 ))"

	case "$1" in
		(*up)   new="$(($cur + $step))";;
		(*down) new="$(($cur - $step))";;
		(*)    return;;
	esac
	if [ "$new" -lt 0 ]; then
		new=0
	elif [ "$new" -gt "$max" ]; then
		new="$max"
	fi
	echo "$new" >$FILE
}

set $*
group="${1%/*}" action="${1#*/}"
device="$2" id="$3" value="$4"

[ -d /dev/snd ] && alsa=true || alsa=false
[ -d /dev/oss ] && oss=true  || oss=false
amixer="amixer -q set Master"
ossmix="ossmix -- vmix0-outvol"

case "$group" in
	(ac_adapter)
		case "$value" in
			(*0) hprofile power.bat ;;
			(*1) hprofile power.adp ;;
			(*) unhandled_event "$@";;
		esac
		;;
	(battery)
		case "$value" in
			(*[01]) hprofile power.adp;;
			(*) unhandled_event "$@"  ;;
		esac
		;;
	button)
		case "$action" in
			(lid)
				case "$id" in
					(close) hibernate-ram   ;;
					(open) hprofile power   ;;
					(*) unhandled_event "$@";;
				esac
				;;
			(power) shutdown -H now;;
			(sleep) hibernate-ram  ;;
			(mute) 
				$alsa && $amixer toggle;;
			(volumeup) 
				$alsa && $amixer 3dB+ ||
				($oss && $ossmix +3);;
			(volumedown) 
				$alsa && $amixer 3dB- ||
				($oss && $ossmix -3);;
			(*) unhandled_event "$@";;
		esac
		;;
	(cd)
		case "$action" in
			(play|stop|next|prev)   ;;
			(*) unhandled_event "$@";;
		esac
		;;
	(jack)
		case "$id" in
			(*plug) ;;
			(*) unhandled_event "$@";;
		esac
		;;
	(video)
		case "$action" in
			(displayoff) ;;
			(brightness*) brightness "$action";;
			(*) unhandled_event "$@";;
		esac
		;;
	(*) unhandled_event "$@";;
esac
unset alsa oss amixer ossmix group action device id

#
# vim:fenc=utf-8:ft=sh:ci:pi:sts=2:sw=2:ts=2:
#
{'fraction_non_alphanumeric': 0.20770480389881643, 'fraction_numerical': 0.02158273381294964, 'mean_word_length': 2.705932932072227, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '875135', 'n_tokens_mistral': 2107, 'n_tokens_neox': 1822, 'n_words': 403}