Browse Source

Update i3blocks config

umatrix-rules
Pearu Vaalma 4 years ago
parent
commit
1d7fd6733f
  1. 8
      i3/.cfg_src/build_i3.sh
  2. 27
      i3/.cfg_src/i3/i3blocks.base
  3. 113
      i3/.i3/blocks/bandwidth
  4. 94
      i3/.i3/blocks/battery
  5. 62
      i3/.i3/blocks/cpu_usage
  6. 48
      i3/.i3/blocks/disk
  7. 70
      i3/.i3/blocks/iface
  8. 92
      i3/.i3/blocks/keyindicator
  9. 34
      i3/.i3/blocks/load_average
  10. 156
      i3/.i3/blocks/mediaplayer
  11. 69
      i3/.i3/blocks/memory
  12. 2
      i3/.i3/blocks/uptime
  13. 91
      i3/.i3/blocks/volume
  14. 53
      i3/.i3/blocks/wifi

8
i3/.cfg_src/build_i3.sh

@ -6,7 +6,8 @@ I3C_SRCDIR=$HOME/.cfg_src/i3
MYHOST=`hostname`; MYHOST=`hostname`;
I3C_LOCCFG=$I3C_SRCDIR/config.$MYHOST.local; I3C_LOCCFG=$I3C_SRCDIR/config.$MYHOST.local;
I3B_CFG=$HOME/.i3blocks.conf; I3B_DIR=$HOME/.config/i3blocks;
I3B_CFG=$I3B_DIR/config;
if [ ! -e $I3C_LOCCFG ] if [ ! -e $I3C_LOCCFG ]
@ -21,5 +22,10 @@ fi
cat $I3C_SRCDIR/config.base $I3C_LOCCFG > $I3C_CFGDIR/config; cat $I3C_SRCDIR/config.base $I3C_LOCCFG > $I3C_CFGDIR/config;
if [ ! -e $I3B_DIR ]
then
mkdir -p $I3B_DIR;
fi
cat $I3C_SRCDIR/i3blocks.base > $I3B_CFG; cat $I3C_SRCDIR/i3blocks.base > $I3B_CFG;

27
i3/.cfg_src/i3/i3blocks.base

@ -1,6 +1,6 @@
full_text= full_text=
align=center align=center
command=/usr/lib/i3blocks/$BLOCK_NAME command=~/.i3/blocks/$BLOCK_NAME
separator_block_width=15 separator_block_width=15
markup=none markup=none
@ -10,31 +10,32 @@ interval=25
signal=10 signal=10
[uptime] [uptime]
command=~/.i3/scripts/uptime label=UP
interval=60 interval=60
[volume] [volume]
label=VOL label=VOL
instance=Master instance=Master
interval=once interval=once
signal=10 signal=10
interval=60 interval=60
[memory] [memory]
label=MEM label=MEM
separator=false separator=false
interval=30 interval=30
[memory] [memory]
label=SWAP label=SWAP
instance=swap instance=swap
interval=30 interval=30
[disk] [disk]
label=HOME label=HOME
interval=30 interval=30
[iface] [iface]
label=NET
color=#00FF00 color=#00FF00
interval=10 interval=10
separator=false separator=false
@ -47,24 +48,24 @@ separator=false
interval=5 interval=5
[cpu_usage] [cpu_usage]
label=CPU label=CPU
interval=10 interval=10
min_width=CPU: 100.00% min_width=CPU: 100.00%
separator=false separator=false
[load_average] [load_average]
interval=10 interval=10
separator=false
[cputemp]
command=sensors | awk '/Tctl/ {print $2}'
interval=10
[battery] [battery]
label=BAT label=BAT
instance=1 instance=1
interval=30 interval=30
[keymap]
label=KB
interval=60
signal=12
[time] [time]
command=date '+%a %Y-%m-%d %H:%M:%S' command=date '+%a %Y-%m-%d %H:%M:%S'
interval=5 interval=5

113
i3/.i3/blocks/bandwidth

