-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathruler
executable file
·52 lines (42 loc) · 1.14 KB
/
ruler
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/perl
$columns = $ARGV[0];
# || $ENV{'COLUMNS'};
if ( $columns < 1 ) {
@rc = split(/ /, `stty size`);
$columns = $rc[1] + 0;
}
# print "0: $ARGV[0], 1: $ARGV[1] stty: " . $columns . "\n";
# $zero_based = 1;
# emacs ^X = (what-cursor-position) is zero-based
# NOTE: this does not match the number that 'cut' expects, which is +1
# no arg processing yet.
$zero_based = 0;
if ( $zero_based ) {
# zero (_) through 9
$z9 = join('', '_', 1..9 );
} else {
# 9 through zero
$z9 = join('', 1..9, '_', );
}
$tens = int( $columns/10 );
# 0..9
for ( 1.. $tens ) { print $z9; }
print substr( $z9, 0, $columns - 10*$tens), "\n";
# 'tens' line
for ( 0.. $tens-1 ) {
if ( $zero_based ) {
$tensline = "${_}_________";
print substr( $tensline,0,10 );
} else {
$tensline = sprintf("__________%d", 1+$_);
#print "$tensline\n";
print substr( $tensline,length("$_"),10 );
}
}
if ( $zero_based ) {
print substr( "$tens ", 0, $columns - 10*$tens ), "\n";
} else {
$tensline = sprintf("__________%d", $tens);
print substr( $tensline,length("$tens"), $columns - 10*$tens );
print "\n";
}