Feat: CPU, memory, backlight and volume modules
This commit is contained in:
parent
01ee5fba93
commit
08dc3a58d3
20
module/bl
Executable file
20
module/bl
Executable file
@ -0,0 +1,20 @@
|
||||
#!/bin/bash
|
||||
|
||||
mod_bl () {
|
||||
# Customizable configuration constants
|
||||
local -r DEFAULT_PRE=' '
|
||||
local -r DEFAULT_SUF='%'
|
||||
|
||||
local -r pre="${1-${DEFAULT_PRE}}"
|
||||
local -r suf="${2-${DEFAULT_SUF}}"
|
||||
|
||||
local bl_file bl max_bl_file max_bl
|
||||
|
||||
bl_file="$(find /sys/class/backlight/*/brightness | head -n 1)"
|
||||
max_bl_file="$(dirname "${bl_file}")/max_brightness"
|
||||
read -r bl < "${bl_file}"
|
||||
read -r max_bl < "${max_bl_file}"
|
||||
# Use printf to do floating point arithmetic
|
||||
printf '%b%3.0f%b' "${pre}" "$((bl * 1000 / max_bl))e-1" "${suf}"
|
||||
}
|
||||
|
15
module/cpu
Executable file
15
module/cpu
Executable file
@ -0,0 +1,15 @@
|
||||
#!/bin/bash
|
||||
|
||||
mod_cpu () {
|
||||
# Customizable configuration constants
|
||||
local -r DEFAULT_PRE=' '
|
||||
local -r DEFAULT_SUF=''
|
||||
|
||||
local -r pre="${1-${DEFAULT_PRE}}"
|
||||
local -r suf="${2-${DEFAULT_SUF}}"
|
||||
|
||||
printf '%b' "${pre}"
|
||||
ps --no-headers -A -o %cpu | awk '{cpu = cpu + $1} END {printf "%3.0f", cpu}'
|
||||
printf '%b' "${suf}"
|
||||
}
|
||||
|
15
module/mem
Executable file
15
module/mem
Executable file
@ -0,0 +1,15 @@
|
||||
#!/bin/bash
|
||||
|
||||
mod_mem () {
|
||||
# Customizable configuration constants
|
||||
local -r DEFAULT_PRE=' '
|
||||
local -r DEFAULT_SUF='%'
|
||||
|
||||
local -r pre="${1-${DEFAULT_PRE}}"
|
||||
local -r suf="${2-${DEFAULT_SUF}}"
|
||||
|
||||
printf '%b' "${pre}"
|
||||
free | awk 'NR == 2 {printf "%3.0f", $3 * 100 / $2}'
|
||||
printf '%b' "${suf}"
|
||||
}
|
||||
|
34
module/vol-amixer
Executable file
34
module/vol-amixer
Executable file
@ -0,0 +1,34 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Requires amixer from the alsa-utils package
|
||||
|
||||
mod_vol_amixer () {
|
||||
# Customizable configuration constants
|
||||
local -r DEFAULT_PRE_LOW=' '
|
||||
local -r DEFAULT_PRE_HI=' '
|
||||
local -r DEFAULT_PRE_MUTE=' '
|
||||
local -r DEFAULT_SUF='%'
|
||||
|
||||
local -r pre_low="${1-${DEFAULT_PRE_LOW}}"
|
||||
local -r pre_hi="${2-${DEFAULT_PRE_HI}}"
|
||||
local -r pre_mute="${3-${DEFAULT_PRE_MUTE}}"
|
||||
local -r suf="${4-${DEFAULT_SUF}}"
|
||||
|
||||
local pre info stat vol
|
||||
|
||||
info="$(amixer get Master | tail -n 1)"
|
||||
stat="$(sed -E 's/.*\[(.*)\]/\1/' <<< "${info}")"
|
||||
vol="$(sed -E 's/.*\[(.*)%\].*/\1/' <<< "${info}")"
|
||||
|
||||
case "${stat}" in
|
||||
on)
|
||||
if [[ "${vol}" -lt 50 ]]; then pre="${pre_low}";
|
||||
else pre="${pre_hi}"; fi
|
||||
;;
|
||||
*)
|
||||
pre="${pre_mute}"
|
||||
;;
|
||||
esac
|
||||
printf '%b%3d%b' "${pre}" "${vol}" "${suf}"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user