diff options
Diffstat (limited to '.local/bin/statusbar')
-rwxr-xr-x | .local/bin/statusbar/cpu_usage | 55 | ||||
-rwxr-xr-x | .local/bin/statusbar/i3bandwidth | 105 | ||||
-rwxr-xr-x | .local/bin/statusbar/i3battery | 66 | ||||
-rwxr-xr-x | .local/bin/statusbar/i3cpu | 34 | ||||
-rwxr-xr-x | .local/bin/statusbar/i3cpubars | 44 | ||||
-rwxr-xr-x | .local/bin/statusbar/i3cpuload | 68 | ||||
-rwxr-xr-x | .local/bin/statusbar/i3memory | 33 | ||||
-rwxr-xr-x | .local/bin/statusbar/i3weather | 26 | ||||
-rwxr-xr-x | .local/bin/statusbar/i3wifi | 37 | ||||
-rwxr-xr-x | .local/bin/statusbar/memory_percent | 57 | ||||
-rwxr-xr-x | .local/bin/statusbar/memory_usage | 56 |
11 files changed, 581 insertions, 0 deletions
diff --git a/.local/bin/statusbar/cpu_usage b/.local/bin/statusbar/cpu_usage new file mode 100755 index 0000000..be729e2 --- /dev/null +++ b/.local/bin/statusbar/cpu_usage @@ -0,0 +1,55 @@ +#!/usr/bin/perl +# +# Copyright 2014 Pierre Mavro <deimos@deimos.fr> +# Copyright 2014 Vivien Didelot <vivien@didelot.org> +# Copyright 2014 Andreas Guldstrand <andreas.guldstrand@gmail.com> +# +# Licensed under the terms of the GNU GPL v3, or any later version. + +use strict; +use warnings; +use utf8; +use Getopt::Long; + +# default values +my $t_warn = 50; +my $t_crit = 80; +my $cpu_usage = -1; + +sub help { + print "Usage: cpu_usage [-w <warning>] [-c <critical>]\n"; + print "-w <percent>: warning threshold to become yellow\n"; + print "-c <percent>: critical threshold to become red\n"; + exit 0; +} + +GetOptions("help|h" => \&help, + "w=i" => \$t_warn, + "c=i" => \$t_crit); + +# Get CPU usage +$ENV{LC_ALL}="en_US"; # if mpstat is not run under en_US locale, things may break, so make sure it is +open (MPSTAT, 'mpstat 1 1 |') or die; +while (<MPSTAT>) { + if (/^.*\s+(\d+\.\d+)\s+$/) { + $cpu_usage = 100 - $1; # 100% - %idle + last; + } +} +close(MPSTAT); + +$cpu_usage eq -1 and die 'Can\'t find CPU information'; + +# Print short_text, full_text +printf "%.1f%%\n", $cpu_usage; +# printf "%.2f%%\n", $cpu_usage; + +# # Print color, if needed +# if ($cpu_usage >= $t_crit) { +# print "#FF0000\n"; +# exit 33; +# } elsif ($cpu_usage >= $t_warn) { +# print "#FFFC00\n"; +# } + +exit 0; diff --git a/.local/bin/statusbar/i3bandwidth b/.local/bin/statusbar/i3bandwidth new file mode 100755 index 0000000..8877d28 --- /dev/null +++ b/.local/bin/statusbar/i3bandwidth @@ -0,0 +1,105 @@ +#!/usr/bin/bash +# Copyright (C) 2012 Stefan Breunig <stefan+measure-net-speed@mathphys.fsk.uni-heidelberg.de> +# Copyright (C) 2014 kaueraal +# Copyright (C) 2015 Thiago Perrotta <perrotta dot thiago at poli dot ufrj dot br> + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +case "$BLOCK_BUTTON" in + 2) $TERMINAL -e nvim "$0" ;; +esac + +# Use the provided interface, otherwise the device used for the default route. +if [[ -n $BLOCK_INSTANCE ]]; then + INTERFACE=$BLOCK_INSTANCE +else + INTERFACE=$(ip route | awk '/^default/ { print $5 ; exit }') +fi + +[ -z "$INTERFACE" ] && echo && exit + +# Issue #36 compliant. +if ! [ -e "/sys/class/net/${INTERFACE}/operstate" ] || ! [ "$(cat "/sys/class/net/${INTERFACE}/operstate")" = "up" ] +then + # echo "$INTERFACE down" + # echo "$INTERFACE down" + # echo "#FF0000" + echo " " + exit 0 +fi + +# path to store the old results in +path="/dev/shm/$(basename "$0")-${INTERFACE}" + +# grabbing data for each adapter. +read -r rx < "/sys/class/net/${INTERFACE}/statistics/rx_bytes" +read -r tx < "/sys/class/net/${INTERFACE}/statistics/tx_bytes" + +# get time +time=$(date +%s) + +# write current data if file does not exist. Do not exit, this will cause +# problems if this file is sourced instead of executed as another process. +if ! [[ -f "${path}" ]]; then + echo "${time} ${rx} ${tx}" > "${path}" + chmod 0666 "${path}" +fi + +# read previous state and update data storage +read -r old < "${path}" +echo "${time} ${rx} ${tx}" > "${path}" + +# parse old data and calc time passed +old=(${old//;/ }) +time_diff=$(( time - old[0] )) + +# sanity check: has a positive amount of time passed +[[ "${time_diff}" -gt 0 ]] || { echo " "; exit; } + +# calc bytes transferred, and their rate in byte/s +rx_diff=$(( rx - old[1] )) +tx_diff=$(( tx - old[2] )) +rx_rate=$(( rx_diff / time_diff )) +tx_rate=$(( tx_diff / time_diff )) + +# shift by 10 bytes to get KiB/s. If the value is larger than +# 1024^2 = 1048576, then display MiB/s instead + +# incoming +rx_kib=$(( rx_rate >> 10 )) +if [ "$rx_kib" -gt 1 ]; then + # echo -n "📥 " + echo -n "↓ " + if [[ "$rx_rate" -gt 1048576 ]]; then + printf '%sM' "$(echo "scale=1; $rx_kib / 1024" | bc)" + else + echo -n "${rx_kib}K" + fi +fi + +# outgoing +tx_kib=$(( tx_rate >> 10 )) +if [ "$tx_kib" -gt 1 ]; then + # echo -n "📤 " + echo -n " ↑ " + if [[ "$tx_rate" -gt 1048576 ]]; then + printf '%sM' "$(echo "scale=1; $tx_kib / 1024" | bc)" + else + echo -n "${tx_kib}K" + fi +fi + +# echo +# echo +# echo "$BLOCK_COLOR_LEVEL1" diff --git a/.local/bin/statusbar/i3battery b/.local/bin/statusbar/i3battery new file mode 100755 index 0000000..5b2fb15 --- /dev/null +++ b/.local/bin/statusbar/i3battery @@ -0,0 +1,66 @@ +#!/bin/sh + +case "$BLOCK_BUTTON" in + 1) notify-send Temprature "$(sensors --no-adapter coretemp-isa-0000 | + tail +2 | sed "s|(.*)||")" ;; + 2) $TERMINAL -e "$EDITOR" "$0" ;; + 3) $TERMINAL -e battop ;; + 4) brightness up ;; + 5) brightness down ;; +esac; + +# Loop through all attached batteries and format the info +for battery in /sys/class/power_supply/BAT?*; do + capacity="$(cat "$battery/capacity" 2>&1)" + # If non-first battery, print a space separator. + # [ -n "${capacity+x}" ] && printf " " + # Sets up the status and capacity + status="$(cat "$battery/status" 2>&1)" + case "$status" in + "Full") icon="" ;; + "Discharging") case "$capacity" in + 9[0-9]) icon="" ;; + 8[0-9]) icon="" ;; + 7[0-9]) icon="" ;; + 6[0-9]) icon="" ;; + 5[0-9]) icon="" ;; + 4[0-9]) icon="" ;; + 3[0-9]) icon="" ;; + 2[0-9]) icon="" ;; + 1[0-9]|[0-9]) icon="" ;; + 100) icon="" ;; + esac ;; + "Charging") case "$capacity" in + 9[0-9]) icon="" ;; + 8[0-9]) icon="" ;; + 7[0-9]) icon="" ;; + 6[0-9]) icon="" ;; + 5[0-9]) icon="" ;; + 4[0-9]) icon="" ;; + 3[0-9]) icon="" ;; + 2[0-9]) icon="" ;; + 1[0-9]|[0-9]) icon="" ;; + 100) icon="" ;; + esac ;; + "Not charging") icon="" ;; + "Unknown") icon="" ;; + *) exit 1 ;; + esac + # Will make a warn variable if discharging and low + [ "$status" = "Discharging" ] && [ "$capacity" -le 25 ] && warn="❗" + # Prints the info + printf "%s%s %d%%" "$warn" "$icon" "$capacity"; unset warn +done && printf "\\n" + +echo +if [ $capacity -ge 80 ]; then + echo "$BLOCK_COLOR_LEVEL1" +elif [ $capacity -ge 40 ]; then + echo "$BLOCK_COLOR_LEVEL2" +elif [ $capacity -ge 20 ]; then + echo "$BLOCK_COLOR_LEVEL3" +elif [ $capacity -ge 10 ]; then + echo "$BLOCK_COLOR_LEVEL4" +else + echo "$BLOCK_COLOR_LEVEL5" +fi diff --git a/.local/bin/statusbar/i3cpu b/.local/bin/statusbar/i3cpu new file mode 100755 index 0000000..c5eeb68 --- /dev/null +++ b/.local/bin/statusbar/i3cpu @@ -0,0 +1,34 @@ +#!/bin/sh + +case "$BLOCK_BUTTON" in + 1) $TERMINAL -e gotop ;; + 2) $TERMINAL -e nvim "$(which i3cpu)" ;; + 3) echo "top,$TERMINAL -e top + htop,$TERMINAL -e htop + gotop,$TERMINAL -e gotop + nvtop,$TERMINAL -e nvtop" | jgmenu --vsimple --at-pointer ;; +esac; + +cpu_usage="$(cpu_usage)" +cpu="${cpu_usage%.*}" +printf "%s" "$cpu_usage" +# printf " " +# sb-cpubars + +echo +echo +# Print color, if needed +if [ "$cpu" -ge 90 ]; then + echo "$BLOCK_COLOR_LEVEL5"; + exit 33; +elif [ "$cpu" -ge 70 ]; then + echo "$BLOCK_COLOR_LEVEL4" +elif [ "$cpu" -ge 50 ]; then + echo "$BLOCK_COLOR_LEVEL3" +elif [ "$cpu" -ge 20 ]; then + echo "$BLOCK_COLOR_LEVEL2" +else + echo "$BLOCK_COLOR_LEVEL1" +fi + + diff --git a/.local/bin/statusbar/i3cpubars b/.local/bin/statusbar/i3cpubars new file mode 100755 index 0000000..c4c18af --- /dev/null +++ b/.local/bin/statusbar/i3cpubars @@ -0,0 +1,44 @@ +#!/bin/sh + +# Module showing CPU load as a changing bars. +# Just like in polybar. +# Each bar represents amount of load on one core since +# last run. + +# Cache in tmpfs to improve speed and reduce SSD load +cache=/tmp/cpubarscache + +case $BLOCK_BUTTON in + 2) setsid -f "$TERMINAL" -e htop ;; + 3) notify-send "🪨 CPU load module" "Each bar represents +one CPU core";; + 6) "$TERMINAL" -e "$EDITOR" "$0" ;; +esac + +# id total idle +stats=$(awk '/cpu[0-9]+/ {printf "%d %d %d\n", substr($1,4), ($2 + $3 + $4 + $5), $5 }' /proc/stat) +[ ! -f $cache ] && echo "$stats" > "$cache" +old=$(cat "$cache") +# printf "🪨" +echo "$stats" | while read -r row; do + id=${row%% *} + rest=${row#* } + total=${rest%% *} + idle=${rest##* } + + case "$(echo "$old" | awk '{if ($1 == id) + printf "%d\n", (1 - (idle - $3) / (total - $2))*100 /12.5}' \ + id="$id" total="$total" idle="$idle")" in + + "0") printf "▁";; + "1") printf "▂";; + "2") printf "▃";; + "3") printf "▄";; + "4") printf "▅";; + "5") printf "▆";; + "6") printf "▇";; + "7") printf "█";; + "8") printf "█";; + esac +done; # printf "\\n" +echo "$stats" > "$cache" diff --git a/.local/bin/statusbar/i3cpuload b/.local/bin/statusbar/i3cpuload new file mode 100755 index 0000000..6c14ddd --- /dev/null +++ b/.local/bin/statusbar/i3cpuload @@ -0,0 +1,68 @@ +#!/usr/bin/perl +# +# Copyright 2014 Pierre Mavro <deimos@deimos.fr> +# Copyright 2014 Vivien Didelot <vivien@didelot.org> +# Copyright 2014 Andreas Guldstrand <andreas.guldstrand@gmail.com> +# +# Licensed under the terms of the GNU GPL v3, or any later version. + +use strict; +use warnings; +use utf8; +use Getopt::Long; + +# default values +my $t_warn = $ENV{T_WARN} // 70; # default 50 +my $t_crit = $ENV{T_CRIT} // 90; # default 80 +my $cpu_usage = -1; +my $decimals = $ENV{DECIMALS} // 2; +my $label = $ENV{LABEL} // ""; + +sub help { + print "Usage: cpu_usage [-w <warning>] [-c <critical>] [-d <decimals>]\n"; + print "-w <percent>: warning threshold to become yellow\n"; + print "-c <percent>: critical threshold to become red\n"; + print "-d <decimals>: Use <decimals> decimals for percentage (default is $decimals) \n"; + exit 0; +} + +GetOptions("help|h" => \&help, + "w=i" => \$t_warn, + "c=i" => \$t_crit, + "d=i" => \$decimals, +); + +# Get CPU usage +$ENV{LC_ALL}="en_US"; # if mpstat is not run under en_US locale, things may break, so make sure it is +open (MPSTAT, 'mpstat |') or die; +while (<MPSTAT>) { + if (/^.*\s+(\d+\.\d+)[\s\x00]?$/) { + $cpu_usage = 100 - $1; # 100% - %idle + last; + } +} +close(MPSTAT); + +$cpu_usage eq -1 and die 'Can\'t find CPU information'; + +# Print short_text, full_text +print "${label}"; +printf "%.${decimals}f%%\n", $cpu_usage; + + +# print "\n"; +# # Print color, if needed +# if ($cpu_usage >= $t_crit) { +# print "$ENV{BLOCK_COLOR_LEVEL5}\n"; +# exit 33; +# } elsif ($cpu_usage >= $t_warn) { +# print "$ENV{BLOCK_COLOR_LEVEL4}\n"; +# } elsif ($cpu_usage >= 50) { +# print "$ENV{BLOCK_COLOR_LEVEL3}\n"; +# } elsif ($cpu_usage >= 20) { +# print "$ENV{BLOCK_COLOR_LEVEL2}\n"; +# } else { +# print "$ENV{BLOCK_COLOR_LEVEL1}\n"; +# } + +exit 0; diff --git a/.local/bin/statusbar/i3memory b/.local/bin/statusbar/i3memory new file mode 100755 index 0000000..edf9a73 --- /dev/null +++ b/.local/bin/statusbar/i3memory @@ -0,0 +1,33 @@ +#!/bin/sh + +case "$BLOCK_BUTTON" in + 1) $TERMINAL -e gotop ;; + 2) $TERMINAL -e nvim "$(which i3cpu)" ;; + 3) echo "top,$TERMINAL -e top + htop,$TERMINAL -e htop + gotop,$TERMINAL -e gotop + nvtop,$TERMINAL -e nvtop" | jgmenu --vsimple --at-pointer ;; +esac; + +memory="$(memory_percent)" +printf "%s" "$(memory_usage)" +# printf " " +# sb-cpubars + +echo +echo +# Print color, if needed +if [ "$memory" -ge 90 ]; then + echo "$BLOCK_COLOR_LEVEL5"; + exit 33; +elif [ "$memory" -ge 70 ]; then + echo "$BLOCK_COLOR_LEVEL4" +elif [ "$memory" -ge 50 ]; then + echo "$BLOCK_COLOR_LEVEL3" +elif [ "$memory" -ge 20 ]; then + echo "$BLOCK_COLOR_LEVEL2" +else + echo "$BLOCK_COLOR_LEVEL1" +fi + + diff --git a/.local/bin/statusbar/i3weather b/.local/bin/statusbar/i3weather new file mode 100755 index 0000000..2d34149 --- /dev/null +++ b/.local/bin/statusbar/i3weather @@ -0,0 +1,26 @@ +#!/bin/sh +# i3block for displaying the current temperature, humidity and precipitation, if wttr.in i unavailable then WEATHER UNAVAILABLE will be displayed + +case "$BLOCK_BUTTON" in + '') ;; + 1) + $TERMINAL -e less -r ~/.cache/weather.txt & sleep 0.3 + i3-msg 'move to workspace "12: Weather"; workspace "12: Weather"' >/dev/null 2>&1 + ;; + 2) $TERMINAL -e nvim "$0" ;; + *) notify-send "⛅ Refreshing weather info..." ;; +esac + +HTTP_WEATHER="https://wttr.in/Vasai" +# weather="$(curl -s "$HTTP_WEATHER?format=%c%C++❄️+%t++☀️+%f++🌬️+%w")" +weather="$(curl -Ss "$HTTP_WEATHER?0&T&Q" | cut -c 16- | head -2 | + xargs echo "$(curl -s "$HTTP_WEATHER?format=%c")")" + +if [ "$(echo "$weather" | grep -Ec "(Unknown|curl|HTML)")" -gt 0 ]; then + echo "WEATHER UNAVAILABLE" +else + echo "${weather:-⛅ -- }" +fi + +curl -s "$HTTP_WEATHER" > ~/.cache/weather.txt + diff --git a/.local/bin/statusbar/i3wifi b/.local/bin/statusbar/i3wifi new file mode 100755 index 0000000..689e3a2 --- /dev/null +++ b/.local/bin/statusbar/i3wifi @@ -0,0 +1,37 @@ +#!/bin/sh +# i3block for the displaying the wifi connectivity level +# If the wifi interface exists but no connection is active, "down" shall be displayed. + +case "$BLOCK_BUTTON" in + 1) $TERMINAL -e nmtui ;; + 2) $TERMINAL -e nvim "$0" ;; + 3) $TERMINAL -e nethogs ;; + # 3) echo "nethogs,$TERMINAL -e nethogs + # bmon,$TERMINAL -e bmon + # nmtui, $TERMINAL -e nmtui" | jgmenu --vsimple --at-pointer ;; +esac + +iface="$(find /sys/class/net/ -maxdepth 1 -name "w*" -printf "%f\n")" +if [ "$(cat "/sys/class/net/$iface/operstate")" = 'down' ]; then + icon=""; quality="down"; color="$BLOCK_COLOR_LEVEL5" +else + quality=$(grep "$iface" /proc/net/wireless | awk '{ print int($3 * 100 / 70) }') + if [ "$quality" = 100 ]; then + icon=""; color="$BLOCK_COLOR_LEVEL1" + elif [ "$quality" -ge 80 ]; then + icon=""; color="$BLOCK_COLOR_LEVEL1" + elif [ "$quality" -ge 60 ]; then + icon=""; color="$BLOCK_COLOR_LEVEL2" + elif [ "$quality" -ge 40 ]; then + icon=""; color="$BLOCK_COLOR_LEVEL3" + elif [ "$quality" -ge 20 ]; then + icon=""; color="$BLOCK_COLOR_LEVEL4" + else + icon=""; color="$BLOCK_COLOR_LEVEL5" + fi + [ -n "$quality" ] && quality="$quality%" +fi + +echo "$icon $quality" +echo +echo "$color" diff --git a/.local/bin/statusbar/memory_percent b/.local/bin/statusbar/memory_percent new file mode 100755 index 0000000..2b8da66 --- /dev/null +++ b/.local/bin/statusbar/memory_percent @@ -0,0 +1,57 @@ +#!/bin/sh +# Copyright (C) 2014 Julien Bonjean <julien@bonjean.info> + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +TYPE="${BLOCK_INSTANCE:-mem}" + +awk -v type=$TYPE ' +/^MemTotal:/ { + mem_total=$2 +} +/^MemFree:/ { + mem_free=$2 +} +/^Buffers:/ { + mem_free+=$2 +} +/^Cached:/ { + mem_free+=$2 +} +/^SwapTotal:/ { + swap_total=$2 +} +/^SwapFree:/ { + swap_free=$2 +} +END { + if (type == "swap") { + free=swap_free/1024/1024 + used=(swap_total-swap_free)/1024/1024 + total=swap_total/1024/1024 + } else { + free=mem_free/1024/1024 + used=(mem_total-mem_free)/1024/1024 + total=mem_total/1024/1024 + } + pct=0 + if (total > 0) { + pct=used/total*100 + } + # full text + # printf("%.1fG/%.1fG", used, total) + # printf("%.1fG", used) + printf("%d", pct) +} +' /proc/meminfo diff --git a/.local/bin/statusbar/memory_usage b/.local/bin/statusbar/memory_usage new file mode 100755 index 0000000..8f0fee4 --- /dev/null +++ b/.local/bin/statusbar/memory_usage @@ -0,0 +1,56 @@ +#!/bin/sh +# Copyright (C) 2014 Julien Bonjean <julien@bonjean.info> + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +TYPE="${BLOCK_INSTANCE:-mem}" + +awk -v type=$TYPE ' +/^MemTotal:/ { + mem_total=$2 +} +/^MemFree:/ { + mem_free=$2 +} +/^Buffers:/ { + mem_free+=$2 +} +/^Cached:/ { + mem_free+=$2 +} +/^SwapTotal:/ { + swap_total=$2 +} +/^SwapFree:/ { + swap_free=$2 +} +END { + if (type == "swap") { + free=swap_free/1024/1024 + used=(swap_total-swap_free)/1024/1024 + total=swap_total/1024/1024 + } else { + free=mem_free/1024/1024 + used=(mem_total-mem_free)/1024/1024 + total=mem_total/1024/1024 + } + pct=0 + if (total > 0) { + pct=used/total*100 + } + # full text + # printf("%.1fG/%.1fG", used, total) + printf("%.1fG", used) +} +' /proc/meminfo |