@ -0,0 +1,113 @@
#!/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 [[ -z $INTERFACE ]] && [[ -n $BLOCK_INSTANCE ]]; then
INTERFACE=$BLOCK_INSTANCE
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" ] || \
(! [ "$TREAT_UNKNOWN_AS_UP" = "1" ] &&
! [ "`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\n' "`echo "scale=1; $tx_kib / 1024" | bc`"
else
echo "${tx_kib}K"
fi

94
i3/.i3/blocks/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} || 0;
my $label = $ENV{LABEL} || "";
# read the first line of the "acpi" command output
open (ACPI, "acpi -b 2>/dev/null | grep -v ' 0%' |") 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 .= ' ONL';
} 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);

62
i3/.i3/blocks/cpu_usage

@ -0,0 +1,62 @@
#!/usr/bin/perl
#
# Copyright 2014 Pierre Mavro <deimos@deimos.fr>
# Copyright 2014 Vivien Didelot <vivien@didelot.org>
# Copyright 2014 Andreas Guldstrand <andreas.guldstrand@gmail.com>
#
# Licensed under the terms of the GNU GPL v3, or any later version.
use strict;
use warnings;
use utf8;
use Getopt::Long;
# default values
my $t_warn = $ENV{T_WARN} // 50;
my $t_crit = $ENV{T_CRIT} // 80;
my $cpu_usage = -1;
my $decimals = $ENV{DECIMALS} // 2;
my $label = $ENV{LABEL} // "";
sub help {
print "Usage: cpu_usage [-w <warning>] [-c <critical>] [-d <decimals>]\n";
print "-w <percent>: warning threshold to become yellow\n";
print "-c <percent>: critical threshold to become red\n";
print "-d <decimals>: Use <decimals> decimals for percentage (default is $decimals) \n";
exit 0;
}
GetOptions("help|h" => \&help,
"w=i" => \$t_warn,
"c=i" => \$t_crit,
"d=i" => \$decimals,
);
# Get CPU usage
$ENV{LC_ALL}="en_US"; # if mpstat is not run under en_US locale, things may break, so make sure it is
open (MPSTAT, 'mpstat 1 1 |') or die;
while (<MPSTAT>) {
if (/^.*\s+(\d+\.\d+)[\s\x00]?$/) {
$cpu_usage = 100 - $1; # 100% - %idle
last;
}
}
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
if ($cpu_usage >= $t_crit) {
print "#FF0000\n";
exit 33;
} elsif ($cpu_usage >= $t_warn) {
print "#FFFC00\n";
}
exit 0;

48
i3/.i3/blocks/disk

@ -0,0 +1,48 @@
#!/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/>.
DIR="${DIR:-$BLOCK_INSTANCE}"
DIR="${DIR:-$HOME}"
ALERT_LOW="${ALERT_LOW:-$1}"
ALERT_LOW="${ALERT_LOW:-10}" # color will turn red under this value (default: 10%)
LOCAL_FLAG="-l"
if [ "$1" = "-n" ] || [ "$2" = "-n" ]; then
LOCAL_FLAG=""
fi
df -h -P $LOCAL_FLAG "$DIR" | awk -v label="$LABEL" -v alert_low=$ALERT_LOW '
/\/.*/ {
# full text
print label $4
# short text
print label $4
use=$5
# no need to continue parsing
exit 0
}
END {
gsub(/%$/,"",use)
if (100 - use < alert_low) {
# color
print "#FF0000"
}
}
'

70
i3/.i3/blocks/iface

@ -0,0 +1,70 @@
#!/bin/bash
# Copyright (C) 2014 Julien Bonjean <julien@bonjean.info>
# Copyright (C) 2014 Alexander Keller <github@nycroth.com>
# 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 the provided interface, otherwise the device used for the default route.
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
# connection (think desktop), the corresponding block should not be displayed.
[[ ! -d /sys/class/net/${IF} ]] && exit
#------------------------------------------------------------------------
AF=${ADDRESS_FAMILY:-inet6?}
LABEL="${LABEL:-}"
for flag in "$1" "$2"; do
case "$flag" in
-4)
AF=inet ;;
-6)
AF=inet6 ;;
-L)
if [[ "$IF" = "" ]]; then
LABEL="iface "
else
LABEL="$IF: "
fi ;;
esac
done
if [[ "$IF" = "" ]] || [[ "$(cat /sys/class/net/$IF/operstate)" = 'down' ]]; then
echo "${LABEL}down" # full text
echo "${LABEL}down" # short text
echo \#FF0000 # color
exit
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")
case $BLOCK_BUTTON in
3) echo -n "$IPADDR" | xclip -q -se c ;;
esac
#------------------------------------------------------------------------
echo "$LABEL$IPADDR" # full text
echo "$LABEL$IPADDR" # short text

