Skip to content

Commit

Permalink
Merge branch 'master' of github.com:vivien/i3blocks-contrib into next
Browse files Browse the repository at this point in the history
  • Loading branch information
kb100 committed Dec 29, 2018
2 parents 4d91f84 + 735cae7 commit 85fe771
Show file tree
Hide file tree
Showing 41 changed files with 222 additions and 114 deletions.
71 changes: 71 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
= Community contributed blocklets

This repository contains a set of scripts (a.k.a. *blocklets*) for link:https://github.com/vivien/i3blocks[i3blocks], contributed by the community.

|===
| Blocklet | Description
| link:afs[] | Show usage information for an AFS directory
| link:apt-upgrades[] | Show system upgrades using aptitude
| link:arch-update[] | Show AUR updates using yaourt
| link:aur-update[] | Show AUR updates
| link:bandwidth[] | Show bandwidth information (default bash version)
| link:bandwidth2[] | Show bandwidth information (C version)
| link:bandwidth3[] | Show bandwidth information (another bash version)
| link:battery[] | Show battery info
| link:battery2[] | Pretty battery info
| link:batterybar[] | Show battery info graphically as a bar
| link:calendar[] | Current date/time and click for calendar
| link:cpu_usage[] | Show current CPU usage
| link:disk[] | Show disk usage (space used) for a given directory
| link:disk-io[] | Monitor disk reads and writes
| link:docker[] | Show the number of Docker containers and container IP
| link:email[] | Show the number of unread IMAP messages
| link:essid[] | Show the wifi ESSID you are connected to
| link:gpu-load[] | Shows load of Nvidia GPUs
| link:iface[] | Show network interface IP/status
| link:kbdd_layout[] | Show the keyboard layout using dbus and kbdd
| link:keyindicator[] | Show the status of capslock or numlock
| link:key_layout[] | Show the current keyboard layout using setxkbmap
| link:kubernetes[] | Show the kubernetes current context and namespace
| link:load_average[] | Show the system 1 minute load average
| link:mediaplayer[] | Generic media player status/controls using playerctl
| link:memory[] | Show ram or swap usage
| link:monitor_manager[] | Manage monitor on/off, resolution, extend, clone
| link:openvpn[] | Show openvpn status
| link:rofi-calendar[] | Current date/time and click for callendar using rofi
| link:shutdown_menu[] | Shutdown menu using rofi or zenity
| link:tahoe-lafs[] | Show status of your tahoe-lafs grid
| link:temperature[] | Show system temperatures using lm-sensors
| link:time[] | Show the current date/time and click to change timezones
| link:usb[] | Show connected usb storage device info
| link:volume[] | Show the current system volume (default)
| link:volume-pulseaudio[] | Pretty print system volume for pulseaudio
| link:wifi[] | Show the strength of your wifi connection in percent
| link:wlan-dbm[] | Show wifi interface link quality in dBm or percent
| link:ytdl-mpv[] | Play youtube videos from your clipboard using youtube-dl
|===

It is officially maintained by @kb100 with the help of a bench of active i3blocks crafters.

Each release of this repository will be guaranteed to work against a given link:https://github.com/vivien/i3blocks/releases[release] of i3blocks (a.k.a. *core*).

|===
| contrib | core
| master | master
| next | next
|===

You may want to take a look at the individual blocklet directories, which contain descriptions, screenshots, and installation/configuration instructions.

NOTE: configurations reference `$SCRIPT_DIR`, meaning the directory that you put the script into. +
You must change `$SCRIPT_DIR` appropriately to coincide with where you put your scripts, for more info see the link:https://github.com/vivien/i3blocks-contrib/wiki/FAQ#blocklets-refer-to-script_dir-what-does-that-mean-how-can-i-use-it[FAQ].

Want to contribute?
Great!
Check the link:https://github.com/vivien/i3blocks-contrib/blob/master/CONTRIBUTING.md[contribution guidelines] in order to get started.

NOTE: i3blocks now supports dynamics properties, and all scripts have been updated to do the same. +
i3blocks-contrib REQUIRES a version of i3blocks that supports dynamics properties, which is currently only +
available in the git version since the last release (v1.4) was years ago.

Happy crafting!
31 changes: 0 additions & 31 deletions README.md

This file was deleted.

4 changes: 2 additions & 2 deletions afs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ Suggested i3blocks configuration:

