#!/usr/bin/perl # COLUMNS - Copyright (C) 2008 Xenoscience, Inc. # Released under GPL v3 # SSF 101808 - display files in columns side-by-side (pipe to less) - a better 'paste' use integer; use strict; use Getopt::Std; use Term::Size 'chars'; my (%opts); my ($cols,$rows)=chars; getopts('d:htw:',\%opts); unless (@ARGV or $opts{h}) { print <) { chomp; push @$arr,$_; $len=length($_); $wd=$len if $len>$wd; } close FILE; $maxrow=scalar @$arr if $maxrow$wd; $spacer=($cols/$wd); --$spacer while ($spacer>0 and @cols*($wd+$spacer)-$spacer>$cols); $spacer=$opts{d} x $spacer; # titles if ($opts{t}) { # determine if titles can have pathnames chopped off if (scalar @titles > scalar %titles) { # no, some basenames are non-unique @titles=@ARGV; } $col=scalar @cols; for $file (@titles) { $line=(' ' x ($wd/2-length($file)/2)).$file; print $line.(' ' x ($wd-length($line))); --$col; print $spacer if $col; } print "\n"; $col=scalar @cols; for $file (@titles) { print '=' x $wd; --$col; print $spacer if $col; } print "\n"; } # content for ($row=0; $row<$maxrow; ++$row) { $col=scalar @cols; for $arr (@cols) { $line=$arr->[$row]; print $line.(' ' x ($wd-length($line))); --$col; print $spacer if $col; } print "\n"; } exit; sub get_basename { # extract basename from url or path my $path=shift; my $i=rindex($path,'/'); $i>-1 ? substr($path,$i+1) : $path; }