diff options
Diffstat (limited to '.local/bin/statusbar')
-rwxr-xr-x | .local/bin/statusbar/disk-io | 93 | ||||
-rwxr-xr-x | .local/bin/statusbar/disk_usage | 123 | ||||
-rwxr-xr-x | .local/bin/statusbar/i3battery | 8 | ||||
-rwxr-xr-x | .local/bin/statusbar/i3weather | 59 | ||||
-rwxr-xr-x | .local/bin/statusbar/sb-clock | 61 |
5 files changed, 324 insertions, 20 deletions
diff --git a/.local/bin/statusbar/disk-io b/.local/bin/statusbar/disk-io new file mode 100755 index 0000000..daf8e58 --- /dev/null +++ b/.local/bin/statusbar/disk-io @@ -0,0 +1,93 @@ +#!/usr/bin/env bash +# +# Copyright (C) 2016 James Murphy +# Licensed under the terms of the GNU GPL v2 only. +# +# i3blocks blocklet script to monitor disk io + +label="${LABEL:-""}" +dt="${DT:-5}" +MB_only="${MB_ONLY:-0}" +kB_only="${KB_ONLY:-0}" +width="${WIDTH:-4}" +MB_precision="${MB_PRECISION:-1}" +kB_precision="${KB_PRECISION:-0}" +regex="${REGEX:-$BLOCK_INSTANCE}" +regex="${regex:-/^(s|h)d[a-zA-Z]+/}" +threshold="${THRESHOLD:-0}" +warn_color="${WARN_COLOR:-#FF0000}" +sep="${SEPARATOR:-/}" +unit_suffix="${SUFFIX:-B/s}" +align="${ALIGN--}" + +function list_devices { + echo "Devices iostat reports that match our regex:" + iostat | awk '$1~/^(s|h)d[a-zA-Z]+/{print $1}' +} + +while getopts L:t:w:p:P:R:s:ST:C:lLMmKkh opt; do + case "$opt" in + L) label="$OPTARG" ;; + t) dt="$OPTARG" ;; + w) width="$OPTARG" ;; + p) kB_precision="$OPTARG" ;; + P) MB_precision="$OPTARG" ;; + R) regex="$OPTARG" ;; + s) sep="$OPTARG" ;; + S) unit_suffix="" ;; + T) threshold="$OPTARG" ;; + C) warn_color="$OPTARG" ;; + l) list_devices; exit 0 ;; + M|m) MB_only=1 ;; + K|k) kB_only=1 ;; + h) printf \ +"Usage: disk-io [-t time] [-w width] [-p kB_precision] [-P MB_precision] [-R regex] [-s separator] [-S] [-T threshold [-C warn_color]] [-k|-M] [-l] [-h] +Options: +-L\tLabel to put in front of the text. Default: $label +-t\tTime interval in seconds between measurements. Default: $dt +-w\tThe width of printed floats. Default: $width +-p\tThe precision of kB/s floats. Default: $kB_precision +-P\tThe precision of MB/s floats. Default: $MB_precision +-R\tRegex that devices must match. Default: $regex +-s\tSeparator to put between rates. Default: $sep +-S\tShort units, omit B/s in kB/s and MB/s. +-T\tRate in kB/s to exceed to trigger a warning. Default: not enabled +-C\tColor to change the blocklet to warn the user. Default: $warn_color +-l\tList devices that iostat reports +-M\tDo not switch between MB/s and kB/s, use only MB/s +-k\tDo not switch between MB/s and kB/s, use only kB/s +-h\tShow this help text +" && exit 0;; + esac +done + +iostat -dyz "$dt" | awk -v sep="$sep" " + BEGIN { + rx = wx = 0; + } + { + if(\$0 == \"\") { + if ($threshold > 0 && (rx >= $threshold || wx >= $threshold)) { + printf \"<span color='$warn_color'>\"; + } + printf \"$label\"; + if(!$kB_only && ($MB_only || rx >= 1024 || wx >= 1024)) { + printf \"%$align$width.${MB_precision}f%s%$width.${MB_precision}f M$unit_suffix\", rx/1024, sep, wx/1024; + } + else { + printf \"%$align$width.${kB_precision}f%s%$width.${kB_precision}f k$unit_suffix\", rx, sep, wx; + } + if ($threshold > 0 && (rx >= $threshold || wx >= $threshold)) { + printf \"</span>\"; + } + printf \"\n\"; + fflush(stdout); + } + else if(\$1~/^Device:?/) { + rx = wx = 0; + } + else if(\$1~$regex) { + rx += \$3; + wx += \$4; + } + }" diff --git a/.local/bin/statusbar/disk_usage b/.local/bin/statusbar/disk_usage new file mode 100755 index 0000000..b129fc9 --- /dev/null +++ b/.local/bin/statusbar/disk_usage @@ -0,0 +1,123 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# MIT License + +# Copyright (c) 2017 Christian SchlΓ€ppi + +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: + +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. + +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +import os +import sys +import subprocess + + +def get_disk_stats(mp): + stat = os.statvfs(mp) + + total = stat.f_blocks * stat.f_frsize / 1024 ** 3 + avail = stat.f_bavail * stat.f_frsize / 1024 ** 3 + used = total - avail + + return { + 'avail': avail, + 'total': total, + 'used': used, + 'perc_used': 100 * used / total + } + + +def launch_ncdu(mp): + cmd = [ + '/usr/bin/sakura', + '-t', + 'pop-up', + '-e', + '/usr/bin/ncdu %s' % mp, + '-x', + ] + + subprocess.Popen( + cmd, + stdout=open(os.devnull, 'w'), + stderr=subprocess.STDOUT + ) + + +def parse_args(): + args = { + 'warn_threshold': 80, + 'crit_threshold': 90, + 'warn_color': '#d6af4e', + 'crit_color': '#d64e4e', + 'format': '{used:.1f}G/{total:.1f}G ({perc_used:.1f}%) - ο {avail:.1f}G' + } + + try: + for arg in sys.argv[1:]: + key, value = arg.split('=') + args[key] = int(value) if value.isdigit() else value + except (KeyError, ValueError): + # ValuError in case user does something weird + pass + + return args + + +def get_instance(): + p = os.getenv('BLOCK_INSTANCE') + if p and os.path.exists(p): + return p + + return os.getenv('HOME') + + +def main(): + + output_color = '' + args = parse_args() + m_point = get_instance() + stats = get_disk_stats(m_point) + + # get some more info when not called by i3blocks + if not os.getenv('BLOCK_NAME'): + print('Args: %s' % args) + print('Stats: %s' % stats) + print('Mount Point: %s' % m_point) + + # print stats with format if given + print(args['format'].format(**stats)) + print() + + # determine color + if args['crit_threshold'] > int(stats['perc_used']) >= args['warn_threshold']: + output_color = args['warn_color'] + elif stats['perc_used'] >= args['crit_threshold']: + output_color = args['crit_color'] + + print(output_color) + + # handle click-event + _button = os.getenv('BLOCK_BUTTON') + if _button and int(_button) == 1: + launch_ncdu(m_point) + + +if __name__ == '__main__': + main() diff --git a/.local/bin/statusbar/i3battery b/.local/bin/statusbar/i3battery index 5b2fb15..17a4dfd 100755 --- a/.local/bin/statusbar/i3battery +++ b/.local/bin/statusbar/i3battery @@ -47,7 +47,7 @@ for battery in /sys/class/power_supply/BAT?*; do *) exit 1 ;; esac # Will make a warn variable if discharging and low - [ "$status" = "Discharging" ] && [ "$capacity" -le 25 ] && warn="β" + [ "$status" = "Discharging" ] && [ "$capacity" -lt 30 ] && warn="β" # Prints the info printf "%s%s %d%%" "$warn" "$icon" "$capacity"; unset warn done && printf "\\n" @@ -55,11 +55,11 @@ done && printf "\\n" echo if [ $capacity -ge 80 ]; then echo "$BLOCK_COLOR_LEVEL1" -elif [ $capacity -ge 40 ]; then +elif [ $capacity -ge 60 ]; then echo "$BLOCK_COLOR_LEVEL2" -elif [ $capacity -ge 20 ]; then +elif [ $capacity -ge 40 ]; then echo "$BLOCK_COLOR_LEVEL3" -elif [ $capacity -ge 10 ]; then +elif [ $capacity -ge 20 ]; then echo "$BLOCK_COLOR_LEVEL4" else echo "$BLOCK_COLOR_LEVEL5" diff --git a/.local/bin/statusbar/i3weather b/.local/bin/statusbar/i3weather index 2d34149..dec12dd 100755 --- a/.local/bin/statusbar/i3weather +++ b/.local/bin/statusbar/i3weather @@ -1,26 +1,53 @@ #!/bin/sh -# i3block for displaying the current temperature, humidity and precipitation, if wttr.in i unavailable then WEATHER UNAVAILABLE will be displayed +# i3blocks weather module using wttr.in +# output is set to -- in case wttr.in is unreachable + +WTTR_CACHE_DIR="/tmp" +WTTR_CACHE="$WTTR_CACHE_DIR/wttr.in" +WTTR_TXT="$WTTR_CACHE_DIR/wttr.txt" +WTTR_LOCATION="Vasai" +WTTR_URL="https://wttr.in/$WTTR_LOCATION" + +notify() { + [ "$isUpdating" = 1 ] && + notify-send --replace-id=217534 "$@" +} + +err() { + printf "i3weather: %s\n" "$@" >&2 + notify "π ERROR (i3weather)" "$*" + echo "β
-- " + exit 1 +} case "$BLOCK_BUTTON" in - '') ;; + '') true ;; 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 - ;; + [ -f "$WTTR_CACHE" ] || BLOCK_BUTTON=5 i3weather + st -c "dropdown_weather" \ + -g "$(wc -L < "$WTTR_TXT")x30" \ + -e less -r "$WTTR_CACHE" & sleep 0.3 ;; 2) $TERMINAL -e nvim "$0" ;; - *) notify-send "β
Refreshing weather info..." ;; + *) isUpdating=1; notify "β
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")")" +# update cache files +res="$(curl -Ss "$WTTR_URL" > "$WTTR_CACHE" 2>&1)" || err "$res" +sed 's,\x1B\[[0-9;]*[a-zA-z],,g' "$WTTR_CACHE" > "$WTTR_TXT" +[ "$(wc -l "$WTTR_TXT" | cut -d' ' -f1)" -lt 20 ] && err "$(cat "$WTTR_TXT")" + +# get weather based on argument +case "$1" in + info) weather="$(curl -Ss "$WTTR_URL?format=%c%C" 2>&1)" ;; + cache) weather="$(sed -E '1,7!d; 3d; 6d; s/.{16}(.{,13}).*/\1/; s/\s//g' "$WTTR_TXT" | + sed -z 's/\n/:/; s/\n/ /g; s/\s*$//' 2>&1)" ;; + *) weather="$(curl -Ss "$WTTR_URL?format=%l:+%c+%t(%f)++%w++%p" 2>&1)" ;; +esac -if [ "$(echo "$weather" | grep -Ec "(Unknown|curl|HTML)")" -gt 0 ]; then - echo "WEATHER UNAVAILABLE" -else - echo "${weather:-β
-- }" -fi +# check for empty responses and errors +[ "$(echo "$weather" | grep -Ec "(Unknown|curl|HTML)")" -gt 0 ] && + err "$weather" || echo "${weather:-β
-- }" -curl -s "$HTTP_WEATHER" > ~/.cache/weather.txt +# End response when no error occurs +notify "βοΈ Weather Updated." diff --git a/.local/bin/statusbar/sb-clock b/.local/bin/statusbar/sb-clock new file mode 100755 index 0000000..d652e92 --- /dev/null +++ b/.local/bin/statusbar/sb-clock @@ -0,0 +1,61 @@ +#!/bin/sh + +clock=$(date '+%I') + +# # emoji icons +# case "$clock" in +# "00") icon="π" ;; +# "01") icon="π" ;; +# "02") icon="π" ;; +# "03") icon="π" ;; +# "04") icon="π" ;; +# "05") icon="π" ;; +# "06") icon="π" ;; +# "07") icon="π" ;; +# "08") icon="π" ;; +# "09") icon="π" ;; +# "10") icon="π" ;; +# "11") icon="π" ;; +# "12") icon="π" ;; +# esac + +# nerd fonts clock +case "$clock" in + "00") icon="σ±" ;; + "01") icon="σ±" ;; + "02") icon="σ±" ;; + "03") icon="σ±" ;; + "04") icon="σ±" ;; + "05") icon="σ±" ;; + "06") icon="σ±" ;; + "07") icon="σ±" ;; + "08") icon="σ±" ;; + "09") icon="σ±" ;; + "10") icon="σ±" ;; + "11") icon="σ±" ;; + "12") icon="σ±" ;; +esac + +# # nerd fonts clock filled +# case "$clock" in +# "00") icon="σ±" ;; +# "01") icon="σ±Ώ" ;; +# "02") icon="σ±" ;; +# "03") icon="σ±" ;; +# "04") icon="σ±" ;; +# "05") icon="σ±" ;; +# "06") icon="σ±" ;; +# "07") icon="σ±
" ;; +# "08") icon="σ±" ;; +# "09") icon="σ±" ;; +# "10") icon="σ±" ;; +# "11") icon="σ±" ;; +# "12") icon="σ±" ;; +# esac + +case $BLOCK_BUTTON in + 1) st -c "dropdown_calendar" -g 66x34 -e sh -c "cal -y --color=always|less" ;; + 2) setsid -f "$TERMINAL" -e "$EDITOR" "$0" ;; +esac + +date +"$icon %H:%M:%S σ° %a %d.%m.%Y β " |