diff --git a/README.adoc b/README.adoc new file mode 100644 index 00000000..6d2ff9a1 --- /dev/null +++ b/README.adoc @@ -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! diff --git a/README.md b/README.md deleted file mode 100644 index 7e9dc2f3..00000000 --- a/README.md +++ /dev/null @@ -1,31 +0,0 @@ -# Community contributed blocklets - -This repository contains a set of scripts (a.k.a. *blocklets*) for -[i3blocks](https://github.com/vivien/i3blocks), contributed by the -community. - -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 [release](https://github.com/vivien/i3blocks/releases) of -i3blocks (a.k.a. *core*). - -contrib | core -------- | ---- -master | master - -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 [FAQ](https://github.com/vivien/i3blocks-contrib/wiki/FAQ#blocklets-refer-to-script_dir-what-does-that-mean-how-can-i-use-it). - -Want to contribute? -Great! -Check the [contribution guidelines](https://github.com/vivien/i3blocks-contrib/blob/master/CONTRIBUTING.md) -in order to get started. - -Happy crafting! diff --git a/afs/README.md b/afs/README.md index bbe9c4f2..86a60653 100644 --- a/afs/README.md +++ b/afs/README.md @@ -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= diff --git a/afs/afs b/afs/afs index 8353a43d..8d619679 100755 --- a/afs/afs +++ b/afs/afs @@ -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) @@ -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: diff --git a/arch-update/README.md b/arch-update/README.md index 6657f156..34232af5 100644 --- a/arch-update/README.md +++ b/arch-update/README.md @@ -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 @@ -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:_ diff --git a/arch-update/arch-update b/arch-update/arch-update index 9dfec462..59044ede 100755 --- a/arch-update/arch-update +++ b/arch-update/arch-update @@ -102,7 +102,8 @@ def matching_updates(updates, watch_list): return matches -message = "{1}" +label = os.environ.get("LABEL","") +message = "{0}{2}" args = create_argparse() updates = get_updates() @@ -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')) diff --git a/bandwidth/README.md b/bandwidth/README.md index fbd271af..8b01bd39 100644 --- a/bandwidth/README.md +++ b/bandwidth/README.md @@ -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) @@ -13,4 +15,5 @@ interval=5 #INTERFACE=eth0 #INLABEL="IN " #OUTLABEL="OUT " +#TREAT_UNKNOWN_AS_UP=0 ``` diff --git a/bandwidth/bandwidth b/bandwidth/bandwidth index 1259366b..a41efb21 100755 --- a/bandwidth/bandwidth +++ b/bandwidth/bandwidth @@ -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" diff --git a/bandwidth2/README.md b/bandwidth2/README.md index e8e11528..5dc60cf4 100644 --- a/bandwidth2/README.md +++ b/bandwidth2/README.md @@ -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 @@ -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 diff --git a/bandwidth2/bandwidth2.c b/bandwidth2/bandwidth2.c index 76ac4ef9..894fe488 100644 --- a/bandwidth2/bandwidth2.c +++ b/bandwidth2/bandwidth2.c @@ -1,3 +1,4 @@ +#define _DEFAULT_SOURCE #include #include #include @@ -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; @@ -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; @@ -95,12 +102,28 @@ void display(int const unit, double b, int const warning, int const critical) printf(""); } +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') @@ -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); @@ -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) { @@ -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); @@ -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; } diff --git a/bandwidth3/README.md b/bandwidth3/README.md index 4fd8aef6..32d600bb 100644 --- a/bandwidth3/README.md +++ b/bandwidth3/README.md @@ -11,11 +11,12 @@ Monitor bandwidth usage. command=$SCRIPT_DIR/bandwidth3 interval=persist markup=pango +#LABEL= #IFACE=[automatically determined] #DT=3 #UNIT=Mb # Exposed variables: rx, wx, tx, unit, iface -#PRINTF_COMMAND=printf " %-5.1f/%5.1f %s/s\n", rx, wx, unit; +#PRINTF_COMMAND=printf "${LABEL}%-5.1f/%5.1f %s/s\n", rx, wx, unit; ``` Note that the interface will be guessed using `ip route` but it can also be specified diff --git a/bandwidth3/bandwidth3 b/bandwidth3/bandwidth3 index 6f74067c..53868a55 100755 --- a/bandwidth3/bandwidth3 +++ b/bandwidth3/bandwidth3 @@ -9,8 +9,8 @@ iface="${BLOCK_INSTANCE}" iface="${IFACE:-$iface}" dt="${DT:-3}" unit="${UNIT:-Mb}" -label=" " # down arrow up arrow -printf_command="${PRINTF_COMMAND:-"printf \"${label}%-5.1f/%5.1f %s/s\\n\", rx, wx, unit;"}" +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}' diff --git a/bandwidth3/i3blocks.conf b/bandwidth3/i3blocks.conf index 407bbec4..b2930c3a 100644 --- a/bandwidth3/i3blocks.conf +++ b/bandwidth3/i3blocks.conf @@ -2,8 +2,9 @@ command=$SCRIPT_DIR/bandwidth3 interval=persist markup=pango +#LABEL= #IFACE=[automatically determined] #DT=3 #UNIT=Mb # Exposed variables: rx, wx, tx, unit, iface -#PRINTF_COMMAND=printf " %-5.1f/%5.1f %s/s\n", rx, wx, unit; +#PRINTF_COMMAND=printf "${LABEL}%-5.1f/%5.1f %s/s\n", rx, wx, unit; diff --git a/battery/README.md b/battery/README.md index 939e60b0..5f14bdb7 100644 --- a/battery/README.md +++ b/battery/README.md @@ -13,8 +13,8 @@ Show battery info. ``` [battery] command=$SCRIPT_DIR/battery -label=BAT -#label=⚡ interval=30 +LABEL=BAT +#LABEL=⚡ #BAT_NUMBER=0 ``` diff --git a/battery/battery b/battery/battery index b09166d0..b5f0a576 100755 --- a/battery/battery +++ b/battery/battery @@ -23,20 +23,25 @@ my $ac_adapt; my $full_text; my $short_text; my $bat_number = $ENV{BAT_NUMBER} || 0; +my $label = $ENV{LABEL} || ""; # read the first line of the "acpi" command output -open (ACPI, "acpi -b | grep 'Battery $bat_number' |") or die; +open (ACPI, "acpi -b 2>/dev/null| grep 'Battery $bat_number' |") or die; $acpi = ; close(ACPI); # fail on unexpected output -if ($acpi !~ /: (\w+), (\d+)%/) { +if (not defined($acpi)) { + # don't print anything to stderr if there is no battery + exit(0); +} +elsif ($acpi !~ /: ([\w\s]+), (\d+)%/) { die "$acpi\n"; } $status = $1; $percent = $2; -$full_text = "$percent%"; +$full_text = "$label$percent%"; if ($status eq 'Discharging') { $full_text .= ' DIS'; diff --git a/battery/i3blocks.conf b/battery/i3blocks.conf index d42ea0a4..18b39683 100644 --- a/battery/i3blocks.conf +++ b/battery/i3blocks.conf @@ -1,6 +1,6 @@ [battery] command=$SCRIPT_DIR/battery -label=BAT -#label=⚡ interval=30 +LABEL=BAT +#LABEL=⚡ #BAT_NUMBER=0 diff --git a/calendar/README.md b/calendar/README.md index 84770889..bf29b5b9 100644 --- a/calendar/README.md +++ b/calendar/README.md @@ -22,8 +22,8 @@ This is similar to the rofi-calendar blocklet, but without the rofi dependency a ```ini [calendar] command=$SCRIPT_DIR/calendar -label= interval=1 +LABEL= DATEFMT=+%H:%M:%S # SHORTFMT=+%H:%M:%S HEIGHT=180 diff --git a/calendar/calendar b/calendar/calendar index d66bcfd0..4ec7d813 100755 --- a/calendar/calendar +++ b/calendar/calendar @@ -36,5 +36,5 @@ case "$BLOCK_BUTTON" in --posx=$posX --posy=$posY \ > /dev/null" esac -date "$DATEFMT" -date "$SHORTFMT" +echo "$LABEL$(date "$DATEFMT")" +echo "$LABEL$(date "$SHORTFMT")" diff --git a/config.example b/config.example index 5bc6e64b..bf04f603 100644 --- a/config.example +++ b/config.example @@ -36,7 +36,6 @@ markup=none # See the script for details. [volume] -command=$SCRIPT_DIR/volume #label=♪ label=VOL interval=once diff --git a/cpu_usage/README.md b/cpu_usage/README.md index f5b63230..f6d8045e 100644 --- a/cpu_usage/README.md +++ b/cpu_usage/README.md @@ -13,8 +13,8 @@ Show CPU usage. ``` [cpu_usage] command=$SCRIPT_DIR/cpu_usage -label=CPU interval=10 +LABEL=CPU #min_width=CPU: 100.00% #T_WARN=50 #T_CRIT=80 diff --git a/cpu_usage/cpu_usage b/cpu_usage/cpu_usage index 648b4ae9..44c1189d 100755 --- a/cpu_usage/cpu_usage +++ b/cpu_usage/cpu_usage @@ -12,10 +12,11 @@ use utf8; use Getopt::Long; # default values -my $t_warn = $ENV{T_WARN} || 50; -my $t_crit = $ENV{T_CRIT} || 80; +my $t_warn = $ENV{T_WARN} // 50; +my $t_crit = $ENV{T_CRIT} // 80; my $cpu_usage = -1; -my $decimals = $ENV{DECIMALS} || 2; +my $decimals = $ENV{DECIMALS} // 2; +my $label = $ENV{LABEL} // ""; sub help { print "Usage: cpu_usage [-w ] [-c ] [-d ]\n"; @@ -45,7 +46,9 @@ close(MPSTAT); $cpu_usage eq -1 and die 'Can\'t find CPU information'; # Print short_text, full_text +print "${label}"; printf "%.${decimals}f%%\n", $cpu_usage; +print "${label}"; printf "%.${decimals}f%%\n", $cpu_usage; # Print color, if needed diff --git a/cpu_usage/i3blocks.conf b/cpu_usage/i3blocks.conf index 239fa0dd..413c38da 100644 --- a/cpu_usage/i3blocks.conf +++ b/cpu_usage/i3blocks.conf @@ -1,7 +1,7 @@ [cpu_usage] command=$SCRIPT_DIR/cpu_usage -label=CPU interval=10 +LABEL=CPU #min_width=CPU: 100.00% #T_WARN=50 #T_CRIT=80 diff --git a/disk-io/README.md b/disk-io/README.md index 8e10fac6..5f753011 100644 --- a/disk-io/README.md +++ b/disk-io/README.md @@ -14,11 +14,11 @@ iostat (sysstat package), fontawesome for the  hard disk icon (fonts-font-aw ``` [disk-io] -label= command=$SCRIPT_DIR/disk-io #command=$SCRIPT_DIR/disk-io -w 3 -M -P 0 interval=persist markup=pango +LABEL= #instance=/^sda/ #DT=5 #MB_ONLY=0 #0 or 1 diff --git a/disk-io/disk-io b/disk-io/disk-io index 6e89bef5..b6bebc2f 100755 --- a/disk-io/disk-io +++ b/disk-io/disk-io @@ -5,7 +5,7 @@ # # i3blocks blocklet script to monitor disk io -label="${PREFIX:-""}" +label="${LABEL:-""}" dt="${DT:-5}" MB_only="${MB_ONLY:-0}" kB_only="${KB_ONLY:-0}" diff --git a/disk/README.md b/disk/README.md index a1911682..d07c7508 100644 --- a/disk/README.md +++ b/disk/README.md @@ -12,7 +12,7 @@ which is disabled by default. ``` [disk] command=$SCRIPT_DIR/disk -label=HOME +LABEL=HOME #DIR=$HOME #ALERT_LOW=10 interval=30 diff --git a/disk/disk b/disk/disk index 47e769df..c34240d7 100755 --- a/disk/disk +++ b/disk/disk @@ -24,13 +24,13 @@ if [ "$1" = "-n" ] || [ "$2" = "-n" ]; then LOCAL_FLAG="" fi -df -h -P $LOCAL_FLAG "$DIR" | awk -v alert_low=$ALERT_LOW ' +df -h -P $LOCAL_FLAG "$DIR" | awk -v label="$LABEL" -v alert_low=$ALERT_LOW ' /\/.*/ { # full text - print $4 + print label $4 # short text - print $4 + print label $4 use=$5 diff --git a/disk/i3blocks.conf b/disk/i3blocks.conf index 5f8890ac..4295b02e 100644 --- a/disk/i3blocks.conf +++ b/disk/i3blocks.conf @@ -1,5 +1,5 @@ [disk] command=$SCRIPT_DIR/disk -label=HOME +LABEL=HOME #DIR=/mnt/data interval=30 diff --git a/docker/README.md b/docker/README.md index 58119960..c6892d0a 100644 --- a/docker/README.md +++ b/docker/README.md @@ -13,7 +13,7 @@ Show the number of running `Docker` containers and latest created container IP a ``` [docker] command=$SCRIPT_DIR/docker -label=🐳 color=#0db7ed interval=10 +LABEL=🐳 ``` diff --git a/docker/docker b/docker/docker index d38271fa..5819cf9a 100755 --- a/docker/docker +++ b/docker/docker @@ -5,4 +5,4 @@ count=$(docker ps -q | wc -l | sed -r 's/^0$//g') # Recent docker container IP recent_ip=$(docker inspect -f "{{ .NetworkSettings.IPAddress }}" $(docker ps -ql)) -echo "$count: $recent_ip" +echo "$LABEL$count: $recent_ip" diff --git a/docker/i3blocks.conf b/docker/i3blocks.conf index e3c26c45..5a8106ad 100644 --- a/docker/i3blocks.conf +++ b/docker/i3blocks.conf @@ -1,5 +1,5 @@ [docker] command=$SCRIPT_DIR/docker -label=🐳 color=#0db7ed interval=10 +LABEL=🐳 diff --git a/iface/README.md b/iface/README.md index d4d95305..e60e7b9e 100644 --- a/iface/README.md +++ b/iface/README.md @@ -2,9 +2,8 @@ Show network interface status. If the instance is not specified, it uses the interface for the default route. -To display the label of the default interface, pass the -L switch. - -The address can be forced to IPv4 or IPv6 with -4 or -6 switches. +Specify ipv6, ipv4, or either by setting `ADDRESS_FAMILY` to +`inet6`, `inet`, or `inet6?`. If an invalid interface is specified, nothing is printed. @@ -17,8 +16,9 @@ If an invalid interface is specified, nothing is printed. ``` [iface] command=$SCRIPT_DIR/iface -#label=wlan0: +#LABEL=wlan0: #IFACE=wlan0 +#ADDRESS_FAMILY=inet6? color=#00FF00 interval=10 ``` diff --git a/iface/i3blocks.conf b/iface/i3blocks.conf index 9c091dd3..1202a852 100644 --- a/iface/i3blocks.conf +++ b/iface/i3blocks.conf @@ -1,6 +1,7 @@ [iface] command=$SCRIPT_DIR/iface -#label=wlan0: +#LABEL=wlan0: #IFACE=wlan0 +#ADDRESS_FAMILY=inet6? color=#00FF00 interval=10 diff --git a/iface/iface b/iface/iface index 21263d24..75baa947 100755 --- a/iface/iface +++ b/iface/iface @@ -21,6 +21,9 @@ IF="${IFACE:-$BLOCK_INSTANCE}" IF="${IF:-$(ip route | awk '/^default/ { print $5 ; exit }')}" +# Exit if there is no default route +[[ -z "$IF" ]] && exit + #------------------------------------------------------------------------ # As per #36 -- It is transparent: e.g. if the machine has no battery or wireless @@ -29,8 +32,8 @@ IF="${IF:-$(ip route | awk '/^default/ { print $5 ; exit }')}" #------------------------------------------------------------------------ -AF=inet6? -LABEL="" +AF=${ADDRESS_FAMILY:-inet6?} +LABEL="${LABEL:-}" for flag in "$1" "$2"; do case "$flag" in @@ -55,7 +58,7 @@ if [[ "$IF" = "" ]] || [[ "$(cat /sys/class/net/$IF/operstate)" = 'down' ]]; the fi # if no interface is found, use the first device with a global scope -IPADDR=$(ip addr show $IF | perl -n -e "/$AF ([^\/]+).* scope global/ && print \$1 and exit") +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 ;; diff --git a/mediaplayer/mediaplayer b/mediaplayer/mediaplayer index 718e335b..f70a409d 100755 --- a/mediaplayer/mediaplayer +++ b/mediaplayer/mediaplayer @@ -120,6 +120,7 @@ sub playerctl { buttons('playerctl'); my $artist = qx(playerctl $player_arg metadata artist); + chomp $artist; # exit status will be nonzero when playerctl cannot find your player exit(0) if $? || $artist eq '(null)'; diff --git a/memory/memory b/memory/memory index 2dfaca36..90eb2c65 100755 --- a/memory/memory +++ b/memory/memory @@ -59,11 +59,11 @@ END { # color if (pct > 90) { - print("#FF0000\n") + print("#FF0000") } else if (pct > 80) { - print("#FFAE00\n") + print("#FFAE00") } else if (pct > 70) { - print("#FFF600\n") + print("#FFF600") } } ' /proc/meminfo diff --git a/rofi-calendar/README.md b/rofi-calendar/README.md index 4127f6d2..1fa748e0 100644 --- a/rofi-calendar/README.md +++ b/rofi-calendar/README.md @@ -1,6 +1,6 @@ # rofi-calendar -Have a minimal calendar pop up in rofi when clicking the date blocklet +Have a minimal calendar pop up in rofi when clicking the date blocklet (right click to show next month) ![](screenshot.png) @@ -20,8 +20,8 @@ Have a minimal calendar pop up in rofi when clicking the date blocklet ```ini [rofi-calendar] command=$SCRIPT_DIR/rofi-calendar -label= interval=3600 +LABEL= #DATEFTM=+%a. %d. %b. %Y #SHORTFTM=+%d.%m.%Y ``` diff --git a/rofi-calendar/rofi-calendar b/rofi-calendar/rofi-calendar index 637c873e..d4f2ec29 100755 --- a/rofi-calendar/rofi-calendar +++ b/rofi-calendar/rofi-calendar @@ -2,12 +2,23 @@ DATEFTM="${DATEFTM:-+%a. %d. %b. %Y}" SHORTFMT="${SHORTFMT:-+%d.%m.%Y}" +LABEL="${LABEL:-}" blockdate=$(date "$DATEFTM") +shortblockdate=$(date "$SHORTFMT") +year=$(date '+%Y') +month=$(date '+%m') case "$BLOCK_BUTTON" in - 1|2|3) date=$(date '+%A, %d. %B') + 1|2) + date=$(date '+%A, %d. %B');; + 3) + (( month == 12 )) && month=1 && year=$((year + 1)) || month=$((month + 1)) + date=$(cal $month $year | sed -n '1s/^ *//;1s/ *$//p') +esac +case "$BLOCK_BUTTON" in + 1|2|3) export TERM=xterm -cal --color=always \ +cal --color=always $month $year \ | sed 's/\x1b\[[7;]*m/\\/g' \ | sed 's/\x1b\[[27;]*m/\<\/u\>\<\/b\>/g' \ | tail -n +2 \ @@ -25,5 +36,5 @@ cal --color=always \ -no-custom \ -p "$date" > /dev/null esac -echo "$blockdate" -date "$SHORTFMT" +echo "$LABEL$blockdate" +echo "$LABEL$shortblockdate" diff --git a/shutdown_menu/shutdown_menu b/shutdown_menu/shutdown_menu index c826e1aa..3949d6fd 100755 --- a/shutdown_menu/shutdown_menu +++ b/shutdown_menu/shutdown_menu @@ -138,7 +138,7 @@ function prepare_launcher() { -hlfg "${HLFG_COLOR}" -hlbg "${HLBG_COLOR}") launcher_exe="rofi" launcher_options=(-dmenu -i -lines "${menu_nrows}" -p "${ROFI_TEXT}" \ - "${rofi_colors}" "${ROFI_OPTIONS[@]}") + "${rofi_colors[@]}" "${ROFI_OPTIONS[@]}") elif [[ "$1" == "zenity" ]]; then launcher_exe="zenity" launcher_options=(--list --title="${ZENITY_TITLE}" --text="${ZENITY_TEXT}" \ @@ -164,7 +164,7 @@ selection="$(printf '%s\n' "${!menu[@]}" | sort | "${launcher[@]}")" function ask_confirmation() { if [ "${launcher_exe}" == "rofi" ]; then confirmed=$(echo -e "Yes\nNo" | rofi -dmenu -i -lines 2 -p "${selection}?" \ - "${rofi_colors}" "${ROFI_OPTIONS[@]}") + "${rofi_colors[@]}" "${ROFI_OPTIONS[@]}") [ "${confirmed}" == "Yes" ] && confirmed=0 elif [ "${launcher_exe}" == "zenity" ]; then zenity --question --text "Are you sure you want to ${selection,,}?" diff --git a/volume/README.md b/volume/README.md index dcfc2679..66e15a47 100644 --- a/volume/README.md +++ b/volume/README.md @@ -29,8 +29,8 @@ as long as it agrees what you put for `signal=` in your i3blocks config. ``` [volume] command=$SCRIPT_DIR/volume -#label=♪ -label=VOL +#LABEL=♪ +LABEL=VOL interval=once signal=10 #STEP=5% diff --git a/volume/i3blocks.conf b/volume/i3blocks.conf index 3e4f01c6..1e257e2a 100644 --- a/volume/i3blocks.conf +++ b/volume/i3blocks.conf @@ -1,7 +1,7 @@ [volume] command=$SCRIPT_DIR/volume -#label=♪ -label=VOL +#LABEL=♪ +LABEL=VOL interval=once signal=10 #STEP=5% diff --git a/volume/volume b/volume/volume index 33dd0106..58c6001d 100755 --- a/volume/volume +++ b/volume/volume @@ -62,12 +62,14 @@ volume() { } format() { + perl_filter='if (/.*\[(\d+%)\] (\[(-?\d+.\d+dB)\] )?\[(on|off)\]/)' perl_filter+='{CORE::say $4 eq "off" ? "MUTE" : "' # If dB was selected, print that instead perl_filter+=$([[ $STEP = *dB ]] && echo '$3' || echo '$1') perl_filter+='"; exit}' - perl -ne "$perl_filter" + output=$(perl -ne "$perl_filter") + echo "$LABEL$output" } #------------------------------------------------------------------------