aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xconfig/i3blocks/bandwidth85
-rw-r--r--config/i3blocks/config54
-rwxr-xr-xconfig/i3blocks/scripts/iface34
-rwxr-xr-xconfig/i3blocks/scripts/wifi4
4 files changed, 101 insertions, 76 deletions
diff --git a/config/i3blocks/bandwidth b/config/i3blocks/bandwidth
new file mode 100755
index 0000000..97b2018
--- /dev/null
+++ b/config/i3blocks/bandwidth
@@ -0,0 +1,85 @@
+#!/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/>.
+
+INTERFACE=$(ip route | awk '/^default .* (wlp|enp)/ { print $5 ; 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"
+ exit 0
+fi
+
+# path to store the old results in
+path="/dev/shm/$(basename $0)-${INTERFACE}"
+
+# grabbing data for each adapter.
+read rx < "/sys/class/net/${INTERFACE}/statistics/rx_bytes"
+read 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 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 ]] || 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
+echo -n "IN "
+rx_kib=$(( $rx_rate >> 10 ))
+if [[ "$rx_rate" -gt 1048576 ]]; then
+ printf '%sM' "`echo "scale=1; $rx_kib / 1024" | bc`"
+else
+ echo -n "${rx_kib}K"
+fi
+
+echo -n " "
+
+# outgoing
+echo -n "OUT "
+tx_kib=$(( $tx_rate >> 10 ))
+if [[ "$tx_rate" -gt 1048576 ]]; then
+ printf '%sM' "`echo "scale=1; $tx_kib / 1024" | bc`"
+else
+ echo -n "${tx_kib}K"
+fi
diff --git a/config/i3blocks/config b/config/i3blocks/config
index 1ff0616..116e2bd 100644
--- a/config/i3blocks/config
+++ b/config/i3blocks/config
@@ -49,10 +49,8 @@ signal=13
# The second parameter overrides the mixer selection
# See the script for details.
[volume]
-#label=VOL
label=♪
instance=Master
-#instance=PCM
interval=once
signal=10
@@ -61,7 +59,6 @@ signal=10
# The script may be called with -w and -c switches to specify thresholds,
# see the script for details.
[cpu_usage]
-#label=CPU
label=cpu
interval=10
separator=false
@@ -69,8 +66,8 @@ separator=false
# Memory usage
#
# The type defaults to "mem" if the instance is not specified.
+# You can specify "swap".
[memory]
-#label=MEM
label=mem
interval=30
@@ -78,12 +75,6 @@ interval=30
command=~/.config/i3blocks/scripts/bbswitch
interval=5
-#[memory]
-#label=SWAP
-#instance=swap
-#separator=false
-#interval=30
-
# Disk usage
#
# The directory defaults to $HOME if the instance is not specified.
@@ -105,45 +96,30 @@ interval=30
# The address can be forced to IPv4 or IPv6 with -4 or -6 switches.
[iface]
command=~/.config/i3blocks/scripts/iface
-instance=enp4s0 wlp3s0
interval=2
separator=false
[bandwidth]
-#instance=eth0
+command=~/.config/i3blocks/scripts/bandwidth
interval=2
[wifi]
command=~/.config/i3blocks/scripts/wifi
-instance=wlp3s0
interval=2
-# OpenVPN support
-#
-# Support multiple VPN, with colors.
-#[openvpn]
-#interval=20
-
# Temperature
#
# Support multiple chips, though lm-sensors.
# The script may be called with -w and -c switches to specify thresholds,
# see the script for details.
[temperature]
-#label=T
interval=10
-#[load_average]
-#interval=10
-
# Battery indicator
#
# The battery instance defaults to 0.
[battery]
command=~/.config/i3blocks/scripts/battery
-#label=BAT
-#label=⚡
-#instance=1
interval=30
[email]
@@ -151,32 +127,6 @@ command=~/.config/i3blocks/scripts/email
interval=30
# Date Time
-#
[time]
command=date '+%Y-%m-%d %H:%M:%S'
interval=1
-
-# Generic media player support
-#
-# This displays "ARTIST - SONG" if a music is playing.
-# Supported players are: spotify, vlc, audacious, xmms2, mplayer, and others.
-#[mediaplayer]
-#instance=mpd
-#interval=5
-#signal=10
-
-# Key indicators
-#
-# Add the following bindings to i3 config file:
-#
-# bindsym --release Caps_Lock exec pkill -SIGRTMIN+11 i3blocks
-# bindsym --release Num_Lock exec pkill -SIGRTMIN+11 i3blocks
-#[keyindicator]
-#instance=CAPS
-#interval=once
-#signal=11
-
-#[keyindicator]
-#instance=NUM
-#interval=once
-#signal=11
diff --git a/config/i3blocks/scripts/iface b/config/i3blocks/scripts/iface
index 7e6ac50..a0a1946 100755
--- a/config/i3blocks/scripts/iface
+++ b/config/i3blocks/scripts/iface
@@ -17,19 +17,9 @@
#------------------------------------------------------------------------
-# Locate current default interface
-D_IF=$(ip route | awk '/^default/ { print $5 ; exit }')
-# Filter if it's one of chosen ones
-if [[ -n $BLOCK_INSTANCE ]]; then
- for INT in $BLOCK_INSTANCE; do
- if [ "$INT" = "$D_IF" ]; then
- IF="$D_IF"
- break
- fi
- done
-else
- IF="$D_IF"
-fi
+# Locate current default interface, but use only wlp (wifi) or enp (ethernet)
+# TODO probably also add connection over phone
+IF=$(ip route | awk '/^default .* (wlp|enp)/ { print $5 ; exit }')
#------------------------------------------------------------------------
@@ -40,7 +30,7 @@ fi
#------------------------------------------------------------------------
-# If no IF is selected then we want se down not anything else.
+# If no IF is selected then we want see down, not anything else.
if [ -z "$IF" ] || [[ "$(cat /sys/class/net/$IF/operstate)" = 'down' ]]; then
echo down # full text
echo down # short text
@@ -49,19 +39,19 @@ if [ -z "$IF" ] || [[ "$(cat /sys/class/net/$IF/operstate)" = 'down' ]]; then
fi
case $1 in
- -4)
- AF=inet ;;
- -6)
- AF=inet6 ;;
- *)
- AF=inet6? ;;
+ -4)
+ AF=inet ;;
+ -6)
+ AF=inet6 ;;
+ *)
+ AF=inet6? ;;
esac
# Use the first global scope address
IPADDR=$(ip addr show $IF | perl -n -e "/$AF ([^\/]+).* scope global/ && print \$1 and exit")
case $BLOCK_BUTTON in
- 3) echo -n "$IPADDR" | xclip -q -se c ;;
+ 3) echo -n "$IPADDR" | xclip -q -se c ;;
esac
#------------------------------------------------------------------------
@@ -70,7 +60,7 @@ echo "$IPADDR" # full text
echo "$IPADDR" # short text
#------------------------------------------------------------------------
-# Use fast ping to check if we have connection
+# Use ping to check if we have connection
# We ping only once and wait for one second
PINGV="-c 1 -w 1"
diff --git a/config/i3blocks/scripts/wifi b/config/i3blocks/scripts/wifi
index a8af5e4..d549b10 100755
--- a/config/i3blocks/scripts/wifi
+++ b/config/i3blocks/scripts/wifi
@@ -16,7 +16,7 @@
#------------------------------------------------------------------------
-INTERFACE="${BLOCK_INSTANCE:-wlan0}"
+INTERFACE="$(ip link | awk '/wlp.*/ {print substr($2, 1, length($2)-1); exit}')"
#------------------------------------------------------------------------
@@ -32,7 +32,7 @@ SSID=$(iwgetid $INTERFACE | sed 's/.*ESSID:"\([^"]*\)"/\1/')
#------------------------------------------------------------------------
-echo $SSID: $QUALITY% # full text
+echo $SSID $QUALITY% # full text
echo $SSID # short text
# color