Skip to content

Commit e948dd4

Browse files
authored
ls: conditional get_columns() (#606)
* get_columns() has the side effect of running external commands via unix() function * Not all modes of ls need the value of $WinCols, e.g. "ls -1" and "ls -l" * Init $WinCols the 1st time it is used within List() * "defined" guard is there because List() can be called repeatedly, e.g. "ls dir1 dir2"
1 parent 69139f3 commit e948dd4

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

bin/ls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ sub List {
373373
} else {
374374

375375
# ------ compute rows, columns, width mask
376+
$WinCols = get_columns() unless defined $WinCols;
376377
$Cols = int($WinCols / $Maxlen) || 1;
377378
$Rows = int(($#_+$Cols) / $Cols);
378379
$Mask = sprintf("%%-%ds ", $Maxlen);
@@ -494,7 +495,6 @@ if ($Options{'f'}) {
494495
$Options{'a'} = 1;
495496
}
496497

497-
$WinCols = get_columns();
498498
$Attributes = stat(*STDOUT);
499499
if ($Attributes->mode & 0140000) {
500500
$Options{'1'} = '1';

0 commit comments

Comments
 (0)