-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathibm-acpi
106 lines (86 loc) · 2 KB
/
ibm-acpi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/bin/sh
# Dependencies: sed, grep
# Directly accesses the files in /proc/acpi/ibm/, so we don't get any
# of that complaining about RandR versions and whatever else.
IBM_DIR='/proc/acpi/ibm'
# Grab a value from one of the procfiles.
#
# Usage: ibm-value-get FILE VALUENAME
ibm-value-get()
{
if [ -n "${2}" ] ; then
# A contains full copy of the file in question
local A="$(<${IBM_DIR}/${1})"
# B ought to be A with everything before the desired value stripped
local B="${A/*${2}:+([ ])/}"
# C ought to be B with everything after the desired value stripped
local C="${B/
*/}"
builtin echo "${C}"
# "/^${2}/!D;s/^[^:]\+\W\+\(.*\)/\1/g" "${IBM_DIR}/${1}"
else
cat "${IBM_DIR}/${1}"
fi
}
# Usage: ibm-value-set FILE VALUENAME VALUE
ibm-value-set()
{
local CV NV A B
A=( "${@}" )
B="${A[${#} - 1]}"
if echo "${B}" | grep -qE '(\+|\-)' ; then
CV=$(ibm-value-get ${1} ${2})
NV=$(( $CV + ( ${B} ) ))
else
NV=${B}
fi
echo ${2} ${NV} > "${IBM_DIR}/${1}"
}
ibm-value()
{
local HELP=\
"Usage: ${FUNCNAME} ITEM [ATTRIBUTE [VALUE]]
Call ibm-value-get, or ibm-value-set if VALUE is specified. See also
\`ibm-list-values'."
case "$#" in
0 ) builtin echo -e "$HELP"; return 1;; # Not enough args
1 | 2 )
case "$1" in
-h | --help )
builtin echo -e "$HELP"
return 0
;;
esac
ibm-value-get "${@}"
return $?
;;
esac
ibm-value-set "${@}"
return $?
}
ibm-list-values()
{
local HELP=\
"Usage: ${FUNCNAME} [ITEM]
List the available items. If an item name is given, list the
attributes it has, separated by line feeds."
if [ "$#" -gt 0 ] ; then
case "$1" in
-h | --help )
builtin echo -e "$HELP"
return 0
;;
esac
# List the values within a certain file
sed -e 's/:.*//g' < "${IBM_DIR}/${1}" | uniq
else
# List all available files
ls "${IBM_DIR}"
fi
}
ibm-completion()
{
export COMPREPLY=( $(ibm-list-values) )
}
# alias ibm-fan-level='ibm-value fan level'
# alias ibm-fan-level='ibm-value fan level'