summaryrefslogtreecommitdiff
path: root/.local
diff options
context:
space:
mode:
authorDavid Luevano Alvarado <55825613+luevano@users.noreply.github.com>2020-02-27 13:36:06 -0700
committerDavid Luevano Alvarado <55825613+luevano@users.noreply.github.com>2020-02-27 13:36:06 -0700
commit4709959c821f323295de7cce78b0f1a8f525de6f (patch)
tree1581fc2b744308c185fcf7009837701e092a133a /.local
parentd086bb4ca0c79f73ceef666e7634e2ade9f4105e (diff)
Tweak blocklets
Diffstat (limited to '.local')
-rwxr-xr-x.local/bin/blocks/cpu6
-rwxr-xr-x.local/bin/blocks/gpu50
-rwxr-xr-x.local/bin/blocks/player24
-rwxr-xr-x.local/bin/blocks/time100
4 files changed, 20 insertions, 160 deletions
diff --git a/.local/bin/blocks/cpu b/.local/bin/blocks/cpu
index e955d4b..7f4bca0 100755
--- a/.local/bin/blocks/cpu
+++ b/.local/bin/blocks/cpu
@@ -1,10 +1,4 @@
#!/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;
diff --git a/.local/bin/blocks/gpu b/.local/bin/blocks/gpu
index 73c17f1..b20fc4a 100755
--- a/.local/bin/blocks/gpu
+++ b/.local/bin/blocks/gpu
@@ -1,18 +1,5 @@
#!/usr/bin/perl
-# 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;
@@ -28,44 +15,43 @@ my $gpu_pcie = -1;
my $label = $ENV{LABEL} // "";
sub help {
- print "Usage: gpu-load [-w <warning>] [-c <critical>]\n";
- print "-w <percent>: warning threshold to become amber\n";
- print "-c <percent>: critical threshold to become red\n";
- exit 0;
+ print "Usage: gpu-load [-w <warning>] [-c <critical>]\n";
+ print "-w <percent>: warning threshold to become amber\n";
+ print "-c <percent>: critical threshold to become red\n";
+ exit 0;
}
GetOptions("help|h" => \&help,
- "w=i" => \$t_warn,
- "c=i" => \$t_crit);
+ "w=i" => \$t_warn,
+ "c=i" => \$t_crit);
# Get GPU usage from nvidia-settings
open (NVS, 'nvidia-settings -q GPUUtilization -t |') or die;
while (<NVS>) {
- if (/^[a-zA-Z]*=(\d+), [a-zA-Z]*=(\d+), [a-zA-Z]*=(\d+), [a-zA-Z]*=(\d+)$/) {
- $gpu_usage = $1;
+ if (/^[a-zA-Z]*=(\d+), [a-zA-Z]*=(\d+), [a-zA-Z]*=(\d+), [a-zA-Z]*=(\d+)$/) {
+ $gpu_usage = $1;
$gpu_mem = $2;
$gpu_video = $3;
$gpu_pcie = $4;
- last;
- }
+ last;
+ }
}
close(NVS);
$gpu_usage eq -1 and die 'Can\'t find GPU information';
-# I edited this to only show the gpu_usage and gpu_mem.
-# Also fixed the label thing.
-# Print full_text, short_text
-# printf "%.0f%% %.0f%% %.0f%% %.0f%%\n", $gpu_usage, $gpu_mem, $gpu_video, $gpu_pcie;
-# printf "%.0f%%\n", $gpu_usage;
-printf "${label} %.0f%% %.0f%%\n", $gpu_usage, $gpu_mem;
+# Full text.
+# printf "%s %.0f%% %.0f%% %.0f%% %.0f%%\n", $label, $gpu_usage, $gpu_mem, $gpu_video, $gpu_pcie;
+printf "%s %.0f%% %.0f%%\n", $label, $gpu_usage, $gpu_mem;
+# Short text.
+printf "%s %.0f%% %.0f%%\n", $label, $gpu_usage, $gpu_mem;
# Print color, if needed
if ($gpu_usage >= $t_crit || $gpu_mem >= $t_crit || $gpu_video >= $t_crit || $gpu_pcie >= $t_crit) {
- print "#FF0000\n";
- exit 33;
+ print "#FF0000\n";
+ exit 33;
} elsif ($gpu_usage >= $t_warn || $gpu_mem >= $t_warn || $gpu_video >= $t_warn || $gpu_pcie >= $t_warn) {
- print "#FFBF00\n";
+ print "#FFBF00\n";
}
exit 0;
diff --git a/.local/bin/blocks/player b/.local/bin/blocks/player
index f78bd78..cc17a4e 100755
--- a/.local/bin/blocks/player
+++ b/.local/bin/blocks/player
@@ -1,26 +1,4 @@
#!/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);
@@ -28,6 +6,7 @@ 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 $label = $ENV{LABEL} // "";
my @metadata = ();
my $player_arg = "";
@@ -83,6 +62,7 @@ sub buttons {
}
}
+print("$label ");
sub cmus {
my @cmus = split /^/, qx(cmus-remote -Q);
if ($? == 0) {
diff --git a/.local/bin/blocks/time b/.local/bin/blocks/time
deleted file mode 100755
index 725fc68..0000000
--- a/.local/bin/blocks/time
+++ /dev/null
@@ -1,100 +0,0 @@
-#!/usr/bin/env perl
-
-use strict;
-use warnings;
-use POSIX qw/strftime/;
-
-my $click = $ENV{BLOCK_BUTTON} || 0;
-my $format = $ENV{BLOCK_INSTANCE} || $ENV{STRFTIME_FORMAT} || "%H:%M";
-my $tz_file = shift || $ENV{TZ_FILE} || "$ENV{HOME}/.tz";
-$tz_file = glob($tz_file);
-my $default_tz = get_default_tz();
-
-my $tzones = $ENV{TZONES} || '$DEFAULT_TZ';
-$tzones =~ s/\$DEFAULT_TZ/$default_tz/g;
-my @tz_list = split(/,/, $tzones);
-my @tz_labels = split(/,/, $ENV{TZ_LABELS} || "");
-if (scalar(@tz_list) != scalar(@tz_labels)) {
- @tz_labels = @tz_list;
-}
-
-my $current_tz;
-if ($click == 1) {
- $current_tz = get_tz();
-
- my %tzmap;
- $tzmap{""} = $tz_list[0];
- my $prev = $tz_list[0];
- foreach my $tz (@tz_list) {
- $tzmap{$prev} = $tz;
- $prev = $tz;
- }
- $tzmap{$prev} = $tz_list[0];
-
- if (exists $tzmap{$current_tz}) {
- set_tz($tzmap{$current_tz});
- $current_tz = $tzmap{$current_tz};
- }
-}
-
-# How each timezone will be displayed in the bar.
-my %display_map;
-for (my $i=0; $i < scalar(@tz_list); $i++) {
- $display_map{$tz_list[$i]} = $tz_labels[$i];
-}
-
-if (!defined $current_tz) {
- $current_tz = get_tz();
- set_tz($current_tz);
-}
-$ENV{TZ} = $current_tz;
-my $tz_display = "";
-if (!exists $display_map{$ENV{TZ}}) {
- $ENV{TZ} = $tz_list[0];
- set_tz($tz_list[0]);
-}
-$tz_display = $display_map{$ENV{TZ}};
-
-my $time = strftime($format, localtime());
-if ($tz_display eq "") {
- print "$time\n";
-} else {
- print "$time ($tz_display)\n";
-}
-
-sub get_tz {
- my $current_tz;
-
- if (-f $tz_file) {
- open my $fh, '<', $tz_file || die "Couldn't open file: $tz_file";
- $current_tz = <$fh>;
- chomp $current_tz;
- close $fh;
- }
-
- return $current_tz || get_default_tz();
-}
-
-sub set_tz {
- my $tz = shift;
-
- open my $fh, '>', $tz_file || die "Couldn't open file: $tz_file";
- print $fh $tz;
- close $fh;
-}
-
-sub get_default_tz {
- my $tz = "Europe/London";
-
- if (-f "/etc/timezone") {
- open my $fh, '<', "/etc/timezone" || die "Couldn't open file: /etc/timezone";
- $tz = <$fh>;
- chomp $tz;
- close $fh;
- } elsif (-l "/etc/localtime") {
- $tz = readlink "/etc/localtime";
- $tz = (split /zoneinfo\//, $tz)[-1];
- }
-
- return $tz;
-}