From 07aef9f22373e0d37736538dfdd8b8953f0c12d0 Mon Sep 17 00:00:00 2001 From: mykola2312 <49044616+mykola2312@users.noreply.github.com> Date: Tue, 10 Sep 2024 08:22:52 +0300 Subject: [PATCH] implement custom i3status bar --- _sync.sh | 2 + i3wm/i3/config | 2 +- i3wm/i3status/config | 7 +++ i3wm/i3status/config.orig | 53 +++++++++++++++++++++ w_status | 97 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 160 insertions(+), 1 deletion(-) create mode 100644 i3wm/i3status/config create mode 100644 i3wm/i3status/config.orig create mode 100755 w_status diff --git a/_sync.sh b/_sync.sh index d311c06..ea597d7 100755 --- a/_sync.sh +++ b/_sync.sh @@ -12,6 +12,7 @@ dirs=( "/var/unbound:." "$HOME/bhyve:." "$HOME/.config/i3:i3wm" + "$HOME/.config/i3status:i3wm" ) files=( @@ -25,6 +26,7 @@ files=( "/etc/rc.conf:rc.conf" "/usr/local/etc/smb4.conf:smb4.conf" "/etc/sysctl.conf:sysctl.conf" + "/usr/local/bin/w_status:w_status" ) # create directories diff --git a/i3wm/i3/config b/i3wm/i3/config index 63eeb19..5ea4b1d 100644 --- a/i3wm/i3/config +++ b/i3wm/i3/config @@ -192,5 +192,5 @@ bindsym $mod+r mode "resize" # Start i3bar to display a workspace bar (plus the system information i3status # finds out, if available) bar { - status_command i3status + status_command w_status } diff --git a/i3wm/i3status/config b/i3wm/i3status/config new file mode 100644 index 0000000..a88c478 --- /dev/null +++ b/i3wm/i3status/config @@ -0,0 +1,7 @@ +general { + output_format = "i3bar" + colors = true + interval = 5 +} + +order = "" \ No newline at end of file diff --git a/i3wm/i3status/config.orig b/i3wm/i3status/config.orig new file mode 100644 index 0000000..ba81c3a --- /dev/null +++ b/i3wm/i3status/config.orig @@ -0,0 +1,53 @@ +# i3status configuration file. +# see "man i3status" for documentation. + +# It is important that this file is edited as UTF-8. +# The following line should contain a sharp s: +# ß +# If the above line is not correctly displayed, fix your editor first! + +general { + colors = true + interval = 5 +} + +order += "ipv6" +order += "wireless _first_" +order += "ethernet _first_" +order += "battery all" +order += "disk /" +order += "load" +order += "memory" +order += "tztime local" + +wireless _first_ { + format_up = "W: (%quality at %essid) %ip" + format_down = "W: down" +} + +ethernet _first_ { + format_up = "E: %ip (%speed)" + format_down = "E: down" +} + +battery all { + format = "%status %percentage %remaining" +} + +disk "/" { + format = "%avail" +} + +load { + format = "%1min" +} + +memory { + format = "%used | %available" + threshold_degraded = "1G" + format_degraded = "MEMORY < %available" +} + +tztime local { + format = "%Y-%m-%d %H:%M:%S" +} diff --git a/w_status b/w_status new file mode 100755 index 0000000..f1b574b --- /dev/null +++ b/w_status @@ -0,0 +1,97 @@ +#!/usr/bin/env bash +# replacement for i3status for my FreeBSD setup +# I want to output +# ue0 | wlan0 | re0 | ZFS | RAM | SWAP | temp | time + +interval=1 + +output_time() { + date "+%d/%m/%Y %H:%M:%S" +} + +output_battery() { + read -r bat_state<<<$(echo "$hwstat_output" | awk '$1=="State:" { print $2 }' | tail -n 1) + read -r bat_capacity<<<$(echo "$hwstat_output" | awk '$1=="Remaining" { print $3 }' | head -n 1) + + echo "BAT: $bat_capacity% $bat_state" +} + +swap_to_mb() { + echo $1 | awk '{ printf "%.2f\n", $1/1024; }' +} + +bytes_to_mb() { + echo $1 | awk '{ printf "%.2f\n", $1/1024/1024; }' +} + +bytes_to_gb() { + echo $1 | awk '{ printf "%.2f\n", $1/1024/1024/1024; }' +} + +output_temp() { + temp=$(echo "$hwstat_output" | awk '$1=="CPU0:" { print $2 }') + + echo "t: $temp" +} + +output_swap() { + read -r swap_used <<<$(swapinfo | awk 'NR==2 { print $3 }') + echo "SWAP: $(swap_to_mb $swap_used) MiB" +} + +output_ram() { + physmem=$(sysctl -n hw.physmem) + usermem=$(sysctl -n hw.usermem) + + echo "RAM: $(bytes_to_gb $usermem)/$(bytes_to_gb $physmem) GiB" +} + +output_zfs() { + read -r zfs_name zfs_size zfs_free<<<$(zpool list | awk 'NR==2 { print $1,$2,$4 }') + echo "$zfs_name: $zfs_free free" +} + +output_eth() { + if_output=$(ifconfig $1) + if [ $? -eq 0 ]; then + read -r eth_ip<<<$(echo "$if_output" | awk '$1=="inet" { print $2 }') + #read -r eth_type<<<$(echo "$if_output" | awk '$1=="media:" { print $2 }') + read -r eth_media<<<$(echo "$if_output" | awk '$1=="media:" { print $4 }' | sed s/\(//) + + echo "$1: $eth_ip $eth_media" + else + echo "$1: offline" + fi +} + +output_wlan() { + if_output=$(ifconfig $1) + if [ $? -eq 0 ]; then + read -r eth_ip<<<$(echo "$if_output" | awk '$1=="inet" { print $2 }') + #read -r eth_type<<<$(echo "$if_output" | awk '$1=="media:" { print $3 }') + #read -r eth_media<<<$(echo "$if_output" | awk '$1=="media:" { print $4 }' | sed s/\(//) + + echo "$1: $eth_ip" + else + echo "$1: offline" + fi +} + +output_usb_eth() { + if_output=$(ifconfig $1) + if [ $? -eq 0 ]; then + read -r eth_ip<<<$(echo "$if_output" | awk '$1=="inet" { print $2 }') + + echo "$1: $eth_ip" + else + echo "$1: offline" + fi +} + + +while true; do + hwstat_output=$(hwstat) + echo "$(output_usb_eth ue0) | $(output_wlan wlan0) | $(output_eth re0) | $(output_zfs) | $(output_ram) | $(output_swap) | $(output_temp) | $(output_battery) | $(output_time)"; + + sleep $interval; +done