```
[afs]
command=$SCRIPT_DIR/afs -c 90
label=AFS
command=$SCRIPT_DIR/afs
instance=~/afs/
markup=pango
interval=600
LABEL=AFS
#CRITICAL=90
#CRIT_FG_COLOR=#FF0000
#CRIT_BG_COLOR=
Expand Down
8 changes: 3 additions & 5 deletions afs/afs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,8 @@ parser.add_argument('-bg', '--bg-color', type=str, default=_default('CRIT_BG_COL
args = parser.parse_args()

# set the afs directory to be checked
if 'BLOCK_INSTANCE' in os.environ:
directory = os.environ['BLOCK_INSTANCE']
else:
directory = '~/afs/' # some default
directory = os.environ.get('BLOCK_INSTANCE', '~/afs/')
label = os.environ.get('LABEL', '')

# expand environment variables etc.
directory = os.path.expandvars(directory)
Expand All @@ -57,7 +55,7 @@ fs_output = fs_output.split('\n')[1]
quota, used, percentage = fs_output.split()[1:4]
percentage = int(percentage.split('%')[0])

output = '%s/%s (%i%%)' % (used, quota, percentage)
output = '%s%s/%s (%i%%)' % (label, used, quota, percentage)

if percentage >= args.critical:
if args.bg_color:
Expand Down
4 changes: 2 additions & 2 deletions arch-update/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,13 @@ Be always on top of your available updates with this blocklet. Optionally show A
```ini
[arch-update]
command=$SCRIPT_DIR/arch-update
label=Updates:
interval=3600
markup=pango
LABEL=Updates:
```
Another advanced example with fontawesome label, AUR updates included, watched packages, and custom colors for both messages:
```ini
[pacman-updates]
label=
command=$SCRIPT_DIR/arch-update
markup=pango
interval= 3600
Expand All @@ -42,6 +41,7 @@ WATCH=^linux.* ^pacman.*
BASE_COLOR=#5fff5f
UPDATE_COLOR=#FFFF85
AUR=true
LABEL=
```
# Configuration
_Use the environment variables above instead of these deprecated command line options:_
Expand Down
9 changes: 5 additions & 4 deletions arch-update/arch-update
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ def matching_updates(updates, watch_list):
return matches


message = "<span color='{0}'>{1}</span>"
label = os.environ.get("LABEL","")
message = "{0}<span color='{1}'>{2}</span>"
args = create_argparse()

updates = get_updates()
Expand All @@ -117,7 +118,7 @@ if update_count > 0:
if matches:
info += ' [{0}]'.format(', '.join(matches))
short_info += '*'
print(message.format(args.updates_available_color, info))
print(message.format(args.updates_available_color, short_info))
print(message.format(label, args.updates_available_color, info))
print(message.format(label, args.updates_available_color, short_info))
elif not args.quiet:
print(message.format(args.base_color, 'system up to date'))
print(message.format(label, args.base_color, 'system up to date'))
5 changes: 4 additions & 1 deletion bandwidth/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# bandwidth

Show bandwidth information
Show bandwidth information. Some interfaces report unknown instead of up for
their state. If you would like to treat unknowns as up, then set
`TREAT_UNKNOWN_AS_UP=1`.

![](bandwidth.png)

Expand All @@ -13,4 +15,5 @@ interval=5
#INTERFACE=eth0
#INLABEL="IN "
#OUTLABEL="OUT "
#TREAT_UNKNOWN_AS_UP=0
```
7 changes: 6 additions & 1 deletion bandwidth/bandwidth
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,13 @@ elif [[ -z $INTERFACE ]]; then
INTERFACE=$(ip route | awk '/^default/ { print $5 ; exit }')
fi

# Exit if there is no default route
[[ -z "$INTERFACE" ]] && exit

# Issue #36 compliant.
if ! [ -e "/sys/class/net/${INTERFACE}/operstate" ] || ! [ "`cat /sys/class/net/${INTERFACE}/operstate`" = "up" ]
if ! [ -e "/sys/class/net/${INTERFACE}/operstate" ] || \
(! [ "$TREAT_UNKNOWN_AS_UP" = "1" ] &&
! [ "`cat /sys/class/net/${INTERFACE}/operstate`" = "up" ])
then
echo "$INTERFACE down"
echo "$INTERFACE down"
Expand Down
4 changes: 2 additions & 2 deletions bandwidth2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ make
### Config
```ini
[bandwidth]
label=
command=$SCRIPT_DIR/bandwidth2
interval=persist
markup=pango
LABEL=
#INTERFACE=(checks all interfaces)
#USE_BITS=0
#USE_BYES=1
Expand All @@ -36,10 +36,10 @@ E.g.

```ini
[bandwidth]
label=
command=$SCRIPT_DIR/bandwidth2
interval=persist
markup=pango
LABEL=
WARN_RX=307200
WARN_TX=30720
CRIT_RX=512000
Expand Down
58 changes: 46 additions & 12 deletions bandwidth2/bandwidth2.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#define _DEFAULT_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
Expand All @@ -24,14 +25,15 @@ void usage(char *argv[])
printf("-b \t\tuse bits/s\n");
printf("-B \t\tuse Bytes/s (default)\n");
printf("-t seconds\trefresh time (default is 1)\n");
printf("-i interface\tnetwork interface to monitor. If not specified, check all interfaces.\n");
printf("-i interfaces\tnetwork interfaces to monitor (comma separated).\n");
printf(" \tIf not specified, check all interfaces.\n");
printf("-w Bytes:Bytes\tSet warning (color orange) for Rx:Tx bandwidth. (default: none)\n");
printf("-c Bytes:Bytes\tSet critical (color red) for Rx:Tx bandwidth. (default: none)\n");
printf("-h \t\tthis help\n");
printf("\n");
}

