diff options
author | Vikas Kushwaha <dev@vikas.rocks> | 2025-05-07 13:44:50 +0530 |
---|---|---|
committer | Vikas Kushwaha <dev@vikas.rocks> | 2025-05-07 13:44:50 +0530 |
commit | e55ad8ca4f99fa024106d5695a55f9ac132d7b68 (patch) | |
tree | f8762e7ac43504841f3c14c20bd8f149c1cbc344 /.local/bin/statusbar | |
parent | 7df7120b1ae66ed0e9a7c6ed9b224ba44ea1d920 (diff) |
updates
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/i3weather | 3 |
3 files changed, 218 insertions, 1 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/i3weather b/.local/bin/statusbar/i3weather index 2d34149..d008deb 100755 --- a/.local/bin/statusbar/i3weather +++ b/.local/bin/statusbar/i3weather @@ -1,5 +1,6 @@ #!/bin/sh -# i3block for displaying the current temperature, humidity and precipitation, if wttr.in i unavailable then WEATHER UNAVAILABLE will be displayed +# weather module for i3blocks +# output is set to 'WEATHER UNAVAILABLE' in case wttr.in is unreachable case "$BLOCK_BUTTON" in '') ;; |