92
i3/.i3/blocks/keyindicator

@ -0,0 +1,92 @@
#!/usr/bin/env perl
#
# Copyright 2014 Marcelo Cerri <mhcerri at gmail dot com>
#
# 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;
use File::Basename;
# Default values
my $indicator = $ENV{BLOCK_INSTANCE} || $ENV{KEY} || "CAPS";
my $text_on = $ENV{TEXT_ON} || $indicator;
my $text_off = $ENV{TEXT_OFF} || $indicator;
my $color_on = $ENV{COLOR_ON} || "#00FF00";
my $color_off = $ENV{COLOR_OFF} || "#222222";
my $bg_color_on = $ENV{BG_COLOR_ON};
my $bg_color_off = $ENV{BG_COLOR_OFF};
my $hide = $ENV{HIDE_WHEN_OFF} || 0;
sub help {
my $program = basename($0);
printf "Usage: %s [-c <color on>] [-C <color off>] [-b <bg color on>] [-B <bg color off>] [--hide]\n", $program;
printf " -c <color on>: hex color to use when indicator is on\n";
printf " -C <color off>: hex color to use when indicator is off\n";
printf " -b <background color on>: hex color to use when indicator is on\n";
printf " -B <background color off>: hex color to use when indicator is off\n";
printf " --hide: don't output anything when indicator is off\n";
printf "\n";
printf "Note: environment variable \$BLOCK_INSTANCE should be one of:\n";
printf " CAPS, NUM (default is CAPS).\n";
exit 0;
}
Getopt::Long::config qw(no_ignore_case);
GetOptions("help|h" => \&help,
"c=s" => \$color_on,
"C=s" => \$color_off,
"b=s" => \$bg_color_on,
"B=s" => \$bg_color_off,
"hide" => \$hide) or exit 1;
# Key mapping
my %indicators = (
CAPS => 0x00000001,
NUM => 0x00000002,
);
# Retrieve key flags
my $mask = 0;
open(XSET, "xset -q |") or die;
while (<XSET>) {
if (/LED mask:\s*([0-9a-f]+)/) {
$mask = hex $1;
last;
}
}
close(XSET);
# Determine if indicator is on or off
my $indicator_status = ($indicators{$indicator} || 0) & $mask;
# Exit if --hide and indicator is off
if ($hide and !$indicator_status) {
exit 0
}
# Output
$indicator = $indicator_status ? $text_on : $text_off;
my $fg_color = $indicator_status ? $color_on : $color_off;
my $bg_color = $indicator_status ? $bg_color_on : $bg_color_off;
if (defined $bg_color) {
printf "<span color='%s' bgcolor='%s'>%s</span>\n", $fg_color, $bg_color, $indicator;
} else {
printf "<span color='%s'>%s</span>\n", $fg_color, $indicator;
}
exit 0

34
i3/.i3/blocks/load_average

@ -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;
}
}
'

156
i3/.i3/blocks/mediaplayer

@ -0,0 +1,156 @@
#!/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);
chomp $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;
}
print("\n");

69
i3/.i3/blocks/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")
} else if (pct > 80) {
print("#FFAE00")
} else if (pct > 70) {
print("#FFF600")
}
}
' /proc/meminfo

2
i3/.i3/scripts/uptime → i3/.i3/blocks/uptime

@ -10,4 +10,4 @@ m=$(( uptime/60%60 ))
h=$(( uptime/60/60%24 )) h=$(( uptime/60/60%24 ))
d=$(( uptime/60/60/24 )) d=$(( uptime/60/60/24 ))
echo "UPTIME "$d"d "$h"h "$m"m" echo $d"d "$h"h "$m"min"

91
i3/.i3/blocks/volume

