aboutsummaryrefslogtreecommitdiff
path: root/config/i3blocks/scripts/time
diff options
context:
space:
mode:
authorKarel Kočí <cynerd@email.cz>2024-04-15 23:34:35 +0200
committerKarel Kočí <cynerd@email.cz>2024-04-15 23:35:42 +0200
commit4a25d79feef0dd6e462abfb48173da7e470127a5 (patch)
treef669e473abd24a84b2d9e167ec3f61463fb2b3a7 /config/i3blocks/scripts/time
parentdef6ee65cecb646c4cf0e02e9cfd17dd21611f9c (diff)
downloadmyconfigs-4a25d79feef0dd6e462abfb48173da7e470127a5.tar.gz
myconfigs-4a25d79feef0dd6e462abfb48173da7e470127a5.tar.bz2
myconfigs-4a25d79feef0dd6e462abfb48173da7e470127a5.zip
Replace i3blocks with swaybar
Diffstat (limited to 'config/i3blocks/scripts/time')
-rwxr-xr-xconfig/i3blocks/scripts/time101
1 files changed, 0 insertions, 101 deletions
diff --git a/config/i3blocks/scripts/time b/config/i3blocks/scripts/time
deleted file mode 100755
index e552a92..0000000
--- a/config/i3blocks/scripts/time
+++ /dev/null
@@ -1,101 +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}};
-
-binmode(STDOUT, ":utf8");
-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;
-}