Last active
August 29, 2015 14:03
-
-
Save hjst/1ef588fd0d86b896e434 to your computer and use it in GitHub Desktop.
Time ticker with variable line length for easy visual recognition of ssh session freezes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use Sys::Hostname; | |
require 'sys/ioctl.ph'; | |
main(@ARGV); | |
sub main { | |
# Ascertain terminal dimensions, assume 80 cols upon failure | |
my ($dimensions, $rows, $columns) = ''; | |
if (ioctl(STDOUT, TIOCGWINSZ(), $dimensions)) { | |
($rows, $columns) = unpack 'S4', $dimensions; | |
} else { | |
warn "Note: ioctl failed to ascertain terminal dimensions\n"; | |
warn "Assuming 80 columns as default\n"; | |
$columns = 80; | |
} | |
while (1) { | |
my $tick = "·"; | |
if ($columns > 40) { | |
# output hostname, full timestamp + padding, for aesthetics | |
print hostname() ." $tick ". localtime() . " $tick$tick$tick"; | |
} else { | |
# output short clock, no padding | |
my ($seconds, $minutes, $hours) = localtime(); | |
print "$hours:$minutes:$seconds "; | |
} | |
foreach(0 .. int(rand(10))) { print $tick } | |
print "\n"; | |
sleep(1); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment