Initial commit
This commit is contained in:
45
status.sh
Executable file
45
status.sh
Executable file
@ -0,0 +1,45 @@
|
||||
# The Sway configuration file in ~/.config/sway/config calls this script.
|
||||
# You should see changes to the status bar after saving this script.
|
||||
# If not, do "killall swaybar" and $mod+Shift+c to reload the configuration.
|
||||
|
||||
# The abbreviated weekday (e.g., "Sat"), followed by the ISO-formatted date
|
||||
# like 2018-10-06 and the time (e.g., 14:01). Check `man date` on how to format
|
||||
# time and date.
|
||||
date_formatted=$(date "+%a %F %H:%M")
|
||||
|
||||
# "upower --enumerate | grep 'BAT'" gets the battery name (e.g.,
|
||||
# "/org/freedesktop/UPower/devices/battery_BAT0") from all power devices.
|
||||
# "upower --show-info" prints battery information from which we get
|
||||
# the state (such as "charging" or "fully-charged") and the battery's
|
||||
# charge percentage. With awk, we cut away the column containing
|
||||
# identifiers. i3 and sway convert the newline between battery state and
|
||||
# the charge percentage automatically to a space, producing a result like
|
||||
# "charging 59%" or "fully-charged 100%".
|
||||
battery_info=$(upower --show-info $(upower --enumerate |\
|
||||
grep 'BAT') |\
|
||||
egrep "state|percentage" |\
|
||||
awk '{print $2}')
|
||||
|
||||
# "amixer -M" gets the mapped volume for evaluating the percentage which
|
||||
# is more natural to the human ear according to "man amixer".
|
||||
# Column number 4 contains the current volume percentage in brackets, e.g.,
|
||||
# "[36%]". Column number 6 is "[off]" or "[on]" depending on whether sound
|
||||
# is muted or not.
|
||||
# "tr -d []" removes brackets around the volume.
|
||||
# Adapted from https://bbs.archlinux.org/viewtopic.php?id=89648
|
||||
audio_volume=$(amixer -M get Master |\
|
||||
awk '/Mono.+/ {print $6=="[off]" ?\
|
||||
$4" muted!": \
|
||||
$4}' |\
|
||||
tr -d [])
|
||||
|
||||
# Wifi
|
||||
ip_address=$(nmcli -g GENERAL.STATE device show wlx0010603707fd | sed 's/.*(\(.*\))/\1/')
|
||||
|
||||
# Temperature
|
||||
temp=$(cat /sys/class/thermal/thermal_zone*/temp | sed 's/...$/°C/')
|
||||
|
||||
# Mem info
|
||||
mem=$(free -m | grep Mem | awk '{printf "%d%%", ($3/$2)*100}')
|
||||
|
||||
echo "V: "$audio_volume" | M: "$mem" | B: "$battery_info" | T: "$temp" | N: "$ip_address" | "$date_formatted
|
Reference in New Issue
Block a user