@ -0,0 +1,91 @@
#!/usr/bin/env bash
# Copyright (C) 2014 Julien Bonjean <julien@bonjean.info>
# Copyright (C) 2014 Alexander Keller <github@nycroth.com>
# 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/>.
#------------------------------------------------------------------------
# The second parameter overrides the mixer selection
# For PulseAudio users, eventually use "pulse"
# For Jack/Jack2 users, use "jackplug"
# For ALSA users, you may use "default" for your primary card
# or you may use hw:# where # is the number of the card desired
if [[ -z "$MIXER" ]] ; then
MIXER="default"
if command -v pulseaudio >/dev/null 2>&1 && pulseaudio --check ; then
# pulseaudio is running, but not all installations use "pulse"
if amixer -D pulse info >/dev/null 2>&1 ; then
MIXER="pulse"
fi
fi
[ -n "$(lsmod | grep jack)" ] && MIXER="jackplug"
MIXER="${2:-$MIXER}"
fi
# The instance option sets the control to report and configure
# This defaults to the first control of your selected mixer
# For a list of the available, use `amixer -D $Your_Mixer scontrols`
if [[ -z "$SCONTROL" ]] ; then
SCONTROL="${BLOCK_INSTANCE:-$(amixer -D $MIXER scontrols |
sed -n "s/Simple mixer control '\([^']*\)',0/\1/p" |
head -n1
)}"
fi
# The first parameter sets the step to change the volume by (and units to display)
# This may be in in % or dB (eg. 5% or 3dB)
if [[ -z "$STEP" ]] ; then
STEP="${1:-5%}"
fi
# AMIXER(1):
# "Use the mapped volume for evaluating the percentage representation like alsamixer, to be
# more natural for human ear."
NATURAL_MAPPING=${NATURAL_MAPPING:-0}
if [[ "$NATURAL_MAPPING" != "0" ]] ; then
AMIXER_PARAMS="-M"
fi
#------------------------------------------------------------------------
capability() { # Return "Capture" if the device is a capture device
amixer $AMIXER_PARAMS -D $MIXER get $SCONTROL |
sed -n "s/ Capabilities:.*cvolume.*/Capture/p"
}
volume() {
amixer $AMIXER_PARAMS -D $MIXER get $SCONTROL $(capability)
}
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}'
output=$(perl -ne "$perl_filter")
echo "$LABEL$output"
}
#------------------------------------------------------------------------
case $BLOCK_BUTTON in
3) amixer $AMIXER_PARAMS -q -D $MIXER sset $SCONTROL $(capability) toggle ;; # right click, mute/unmute
4) amixer $AMIXER_PARAMS -q -D $MIXER sset $SCONTROL $(capability) ${STEP}+ unmute ;; # scroll up, increase
5) amixer $AMIXER_PARAMS -q -D $MIXER sset $SCONTROL $(capability) ${STEP}- unmute ;; # scroll down, decrease
esac
volume | format

53
i3/.i3/blocks/wifi

@ -0,0 +1,53 @@
#!/bin/bash
# Copyright (C) 2014 Alexander Keller <github@nycroth.com>
# 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/>.
#------------------------------------------------------------------------
if [[ -z "$INTERFACE" ]] ; then
INTERFACE="${BLOCK_INSTANCE:-wlp3s0}"
fi
#------------------------------------------------------------------------
# As per #36 -- It is transparent: e.g. if the machine has no battery or wireless
# connection (think desktop), the corresponding block should not be displayed.
[[ ! -d /sys/class/net/${INTERFACE}/wireless ]] && exit
# If the wifi interface exists but no connection is active, "down" shall be displayed.
if [[ "$(cat /sys/class/net/$INTERFACE/operstate)" = 'down' ]]; then
echo "down"
echo "down"
echo "#FF0000"
exit
fi
#------------------------------------------------------------------------
QUALITY=$(grep $INTERFACE /proc/net/wireless | awk '{ print int($3 * 100 / 70) }')
#------------------------------------------------------------------------
echo `nmcli -t -f NAME connection show --active | head -n 1` $QUALITY% # full text
echo $QUALITY% # short text
# color
if [[ $QUALITY -ge 80 ]]; then
echo "#00FF00"
elif [[ $QUALITY -ge 60 ]]; then
echo "#FFF600"
elif [[ $QUALITY -ge 40 ]]; then
echo "#FFAE00"
else
echo "#FF0000"
fi
Loading…
Cancel
Save