Skip to content

Instantly share code, notes, and snippets.

@hjst
Last active Aug 29, 2015
Embed
What would you like to do?
Time ticker with variable line length for easy visual recognition of ssh session freezes
#!/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