reorganize directory structure again
This commit is contained in:
104
home/bin/i3blocks/bandwidth
Executable file
104
home/bin/i3blocks/bandwidth
Executable file
@@ -0,0 +1,104 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# Copyright (C) 2015 James Murphy
|
||||
# Licensed under the terms of the GNU GPL v2 only.
|
||||
#
|
||||
# i3blocks blocklet script to monitor bandwidth usage
|
||||
|
||||
iface="${BLOCK_INSTANCE}"
|
||||
iface="${IFACE:-$iface}"
|
||||
dt="${DT:-3}"
|
||||
unit="${UNIT:-Mb}"
|
||||
LABEL="${LABEL:- }" # down arrow up arrow
|
||||
printf_command="${PRINTF_COMMAND:-"printf \"${LABEL}%-5.1f/%5.1f %s/s\\n\", rx, wx, unit;"}"
|
||||
|
||||
function default_interface {
|
||||
ip route | awk '/^default via/ {print $5; exit}'
|
||||
}
|
||||
|
||||
function check_proc_net_dev {
|
||||
if [ ! -f "/proc/net/dev" ]; then
|
||||
echo "/proc/net/dev not found"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
function list_interfaces {
|
||||
check_proc_net_dev
|
||||
echo "Interfaces in /proc/net/dev:"
|
||||
grep -o "^[^:]\\+:" /proc/net/dev | tr -d " :"
|
||||
}
|
||||
|
||||
while getopts i:t:u:p:lh opt; do
|
||||
case "$opt" in
|
||||
i) iface="$OPTARG" ;;
|
||||
t) dt="$OPTARG" ;;
|
||||
u) unit="$OPTARG" ;;
|
||||
p) printf_command="$OPTARG" ;;
|
||||
l) list_interfaces && exit 0 ;;
|
||||
h) printf \
|
||||
"Usage: bandwidth3 [-i interface] [-t time] [-u unit] [-p printf_command] [-l] [-h]
|
||||
Options:
|
||||
-i\tNetwork interface to measure. Default determined using \`ip route\`.
|
||||
-t\tTime interval in seconds between measurements. Default: 3
|
||||
-u\tUnits to measure bytes in. Default: Mb
|
||||
\tAllowed units: Kb, KB, Mb, MB, Gb, GB, Tb, TB
|
||||
\tUnits may have optional it/its/yte/ytes on the end, e.g. Mbits, KByte
|
||||
-p\tAwk command to be called after a measurement is made.
|
||||
\tDefault: printf \"<span font='FontAwesome'> </span>%%-5.1f/%%5.1f %%s/s\\\\n\", rx, wx, unit;
|
||||
\tExposed variables: rx, wx, tx, unit, iface
|
||||
-l\tList available interfaces in /proc/net/dev
|
||||
-h\tShow this help text
|
||||
" && exit 0;;
|
||||
esac
|
||||
done
|
||||
|
||||
check_proc_net_dev
|
||||
|
||||
iface="${iface:-$(default_interface)}"
|
||||
while [ -z "$iface" ]; do
|
||||
echo No default interface
|
||||
sleep "$dt"
|
||||
iface=$(default_interface)
|
||||
done
|
||||
|
||||
case "$unit" in
|
||||
Kb|Kbit|Kbits) bytes_per_unit=$((1024 / 8));;
|
||||
KB|KByte|KBytes) bytes_per_unit=$((1024));;
|
||||
Mb|Mbit|Mbits) bytes_per_unit=$((1024 * 1024 / 8));;
|
||||
MB|MByte|MBytes) bytes_per_unit=$((1024 * 1024));;
|
||||
Gb|Gbit|Gbits) bytes_per_unit=$((1024 * 1024 * 1024 / 8));;
|
||||
GB|GByte|GBytes) bytes_per_unit=$((1024 * 1024 * 1024));;
|
||||
Tb|Tbit|Tbits) bytes_per_unit=$((1024 * 1024 * 1024 * 1024 / 8));;
|
||||
TB|TByte|TBytes) bytes_per_unit=$((1024 * 1024 * 1024 * 1024));;
|
||||
*) echo Bad unit "$unit" && exit 1;;
|
||||
esac
|
||||
|
||||
scalar=$((bytes_per_unit * dt))
|
||||
init_line=$(cat /proc/net/dev | grep "^[ ]*$iface:")
|
||||
if [ -z "$init_line" ]; then
|
||||
echo Interface not found in /proc/net/dev: "$iface"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
init_received=$(awk '{print $2}' <<< $init_line)
|
||||
init_sent=$(awk '{print $10}' <<< $init_line)
|
||||
|
||||
(while true; do cat /proc/net/dev; sleep "$dt"; done) |\
|
||||
stdbuf -oL grep "^[ ]*$iface:" |\
|
||||
awk -v scalar="$scalar" -v unit="$unit" -v iface="$iface" '
|
||||
BEGIN{old_received='"$init_received"';old_sent='"$init_sent"'}
|
||||
{
|
||||
received=$2
|
||||
sent=$10
|
||||
rx=(received-old_received)/scalar;
|
||||
wx=(sent-old_sent)/scalar;
|
||||
tx=rx+wr;
|
||||
old_received=received;
|
||||
old_sent=sent;
|
||||
if(rx >= 0 && wx >= 0){
|
||||
'"$printf_command"';
|
||||
fflush(stdout);
|
||||
}
|
||||
}
|
||||
'
|
11
home/bin/i3blocks/clock
Executable file
11
home/bin/i3blocks/clock
Executable file
@@ -0,0 +1,11 @@
|
||||
#!/bin/sh
|
||||
|
||||
date '+%b %d (%a) %I:%M%p'
|
||||
|
||||
case $BLOCK_BUTTON in
|
||||
1) pgrep -x dunst >/dev/null && notify-send "$(cal --color=always | sed "s/..7m/<b><span color=\"red\">/;s/..27m/<\/span><\/b>/")" && notify-send "$(calcurse -d3)" ;;
|
||||
2) "$TERMINAL" -e calcurse ;;
|
||||
3) pgrep -x dunst >/dev/null && notify-send "<b>📅 Time/date module:</b>
|
||||
- Left click to show upcoming appointments for the next three days via \`calcurse -d3\` and show the month via \`cal\`
|
||||
- Middle click opens calcurse if installed" ;;
|
||||
esac
|
12
home/bin/i3blocks/cpu
Executable file
12
home/bin/i3blocks/cpu
Executable file
@@ -0,0 +1,12 @@
|
||||
#!/bin/sh
|
||||
|
||||
case $BLOCK_BUTTON in
|
||||
1) notify-send "<b>🖥 CPU hogs</b>:
|
||||
$(ps axch -o cmd:15,%cpu --sort=-%cpu | head)" ;;
|
||||
3) notify-send "<b>🖥 CPU module:</b>
|
||||
- Shows CPU temperature.
|
||||
- Click to show intensive processes.
|
||||
- % is of single core." ;;
|
||||
esac
|
||||
|
||||
sensors | awk '/temp1/ {print $2}'
|
BIN
home/bin/i3blocks/cpu_usage
Executable file
BIN
home/bin/i3blocks/cpu_usage
Executable file
Binary file not shown.
20
home/bin/i3blocks/disk
Executable file
20
home/bin/i3blocks/disk
Executable file
@@ -0,0 +1,20 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Status bar module for disk space
|
||||
# $1 should be drive mountpoint
|
||||
# $2 is optional icon, otherwise mountpoint will displayed
|
||||
|
||||
[ -z "$1" ] && exit
|
||||
|
||||
icon="$2"
|
||||
[ -z "$2" ] && icon="$1"
|
||||
|
||||
case $BLOCK_BUTTON in
|
||||
1) pgrep -x dunst >/dev/null && notify-send "<b>💽 Disk space:</b>
|
||||
$(df -h --output=target,used,size)" ;;
|
||||
3) pgrep -x dunst >/dev/null && notify-send "<b>💽 Hard drive space remaining:</b>
|
||||
- Shows used hard drive space.
|
||||
- Click to show all disk info." ;;
|
||||
esac
|
||||
|
||||
printf "%s: %s" "$icon" "$(df -h "$1" | awk ' /[0-9]/ {print $3 "/" $2}')"
|
67
home/bin/i3blocks/gpu-load
Executable file
67
home/bin/i3blocks/gpu-load
Executable file
@@ -0,0 +1,67 @@
|
||||
#! /usr/bin/perl
|
||||
|
||||
# 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/>.
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use utf8;
|
||||
use Getopt::Long;
|
||||
|
||||
# default values
|
||||
my $t_warn = $ENV{T_WARN} || 70;
|
||||
my $t_crit = $ENV{T_CRIT} || 90;
|
||||
my $gpu_usage = -1;
|
||||
my $gpu_mem = -1;
|
||||
my $gpu_video = -1;
|
||||
my $gpu_pcie = -1;
|
||||
|
||||
sub help {
|
||||
print "Usage: gpu-load [-w <warning>] [-c <critical>]\n";
|
||||
print "-w <percent>: warning threshold to become amber\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 GPU usage from nvidia-settings
|
||||
open (NVS, 'nvidia-settings -q GPUUtilization -t |') or die;
|
||||
while (<NVS>) {
|
||||
if (/^[a-zA-Z]*=(\d+), [a-zA-Z]*=(\d+), [a-zA-Z]*=(\d+), [a-zA-Z]*=(\d+)$/) {
|
||||
$gpu_usage = $1;
|
||||
$gpu_mem = $2;
|
||||
$gpu_video = $3;
|
||||
$gpu_pcie = $4;
|
||||
last;
|
||||
}
|
||||
}
|
||||
close(NVS);
|
||||
|
||||
$gpu_usage eq -1 and die 'Can\'t find GPU information';
|
||||
|
||||
# Print full_text, short_text
|
||||
printf "%.0f%% %.0f%% %.0f%% %.0f%%\n", $gpu_usage, $gpu_mem, $gpu_video, $gpu_pcie;
|
||||
printf "%.0f%%\n", $gpu_usage;
|
||||
|
||||
# Print color, if needed
|
||||
if ($gpu_usage >= $t_crit || $gpu_mem >= $t_crit || $gpu_video >= $t_crit || $gpu_pcie >= $t_crit) {
|
||||
print "#FF0000\n";
|
||||
exit 33;
|
||||
} elsif ($gpu_usage >= $t_warn || $gpu_mem >= $t_warn || $gpu_video >= $t_warn || $gpu_pcie >= $t_warn) {
|
||||
print "#FFBF00\n";
|
||||
}
|
||||
|
||||
exit 0;
|
9
home/bin/i3blocks/internet
Executable file
9
home/bin/i3blocks/internet
Executable file
@@ -0,0 +1,9 @@
|
||||
#!/bin/bash
|
||||
|
||||
if ping -c 1 1.1.1.1 > /dev/null 2>&1; then
|
||||
echo "😛"
|
||||
else
|
||||
echo "🤬"
|
||||
echo "$(date)" >> /tmp/internet-outages
|
||||
nfty send "Internet Outage"
|
||||
fi
|
34
home/bin/i3blocks/load_average
Executable file
34
home/bin/i3blocks/load_average
Executable file
@@ -0,0 +1,34 @@
|
||||
#!/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/>.
|
||||
|
||||
load="$(cut -d ' ' -f1 /proc/loadavg)"
|
||||
cpus="$(nproc)"
|
||||
|
||||
# full text
|
||||
echo "$load"
|
||||
|
||||
# short text
|
||||
echo "$load"
|
||||
|
||||
# color if load is too high
|
||||
awk -v cpus=$cpus -v cpuload=$load '
|
||||
BEGIN {
|
||||
if (cpus <= cpuload) {
|
||||
print "#FF0000";
|
||||
exit 33;
|
||||
}
|
||||
}
|
||||
'
|
11
home/bin/i3blocks/memory
Executable file
11
home/bin/i3blocks/memory
Executable file
@@ -0,0 +1,11 @@
|
||||
#!/bin/sh
|
||||
|
||||
case $BLOCK_BUTTON in
|
||||
1) notify-send "<b>🧠 Memory hogs:</b>
|
||||
$(ps axch -o cmd:15,%mem --sort=-%mem | head)" ;;
|
||||
3) notify-send "<b>🧠 Memory module:</b>
|
||||
- Shows Memory Used/Total.
|
||||
- Click to show memory hogs." ;;
|
||||
esac
|
||||
|
||||
free -h | awk '/^Mem:/ {print $3 "/" $2}'
|
3
home/bin/i3blocks/scratchpad
Executable file
3
home/bin/i3blocks/scratchpad
Executable file
@@ -0,0 +1,3 @@
|
||||
#!/bin/bash
|
||||
|
||||
~/bin/i3-dstatus scratchpad
|
35
home/bin/i3blocks/spotify
Executable file
35
home/bin/i3blocks/spotify
Executable file
@@ -0,0 +1,35 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# Created by: https://github.com/firatakandere/i3blocks-spotify
|
||||
|
||||
import dbus
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
||||
try:
|
||||
bus = dbus.SessionBus()
|
||||
spotify = bus.get_object("org.mpris.MediaPlayer2.spotify", "/org/mpris/MediaPlayer2")
|
||||
|
||||
|
||||
if os.environ.get('BLOCK_BUTTON'):
|
||||
control_iface = dbus.Interface(spotify, 'org.mpris.MediaPlayer2.Player')
|
||||
if (os.environ['BLOCK_BUTTON'] == '1'):
|
||||
control_iface.Previous()
|
||||
elif (os.environ['BLOCK_BUTTON'] == '2'):
|
||||
control_iface.PlayPause()
|
||||
elif (os.environ['BLOCK_BUTTON'] == '3'):
|
||||
control_iface.Next()
|
||||
|
||||
spotify_iface = dbus.Interface(spotify, 'org.freedesktop.DBus.Properties')
|
||||
props = spotify_iface.Get('org.mpris.MediaPlayer2.Player', 'Metadata')
|
||||
|
||||
if (sys.version_info > (3, 0)):
|
||||
print(str(props['xesam:artist'][0]) + " - " + str(props['xesam:title']))
|
||||
else:
|
||||
print(props['xesam:artist'][0] + " - " + props['xesam:title']).encode('utf-8')
|
||||
exit
|
||||
except dbus.exceptions.DBusException:
|
||||
exit
|
||||
|
||||
|
8
home/bin/i3blocks/window
Executable file
8
home/bin/i3blocks/window
Executable file
@@ -0,0 +1,8 @@
|
||||
#!/bin/bash
|
||||
|
||||
ACTIVE_WINDOW=$(xprop -id $(xprop -root _NET_ACTIVE_WINDOW | cut -d ' ' -f 5) WM_NAME | cut -d '"' -f 2)
|
||||
|
||||
if [[ "${ACTIVE_WINDOW}" != "" ]]; then
|
||||
echo "${ACTIVE_WINDOW}"
|
||||
echo ""
|
||||
fi
|
Reference in New Issue
Block a user