dotfiles/stow_home/spectrwm/.config/spectrwm/bar-config.org

5.7 KiB

My Spectrwm bar config

My bar action configuration

This is my bar script for Spectrwm. Which can be found here. This script displays some of the information I actually care about, as well as some things I don't.

Dependencies

You are going to need a few programs in order to properly display the bar output

  • awk
  • mpc
  • pamixer
  • sed
  • mpd

Disclaimer

Keep in mind that some of my scripts might not work on your specific linux distro, I am running Endeavour OS which is Arch based and uses pacman as package manager. So some of the package related scripts might not work

Network status

This one will probably be fine for most setups.

# network status
network() {
wifi="$(ip a | grep wlan0 | grep inet | wc -l)"
wire="$(ip a | grep enp1s0 | grep inet | wc -l)"
if [ $wire = 1 ]; then
    echo " "
elif [ $wifi = 1 ]; then
    echo " "
else
    echo "睊"
fi
}

Battery status

This one comes from using cat on a system file. There might be some other utilites, like acpi that could work here, but this is fine.

# battery status
bat() {
    batstat="$(cat /sys/class/power_supply/BAT0/status)"
    battery="$(cat /sys/class/power_supply/BAT0/capacity)"

    if [ $batstat = 'Unknown' ]; then
            batstat=""
        elif [[ $battery -ge 5 ]] && [[ $battery -le 19 ]]; then
            batstat=""
        elif [[ $battery -ge 20 ]] && [[ $battery -le 39 ]]; then
            batstat=""
        elif [[ $battery -ge 40 ]] && [[ $battery -le 59 ]]; then
            batstat=""
        elif [[ $battery -ge 60 ]] && [[ $battery -le 79 ]]; then
            batstat=""
        elif [[ $battery -ge 80 ]] && [[ $battery -le 95 ]]; then
            batstat=""
        elif [[ $battery -ge 96 ]] && [[ $battery -le 100 ]]; then
            batstat=""
    fi

    echo "$batstat  $battery"
}

Volume levels

In this case I decided to go with pamixer just because its easier to use and write. I can probably do something like what happens with the battery section, but its fine as is, I got this from the internet too, what do you expect?

# volume status
vol() {
    volstat=$(pamixer --get-volume-human)
    vol=$(echo "$volstat")
    volicon="墳"
    echo -e "$volicon $vol"
}

Storage and RAM

This section just displays how much storage I've used in my ssd, might require some configuration on your part, I don't know. It also shows the available system memory.

# used storage
hdd() {
    hdd="$(df -h /home | grep /dev | awk '{print $3 " / " $2}')"
    echo -e " $hdd"
}

# available ram
mem() {
    used="$(free -h | grep Mem: | awk '{print $3}')"
    #total="$(free | grep Mem: | awk '{print $2}')"
    #totalh="$(free -h | grep Mem: | awk '{print $2}' | sed 's/Gi/G/')"
    ram="$used"
    echo $ram
}

CPU status

Yep, I have no idea of what this does, but it works and I use it, ok?

# Cpu things
cpu() {
    read cpu a b c previdle rest < /proc/stat
    prevtotal=$((a+b+c+previdle))
    sleep 0.5
    read cpu a b c idle rest < /proc/stat
    total=$((a+b+c+idle))
    cpu=$((100*( (total-prevtotal) - (idle-previdle) ) / (total-prevtotal) ))
    echo -e "  $cpu%"
}

Bar process

The bar is going to be constantly running, updating every once in a while, this section echoes the output of all of the used functions, and its what spectrwm will show as the bar

Notice the different sections such as +fg@1, these are the colors that are shown in my spectrwm.conf file, and that's how spectrwm knows it needs to change the color of things. Like foreground and background

# Loop to update bar output
update(){
	echo " $(mpd)$(cpu)+@fg=3; +@bg=1;+@fg=1;  $(mem)  +@fg=4;+@bg=2;+@fg=1;  $(hdd) +@fg=5;+@bg=3;+@fg=1; $(vol) +@fg=7;+@bg=5;+@fg=1; $(bat) +@fg=8;+@bg=6;+@fg=1; $(network) +@fg=1;+@bg=0;"
    wait
}
while :; do
		update
		~/.config/spectrwm/scripts/trayer_follows_ws.sh
    sleep 2 &
    wait
done

Extras

I have used and removed a few things from my script, but I added them here just in case anyone cares about them or is looking for stuff to put into their own config files.

MPD status

Displays the current song playing with mpd, and if its paused

mpd(){
    song="$(mpc current)"
    status="$(mpc status | grep paused | awk '{print $1}')"
    echo -e "$song"
}

Packages and updates

These were made for Void Linux, and I stil don't adapt them for Endeavor OS. Therefore, I don't call them, since they would not work

# Installed packages
pkgs() {
    pkgs="$(xbps-query -l | wc -l)"
    echo -e " $pkgs"
}

# Available updates
upgrades() {
    upgrades="$(xbps-install -Sun | wc -l)"
    echo -e " $upgrades"
}

Weather report

I guess you can tell what this does from reading the title. I don't really know if it still works, to be honest.

# weather using curl wttr.in
temp() {
    tmp="$(curl -s wttr.in | grep -m 1 °C | awk '{print $5 $6}')"
    ##tmp="$(grep temp_F ~/.config/weather.txt | awk '{print $2}' | sed 's/"//g' | sed 's/,/ F/g')"
    echo " $tmp"
}