void get_values(char *const iface, time_t * const s, ulli * const received, ulli * const sent)
void get_values(char **const ifaces, int num_ifaces, time_t * const s, ulli * const received, ulli * const sent)
{
FILE *f;

Expand All @@ -42,18 +44,23 @@ void get_values(char *const iface, time_t * const s, ulli * const received, ulli
}

ulli temp_r, temp_s;
char line[BUFSIZ];
char line[BUFSIZ] = {0};
char ifname[BUFSIZ];

*received = 0;
*sent = 0;
while (fgets(line, BUFSIZ - 1, f) != NULL) {
if (sscanf(line, "%s %llu %*u %*u %*u %*u %*u %*u %*u %llu", ifname, &temp_r, &temp_s) == 3) {
if (iface && strcmp(iface, ifname) != 0) {
continue;
if (sscanf(line, "%[^:]: %llu %*u %*u %*u %*u %*u %*u %*u %llu", ifname, &temp_r, &temp_s) == 3) {
int i;
int iface_found = num_ifaces == 0;
for (i = 0; i < num_ifaces; i++) {
if (strcmp(ifaces[i], ifname) != 0) {
iface_found = 1;
break;
}
}

if (strcmp(ifname, "lo:") == 0)
if (!iface_found || strcmp(ifname, "lo") == 0)
continue;

*received = *received + temp_r;
Expand Down Expand Up @@ -95,12 +102,28 @@ void display(int const unit, double b, int const warning, int const critical)
printf("</span>");
}

void parse_ifaces(char *str, char ***ifaces, int *num_ifaces)
{
int max_ifaces = strlen(str) / 2 + 1;

*ifaces = calloc(max_ifaces, sizeof (char *));
*num_ifaces = 0;
while (((*ifaces)[*num_ifaces] = strsep(&str, ","))) {
if ((*ifaces)[*num_ifaces] != NULL && (*ifaces)[*num_ifaces][0] != '\0') {
(*num_ifaces)++;
}
}
}

int main(int argc, char *argv[])
{
int c, unit = 'B', t = 1;
char iface[BUFSIZ] = {0};
char str_ifaces[BUFSIZ] = {0};
char **ifaces;
int num_ifaces;
int warningrx = 0, warningtx = 0, criticalrx = 0, criticaltx = 0;
char *envvar = NULL;
char *label = "";

envvar = getenv("USE_BITS");
if (envvar && *envvar == '1')
Expand All @@ -113,7 +136,10 @@ int main(int argc, char *argv[])
t = atoi(envvar);
envvar = getenv("INTERFACE");
if (envvar)
snprintf(iface, BUFSIZ, "%s:", envvar);
snprintf(str_ifaces, BUFSIZ, "%s", envvar);
envvar = getenv("INTERFACES");
if (envvar)
snprintf(str_ifaces, BUFSIZ, "%s", envvar);
envvar = getenv("WARN_RX");
if (envvar)
warningrx = atoi(envvar);
Expand All @@ -126,6 +152,9 @@ int main(int argc, char *argv[])
envvar = getenv("CRIT_TX");
if (envvar)
criticaltx = atoi(envvar);
envvar = getenv("LABEL");
if (envvar)
label = envvar;

while (c = getopt(argc, argv, "bBht:i:w:c:"), c != -1) {
switch (c) {
Expand All @@ -137,7 +166,7 @@ int main(int argc, char *argv[])
t = atoi(optarg);
break;
case 'i':
snprintf(iface, BUFSIZ, "%s:", optarg);
snprintf(str_ifaces, BUFSIZ, "%s", optarg);
break;
case 'w':
sscanf(optarg, "%d:%d", &warningrx, &warningtx);
Expand All @@ -151,26 +180,31 @@ int main(int argc, char *argv[])
}
}

parse_ifaces(str_ifaces, &ifaces, &num_ifaces);

time_t s, s_old;
ulli received, sent, received_old, sent_old;
double rx, tx;

get_values(iface, &s_old, &received_old, &sent_old);
get_values(ifaces, num_ifaces, &s_old, &received_old, &sent_old);

while (1) {
sleep(t);
get_values(iface[0] ? iface : NULL, &s, &received, &sent);
get_values(ifaces, num_ifaces, &s, &received, &sent);

rx = (received - received_old) / (float)(s - s_old);
tx = (sent - sent_old) / (float)(s - s_old);
printf("%s", label);
display(unit, rx, warningrx, criticalrx);
printf(" ");
display(unit, tx, warningtx, criticaltx);
printf("\n");
fflush(stdout);
s_old = s;
received_old = received;
sent_old = sent;
}

free(ifaces);
return STATE_OK;
}
Loading

0 comments on commit 85fe771

Please sign in to comment.