#!/bin/sh # i3 config in ~/.config/i3/config : # bar { # status_command exec /home/you/.config/i3status/mybar.sh # } bg_bar_color="#282A36" # Print a left caret separator # @params {string} $1 text color, ex: "#FF0000" # @params {string} $2 background color, ex: "#FF0000" separator() { echo -n "{" echo -n "\"full_text\":\"\"," # CTRL+Ue0b2 echo -n "\"separator\":false," echo -n "\"separator_block_width\":0," echo -n "\"border\":\"$bg_bar_color\"," echo -n "\"border_left\":0," echo -n "\"border_right\":0," echo -n "\"border_top\":2," echo -n "\"border_bottom\":2," echo -n "\"color\":\"$1\"," echo -n "\"background\":\"$2\"" echo -n "}" } common() { echo -n "\"border\": \"$bg_bar_color\"," echo -n "\"separator\":false," echo -n "\"separator_block_width\":0," echo -n "\"border_top\":2," echo -n "\"border_bottom\":2," echo -n "\"border_left\":0," echo -n "\"border_right\":0" } root_text() { local bg="#000000" local text_color="#D48F06" separator $bg "#FFD180" echo -n ",{" echo -n "\"name\":\"id_root_text\"," echo -n "\"color\":\"$text_color\"," echo -n "\"full_text\":\" $(echo -n 'Root:')\"," echo -n "\"background\":\"$bg\"," common echo -n "}," } root_usage() { local bg="#000000" local text_color="#00A300" separator $bg "#2E7D32" echo -n ",{" echo -n "\"name\":\"id_root_usage\"," echo -n "\"color\":\"$text_color\"," echo -n "\"full_text\":\"$(df --output=pcent / | grep -v Uti)\"," echo -n "\"background\":\"$bg\"," common echo -n "}," } home_text() { local bg="#000000" local text_color="#D48F06" separator $bg "#FFD180" echo -n ",{" echo -n "\"name\":\"id_home_text\"," echo -n "\"color\":\"$text_color\"," echo -n "\"full_text\":\" $(echo -n 'Home:')\"," echo -n "\"background\":\"$bg\"," common echo -n "}," } home_usage() { local bg="#000000" local text_color="#00A300" separator $bg "#2E7D32" echo -n ",{" echo -n "\"name\":\"id_home_usage\"," echo -n "\"color\":\"$text_color\"," echo -n "\"full_text\":\"$(df --output=pcent /home | grep -v Uti)\"," echo -n "\"background\":\"$bg\"," common echo -n "}," } src_usage() { local bg="#000000" local text_color="#00A300" separator $bg "#2E7D32" echo -n ",{" echo -n "\"name\":\"id_src_usage\"," echo -n "\"color\":\"$text_color\"," echo -n "\"full_text\":\"$(df --output=pcent /usr/src | grep -v Uti)\"," echo -n "\"background\":\"$bg\"," common echo -n "}," } src_text() { local bg="#000000" local text_color="#D48F06" separator $bg "#FFD180" echo -n ",{" echo -n "\"name\":\"id_src_text\"," echo -n "\"color\":\"$text_color\"," echo -n "\"full_text\":\" $(echo -n 'Src:')\"," echo -n "\"background\":\"$bg\"," common echo -n "}," } seclists_usage() { local bg="#000000" local text_color="#00A300" separator $bg "#2E7D32" echo -n ",{" echo -n "\"name\":\"id_seclists_usage\"," echo -n "\"color\":\"$text_color\"," echo -n "\"full_text\":\"$(df --output=pcent /usr/share/seclists | grep -v Uti)\"," echo -n "\"background\":\"$bg\"," common echo -n "}," } seclists_text() { local bg="#000000" local text_color="#D48F06" separator $bg "#FFD180" echo -n ",{" echo -n "\"name\":\"id_boot_text\"," echo -n "\"color\":\"$text_color\"," echo -n "\"full_text\":\" $(echo -n 'Sec:')\"," echo -n "\"background\":\"$bg\"," common echo -n "}," } boot_usage() { local bg="#000000" local text_color="#00A300" separator $bg "#2E7D32" echo -n ",{" echo -n "\"name\":\"id_boot_usage\"," echo -n "\"color\":\"$text_color\"," echo -n "\"full_text\":\"$(df --output=pcent /boot | grep -v Uti)\"," echo -n "\"background\":\"$bg\"," common echo -n "}," } boot_text() { local bg="#000000" local text_color="#D48F06" separator $bg "#FFD180" echo -n ",{" echo -n "\"name\":\"id_boot_text\"," echo -n "\"color\":\"$text_color\"," echo -n "\"full_text\":\" $(echo -n 'Boot:')\"," echo -n "\"background\":\"$bg\"," common echo -n "}," } memory_text() { local bg="#000000" local text_color="#D48F06" separator $bg "#FFD180" echo -n ",{" echo -n "\"name\":\"id_memory_text\"," echo -n "\"color\":\"$text_color\"," echo -n "\"full_text\":\" $(echo -n ' Mem: ')\"," echo -n "\"background\":\"$bg\"," common echo -n "}," } memory() { local bg="#000000" local text_color="#00A300" separator $bg "#FFD180" echo -n ",{" echo -n "\"color\":\"$text_color\"," echo -n "\"name\":\"id_memory\"," echo -n "\"full_text\":\"$(free | awk '/^Mem/ { printf("%.2f", $3/$2 * 100.0) }')%\"," echo -n "\"background\":\"$bg\"," common echo -n "}," } cpu_usage() { local text_color="#00A300" separator $bg "#FFD180" echo -n ",{" echo -n "\"color\":\"$text_color\"," echo -n "\"name\":\"id_cpu_usage\"," echo -n "\"full_text\":\"$(ps -A -o pcpu | tail -n+2 | paste -sd+ | bc)% \"," echo -n "\"background\":\"#000000\"," common echo -n "}," } cpu_text() { local bg="#000000" local text_color="#D48F06" separator $bg "#FFD180" echo -n ",{" echo -n "\"name\":\"id_cpu_text\"," echo -n "\"color\":\"$text_color\"," echo -n "\"full_text\":\" $(echo -n ' CPU: ')\"," echo -n "\"background\":\"$bg\"," common echo -n "}," } mydate() { local bg="#000000" separator $bg "#FFD190" echo -n ",{" echo -n "\"name\":\"id_time\"," echo -n "\"full_text\":\"  $(date "+%a %d/%m %H:%M") \"," echo -n "\"color\":\"#D48F06\"," echo -n "\"background\":\"$bg\"," common echo -n "}," } bat_text() { local bg="#000000" local text_color="#D48F06" charging=$(cat /sys/class/power_supply/BAT0/uevent | grep "POWER_SUPPLY_STATUS" | cut -d'=' -f2) # POWER_SUPPLY_STATUS=Discharging|Charging icon="" if [ "$charging" == "Charging" ]; then icon="" fi separator $bg "#FFD180" echo -n ",{" echo -n "\"name\":\"id_bat_text\"," echo -n "\"color\":\"$text_color\"," echo -n "\"full_text\":\"${icon}$(echo -n ' Bat: ')\"," echo -n "\"background\":\"$bg\"," common echo -n "}," } battery0() { if [ -f /sys/class/power_supply/BAT0/uevent ]; then local bg="#000000" separator $bg "#E0E0E0" bg_separator_previous=$bg prct=$(cat /sys/class/power_supply/BAT0/uevent | grep "POWER_SUPPLY_CAPACITY=" | cut -d'=' -f2) echo -n ",{" echo -n "\"name\":\"battery0\"," echo -n "\"full_text\":\"${prct}% \"," echo -n "\"color\":\"#00A300\"," echo -n "\"background\":\"$bg\"," common echo -n "}," else bg_separator_previous="#E0E0E0" fi } volume() { local bg="#000000" local text_color="#D48F06" separator $bg $bg_separator_previous vol=$(pulsemixer --get-volume) echo -n ",{" echo -n "\"name\":\"id_volume\"," echo -n "\"color\":\"$text_color\"," if [ $vol -le 0 ]; then echo -n "\"full_text\":\"  ${vol}% \"," else echo -n "\"full_text\":\"  ${vol}% \"," fi echo -n "\"background\":\"$bg\"," common echo -n "}," separator $bg_bar_color $bg } systemupdate() { local nb=$(checkupdates | wc -l) if (( $nb > 0)); then echo -n ",{" echo -n "\"name\":\"id_systemupdate\"," echo -n "\"full_text\":\"  ${nb}\"" echo -n "}" fi } logout() { echo -n ",{" echo -n "\"name\":\"id_logout\"," echo -n "\"full_text\":\"  \"" echo -n "}" } # https://github.com/i3/i3/blob/next/contrib/trivial-bar-script.sh echo '{ "version": 1, "click_events":true }' # Send the header so that i3bar knows we want to use JSON: echo '[' # Begin the endless array. echo '[]' # We send an empty first array of blocks to make the loop simpler: # Now send blocks with information forever: (while :; do echo -n ",[" root_text root_usage home_text home_usage boot_text boot_usage src_text src_usage seclists_text seclists_usage memory_text memory cpu_text cpu_usage mydate bat_text battery0 volume logout echo "]" sleep 1 done) & # click events while read line; do # echo $line > /home/you/gitclones/github/i3/tmp.txt # {"name":"id_vpn","button":1,"modifiers":["Mod2"],"x":2982,"y":9,"relative_x":67,"relative_y":9,"width":95,"height":22} # CPU if [[ $line == *"name"*"id_cpu_usage"* ]]; then wezterm --config-file /home/pierre/.config/i3status/wezterm_htop.lua -e --class term_date htop & # TIME elif [[ $line == *"name"*"id_time"* ]]; then wezterm --config-file /home/pierre/.config/i3status/wezterm_date.lua -e --position screen:1582,21 --class term_date /home/pierre/.config/i3status/click_time.sh & # VOLUME elif [[ $line == *"name"*"id_volume"* ]]; then wezterm -e --class term_date -e pulsemixer & # LOGOUT elif [[ $line == *"name"*"id_logout"* ]]; then i3-nagbar -t warning -m 'Log out ?' -b 'yes' 'i3-msg exit' > /dev/null & fi done