diff options
author | luxagraf <sng@luxagraf.net> | 2020-02-16 13:23:56 -0500 |
---|---|---|
committer | luxagraf <sng@luxagraf.net> | 2020-02-16 13:23:56 -0500 |
commit | cd507c92f617d4a8a3f7bb0b43e425491ef7184d (patch) | |
tree | 42144ef0f35b91e7955f570c5ecc4bcec3c4d780 /.i3blocks/blocklets |
initial commit of dotfiles
Diffstat (limited to '.i3blocks/blocklets')
-rwxr-xr-x | .i3blocks/blocklets/bandwidth | 107 | ||||
-rwxr-xr-x | .i3blocks/blocklets/battery | 94 | ||||
-rwxr-xr-x | .i3blocks/blocklets/battery2 | 102 | ||||
-rwxr-xr-x | .i3blocks/blocklets/battery3 | 26 | ||||
-rwxr-xr-x | .i3blocks/blocklets/calendar | 38 | ||||
-rwxr-xr-x | .i3blocks/blocklets/mediaplayer | 154 | ||||
-rwxr-xr-x | .i3blocks/blocklets/memory | 69 | ||||
-rwxr-xr-x | .i3blocks/blocklets/openvpn | 3 | ||||
-rwxr-xr-x | .i3blocks/blocklets/ssid | 18 |
9 files changed, 611 insertions, 0 deletions
diff --git a/.i3blocks/blocklets/bandwidth b/.i3blocks/blocklets/bandwidth new file mode 100755 index 0000000..c69a22c --- /dev/null +++ b/.i3blocks/blocklets/bandwidth @@ -0,0 +1,107 @@ +#!/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/>. + +# Get custom IN and OUT labels if provided by command line arguments +while [[ $# -gt 1 ]]; do + key="$1" + case "$key" in + -i|--inlabel) + INLABEL="$2" + shift;; + -o|--outlabel) + OUTLABEL="$2" + shift;; + esac + shift +done + +[[ -z $INLABEL ]] && INLABEL="IN " +[[ -z $OUTLABEL ]] && OUTLABEL="OUT " + +# Use the provided interface, otherwise the device used for the default route. +if [[ -n $BLOCK_INSTANCE ]]; then + INTERFACE=$BLOCK_INSTANCE +else + INTERFACE=$(ip route | awk '/^default/ { print $5 ; exit }') +fi + +# 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 "$INLABEL" +rx_kib=$(( $rx_rate >> 10 )) +if hash bc 2>/dev/null && [[ "$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 "$OUTLABEL" +tx_kib=$(( $tx_rate >> 10 )) +if hash bc 2>/dev/null && [[ "$tx_rate" -gt 1048576 ]]; then + printf '%sM' "`echo "scale=1; $tx_kib / 1024" | bc`" +else + echo -n "${tx_kib}K" +fi diff --git a/.i3blocks/blocklets/battery b/.i3blocks/blocklets/battery new file mode 100755 index 0000000..7679f86 --- /dev/null +++ b/.i3blocks/blocklets/battery @@ -0,0 +1,94 @@ +#!/usr/bin/perl +# +# Copyright 2014 Pierre Mavro <deimos@deimos.fr> +# Copyright 2014 Vivien Didelot <vivien@didelot.org> +# +# Licensed under the terms of the GNU GPL v3, or any later version. +# +# This script is meant to use with i3blocks. It parses the output of the "acpi" +# command (often provided by a package of the same name) to read the status of +# the battery, and eventually its remaining time (to full charge or discharge). +# +# The color will gradually change for a percentage below 85%, and the urgency +# (exit code 33) is set if there is less that 5% remaining. + +use strict; +use warnings; +use utf8; + +my $acpi; +my $status; +my $percent; +my $ac_adapt; +my $full_text; +my $short_text; +my $bat_number = $ENV{BAT_NUMBER} || 1; +my $label = $ENV{LABEL} || ""; + +# read the first line of the "acpi" command output +open (ACPI, "acpi -b 2>/dev/null| grep 'Battery $bat_number' |") or die; +$acpi = <ACPI>; +close(ACPI); + +# fail on unexpected output +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 = "$label$percent%"; + +if ($status eq 'Discharging') { + $full_text .= ' DIS'; +} elsif ($status eq 'Charging') { + $full_text .= ' CHR'; +} elsif ($status eq 'Unknown') { + open (AC_ADAPTER, "acpi -a |") or die; + $ac_adapt = <AC_ADAPTER>; + close(AC_ADAPTER); + + if ($ac_adapt =~ /: ([\w-]+)/) { + $ac_adapt = $1; + + if ($ac_adapt eq 'on-line') { + $full_text .= ' CHR'; + } elsif ($ac_adapt eq 'off-line') { + $full_text .= ' DIS'; + } + } +} + +$short_text = $full_text; + +if ($acpi =~ /(\d\d:\d\d):/) { + $full_text .= " ($1)"; +} + +# print text +print "$full_text\n"; +print "$short_text\n"; + +# consider color and urgent flag only on discharge +if ($status eq 'Discharging') { + + if ($percent < 20) { + print "#FF0000\n"; + } elsif ($percent < 40) { + print "#FFAE00\n"; + } elsif ($percent < 60) { + print "#FFF600\n"; + } elsif ($percent < 85) { + print "#A8FF00\n"; + } + + if ($percent < 5) { + exit(33); + } +} + +exit(0); diff --git a/.i3blocks/blocklets/battery2 b/.i3blocks/blocklets/battery2 new file mode 100755 index 0000000..b23dfdd --- /dev/null +++ b/.i3blocks/blocklets/battery2 @@ -0,0 +1,102 @@ +#!/usr/bin/env python3 +# +# Copyright (C) 2016 James Murphy +# Licensed under the GPL version 2 only +# +# A battery indicator blocklet script for i3blocks + +import re +from subprocess import check_output + +status = check_output(['acpi'], universal_newlines=True) + +if not status: + # stands for no battery found + fulltext = "<span color='red'><span font='FontAwesome'>\uf00d \uf240</span></span>" + percentleft = 100 +else: + # if there is more than one battery in one laptop, the percentage left is + # available for each battery separately, although state and remaining + # time for overall block is shown in the status of the first battery + batteries = status.split("\n") + state_batteries=[] + commasplitstatus_batteries=[] + percentleft_batteries=[] + time = "" + for battery in batteries: + if battery!='': + state_batteries.append(battery.split(": ")[1].split(", ")[0]) + commasplitstatus = battery.split(", ") + if not time: + time = commasplitstatus[-1].strip() + # check if it matches a time + time = re.match(r"(\d+):(\d+)", time) + if time: + time = ":".join(time.groups()) + timeleft = " ({})".format(time) + else: + timeleft = "" + + p = int(commasplitstatus[1].rstrip("%\n")) + if p>0: + percentleft_batteries.append(p) + commasplitstatus_batteries.append(commasplitstatus) + state = state_batteries[0] + commasplitstatus = commasplitstatus_batteries[0] + if percentleft_batteries: + percentleft = int(sum(percentleft_batteries)/len(percentleft_batteries)) + else: + percentleft = 0 + + # stands for charging + FA_LIGHTNING = "<span color='yellow'><span font='FontAwesome'>\uf0e7</span></span>" + + # stands for plugged in + FA_PLUG = "<span font='FontAwesome'>\uf1e6</span>" + + # stands for using battery + FA_BATTERY = "<span font='FontAwesome'>\uf240</span>" + + # stands for unknown status of battery + FA_QUESTION = "<span font='FontAwesome'>\uf128</span>" + + + if state == "Discharging": + fulltext = FA_BATTERY + " " + elif state == "Full": + fulltext = FA_PLUG + " " + timeleft = "" + elif state == "Unknown": + fulltext = FA_QUESTION + " " + FA_BATTERY + " " + timeleft = "" + else: + fulltext = FA_LIGHTNING + " " + FA_PLUG + " " + + def color(percent): + if percent < 10: + # exit code 33 will turn background red + return "#FFFFFF" + if percent < 20: + return "#FF3300" + if percent < 30: + return "#FF6600" + if percent < 40: + return "#FF9900" + if percent < 50: + return "#FFCC00" + if percent < 60: + return "#FFFF00" + if percent < 70: + return "#FFFF33" + if percent < 80: + return "#FFFF66" + return "#FFFFFF" + + form = '<span color="{}">{}%</span>' + fulltext += form.format(color(percentleft), percentleft) + fulltext += timeleft + +print(fulltext) +print(fulltext) +if percentleft < 10: + exit(33) diff --git a/.i3blocks/blocklets/battery3 b/.i3blocks/blocklets/battery3 new file mode 100755 index 0000000..39ccc2a --- /dev/null +++ b/.i3blocks/blocklets/battery3 @@ -0,0 +1,26 @@ +#!/bin/bash + +BATTERY=1 +BATTERY_INFO=$(acpi -b | grep "Battery ${BATTERY}") +BATTERY_STATE=$(echo "${BATTERY_INFO}" | grep -wo "Full\|Charging\|Discharging") +BATTERY_POWER=$(echo "${BATTERY_INFO}" | grep -o '[0-9]\+%' | tr -d '%') + +URGENT_VALUE=10 + +if [[ "${BATTERY_STATE}" = "Charging" ]]; then + echo "${BATTERY_POWER}%+" + echo "${BATTERY_POWER}%+" + echo "" +elif [[ "${BATTERY_STATE}" = "Discharging" ]]; then + echo "${BATTERY_POWER}%-" + echo "${BATTERY_POWER}%-" + echo "" +else + echo "${BATTERY_POWER}%" + echo "${BATTERY_POWER}%" + echo "" +fi + +if [[ "${BATTERY_POWER}" -le "${URGENT_VALUE}" ]]; then + exit 33 +fi diff --git a/.i3blocks/blocklets/calendar b/.i3blocks/blocklets/calendar new file mode 100755 index 0000000..aceafe6 --- /dev/null +++ b/.i3blocks/blocklets/calendar @@ -0,0 +1,38 @@ +#! /bin/sh + +width=200 +height=200 +datefmt="+%a %m-%d %H:%M:%S" + +OPTIND=1 +while getopts ":f:W:H:" opt; do + case $opt in + f) datefmt="$OPTARG" ;; + W) width="$OPTARG" ;; + H) height="$OPTARG" ;; + \?) + echo "Invalid option: -$OPTARG" >&2 + exit 1 + ;; + :) + echo "Option -$OPTARG requires an argument." >&2 + exit 1 + ;; + esac +done + +case "$BLOCK_BUTTON" in + 1|2|3) + + # the position of the upper left corner of the popup + posX=$(($BLOCK_X - $width / 2)) + posY=$(($BLOCK_Y - $height)) + + i3-msg -q "exec gsimplecal \ + --width=$width --height=$height \ + --undecorated --fixed \ + --close-on-unfocus --no-buttons \ + --posx=$posX --posy=$posY \ + > /dev/null" +esac +date "$datefmt" diff --git a/.i3blocks/blocklets/mediaplayer b/.i3blocks/blocklets/mediaplayer new file mode 100755 index 0000000..718e335 --- /dev/null +++ b/.i3blocks/blocklets/mediaplayer @@ -0,0 +1,154 @@ +#!/usr/bin/env perl +# Copyright (C) 2014 Tony Crisci <tony@dubstepdish.com> +# 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/>. + +# Requires playerctl binary to be in your path (except cmus) +# See: https://github.com/acrisci/playerctl + +# Set instance=NAME in the i3blocks configuration to specify a music player +# (playerctl will attempt to connect to org.mpris.MediaPlayer2.[NAME] on your +# DBus session). + +use Time::HiRes qw(usleep); +use Env qw(BLOCK_INSTANCE); + +use constant DELAY => 50; # Delay in ms to let network-based players (spotify) reflect new data. +use constant SPOTIFY_STR => 'spotify'; + +my @metadata = (); +my $player_arg = ""; + +if ($BLOCK_INSTANCE) { + $player_arg = "--player='$BLOCK_INSTANCE'"; +} + +sub buttons { + my $method = shift; + + if($method eq 'mpd') { + if ($ENV{'BLOCK_BUTTON'} == 1) { + system("mpc prev"); + } elsif ($ENV{'BLOCK_BUTTON'} == 2) { + system("mpc toggle"); + } elsif ($ENV{'BLOCK_BUTTON'} == 3) { + system("mpc next"); + } elsif ($ENV{'BLOCK_BUTTON'} == 4) { + system("mpc volume +10"); + } elsif ($ENV{'BLOCK_BUTTON'} == 5) { + system("mpc volume -10"); + } + } elsif ($method eq 'cmus') { + if ($ENV{'BLOCK_BUTTON'} == 1) { + system("cmus-remote --prev"); + } elsif ($ENV{'BLOCK_BUTTON'} == 2) { + system("cmus-remote --pause"); + } elsif ($ENV{'BLOCK_BUTTON'} == 3) { + system("cmus-remote --next"); + } + } elsif ($method eq 'playerctl') { + if ($ENV{'BLOCK_BUTTON'} == 1) { + system("playerctl $player_arg previous"); + usleep(DELAY * 1000) if $BLOCK_INSTANCE eq SPOTIFY_STR; + } elsif ($ENV{'BLOCK_BUTTON'} == 2) { + system("playerctl $player_arg play-pause"); + } elsif ($ENV{'BLOCK_BUTTON'} == 3) { + system("playerctl $player_arg next"); + usleep(DELAY * 1000) if $BLOCK_INSTANCE eq SPOTIFY_STR; + } elsif ($ENV{'BLOCK_BUTTON'} == 4) { + system("playerctl $player_arg volume 0.01+"); + } elsif ($ENV{'BLOCK_BUTTON'} == 5) { + system("playerctl $player_arg volume 0.01-"); + } + } elsif ($method eq 'rhythmbox') { + if ($ENV{'BLOCK_BUTTON'} == 1) { + system("rhythmbox-client --previous"); + } elsif ($ENV{'BLOCK_BUTTON'} == 2) { + system("rhythmbox-client --play-pause"); + } elsif ($ENV{'BLOCK_BUTTON'} == 3) { + system("rhythmbox-client --next"); + } + } +} + +sub cmus { + my @cmus = split /^/, qx(cmus-remote -Q); + if ($? == 0) { + foreach my $line (@cmus) { + my @data = split /\s/, $line; + if (shift @data eq 'tag') { + my $key = shift @data; + my $value = join ' ', @data; + + @metadata[0] = $value if $key eq 'artist'; + @metadata[1] = $value if $key eq 'title'; + } + } + + if (@metadata) { + buttons('cmus'); + + # metadata found so we are done + print(join ' - ', @metadata); + exit 0; + } + } +} + +sub mpd { + my $data = qx(mpc current); + if (not $data eq '') { + buttons("mpd"); + print($data); + exit 0; + } +} + +sub playerctl { + buttons('playerctl'); + + my $artist = qx(playerctl $player_arg metadata artist); + # exit status will be nonzero when playerctl cannot find your player + exit(0) if $? || $artist eq '(null)'; + + push(@metadata, $artist) if $artist; + + my $title = qx(playerctl $player_arg metadata title); + exit(0) if $? || $title eq '(null)'; + + push(@metadata, $title) if $title; + + print(join(" - ", @metadata)) if @metadata; +} + +sub rhythmbox { + buttons('rhythmbox'); + + my $data = qx(rhythmbox-client --print-playing --no-start); + print($data); +} + +if ($player_arg eq '' or $player_arg =~ /mpd/) { + mpd; +} +elsif ($player_arg =~ /cmus/) { + cmus; +} +elsif ($player_arg =~ /rhythmbox/) { + rhythmbox; +} +else { + playerctl; +} diff --git a/.i3blocks/blocklets/memory b/.i3blocks/blocklets/memory new file mode 100755 index 0000000..2dfaca3 --- /dev/null +++ b/.i3blocks/blocklets/memory @@ -0,0 +1,69 @@ +#!/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/>. + +TYPE="${BLOCK_INSTANCE:-mem}" + +awk -v type=$TYPE ' +/^MemTotal:/ { + mem_total=$2 +} +/^MemFree:/ { + mem_free=$2 +} +/^Buffers:/ { + mem_free+=$2 +} +/^Cached:/ { + mem_free+=$2 +} +/^SwapTotal:/ { + swap_total=$2 +} +/^SwapFree:/ { + swap_free=$2 +} +END { + if (type == "swap") { + free=swap_free/1024/1024 + used=(swap_total-swap_free)/1024/1024 + total=swap_total/1024/1024 + } else { + free=mem_free/1024/1024 + used=(mem_total-mem_free)/1024/1024 + total=mem_total/1024/1024 + } + + pct=0 + if (total > 0) { + pct=used/total*100 + } + + # full text + printf("%.1fG/%.1fG (%.f%%)\n", used, total, pct) + + # short text + printf("%.f%%\n", pct) + + # color + if (pct > 90) { + print("#FF0000\n") + } else if (pct > 80) { + print("#FFAE00\n") + } else if (pct > 70) { + print("#FFF600\n") + } +} +' /proc/meminfo diff --git a/.i3blocks/blocklets/openvpn b/.i3blocks/blocklets/openvpn new file mode 100755 index 0000000..8139436 --- /dev/null +++ b/.i3blocks/blocklets/openvpn @@ -0,0 +1,3 @@ +#!/bin/bash +result=$(nmcli -t -f type,state,connection d | egrep "^(tun|tap):connected" | awk -F':' '{ print $3 }') +[[ -z $result ]] && echo '' || echo "" diff --git a/.i3blocks/blocklets/ssid b/.i3blocks/blocklets/ssid new file mode 100755 index 0000000..d95c721 --- /dev/null +++ b/.i3blocks/blocklets/ssid @@ -0,0 +1,18 @@ +#!/bin/bash + +SSID_NAME=$(iwgetid -r) + +# You can put any urgent name so the block will give warning +# if a network with this name is used, like public wifi or alike. +# You can separate multiple values with \| +URGENT_VALUE="" + +if [[ "${SSID_NAME}" != "" ]]; then + echo "${SSID_NAME}" + echo "${SSID_NAME}" + echo "" + + if [[ "${URGENT_VALUE}" != "" ]] && [[ $(echo "${SSID_NAME}" | grep -we "${URGENT_VALUE}") != "" ]]; then + exit 33 + fi +fi
\ No newline at end of file |