Skip to content

Instantly share code, notes, and snippets.

@hjst
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hjst/1ef588fd0d86b896e434 to your computer and use it in GitHub Desktop.
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
#!/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