App-lsplusplus

 view release on metacpan or  search on metacpan

ls++  view on Meta::CPAN

  ## 0.75 < hour < 42
  $unit = "hour";
  $ret = int($ret/60);

  return relative_time_format(fg($c[9]), "<", $unit)
    if $delta < 90 * 60;
  return relative_time_format(fg($c[9]), $ret, $unit)
    if $delta < 24 * 60 * 60;
  return relative_time_format(fg($c[9]), $ret, $unit)
    if $delta < 30 * 60 * 60;
  return relative_time_format(fg($c[9]), $ret, $unit)
    if $delta < 36 * 60 * 60;

  ## 0.75 < day < 30
  $unit = "day ";
  $ret = int($ret/24);

  return relative_time_format(fg($c[4]), "<", $unit)
    if $delta < 48 * 60 * 60;
  return relative_time_format(fg($c[4]), $ret, $unit)
    if $delta < 7 * 24 * 60 * 60;
  return relative_time_format(fg($c[4]), $ret, $unit)
    if $delta < 14 * 24 * 60 * 60;
  return relative_time_format(fg($c[4]), $ret, $unit)
    if $delta < 28 * 24 * 60 * 60;
  return relative_time_format(fg($c[4]), $ret, $unit)
    if $delta < 30 * 24 * 60 * 60;

  ## 1 < month < 12
  $unit = "mon ";
  $ret = int($ret/30);

  return relative_time_format(fg($c[14]), "<", $unit)
    if $delta < 2 * 30 * 24 * 60 * 60;
  return relative_time_format(fg($c[14]), $ret, $unit)
    if $delta < 12 * 30 * 24 * 60 * 60;

  ## 1 < years < inf
  $unit = "year";
  $ret = int($ret/12);

  return relative_time_format(fg($c[0]), $ret, $unit);
}


sub _get_color_support {
  my $colors = 8;
  if(exists($ENV{DISPLAY}) && !($ENV{DISPLAY})) {
    $colors = 16;
    return $colors;
  }
  if(
    $ENV{TERM} eq 'xterm'
      or($ENV{TERM} eq 'xterm-256color') # What Mac OS Lion terminal pretends to be
      or($ENV{TERM} eq 'rxvt-256-color')
      or($ENV{TERM} =~ /screen-256/)
      or($ENV{TERM} eq 'Eterm-256color')
      or($ENV{TERM} eq 'gnome-256color')
      or($ENV{TERM} eq 'konsole-256color')
      or($ENV{TERM} eq 'putty-256color')
      or($ENV{TERM} eq /rxvt-unicode-256color/)
      or($ENV{TERM} =~ /u?rxvt-256color/)
  ) {
    $colors = 256;
  }
  elsif($ENV{TERM} eq 'rxvt-unicode') {
    $colors = 88;
  }
  elsif($ENV{TERM} eq 'screen') {
    $colors = $ENV{TMUX} ? 256 : 8;
  }
  else {
    chomp($colors = `tput colors`); # fail silently
  }

  return $colors;
}


sub _init_config {
  my $config;

  if($ENV{DEBUG}) {
    require('./ls++.conf');
    print "Using ./ls++.conf\n" unless $@;
  }

  require "$ENV{HOME}/.ls++.conf",
  return 1;
}


sub isa_tty {
  return 1 if -t STDOUT;
  return 0;
}

sub get_ls_where {
  my @files;
  for(@_) {
    if(-e $_) {
      push(@files, escape($_));
    }
    else {
      push(@ls_opts, $_);
    }
  }
  return (wantarray()) ? @files : scalar(@files);
}


sub get_ls_cmdline {
  my $os = get_os();

  if( ($os eq 'darwin') || ($os =~ m/.*bsd$/) ) {
    return '-lvGcTh ' . join('', @ls_opts);
  }

  return '-hlv --group-directories-first --color=always --time=ctime ' .
         '--time-style=+%s ' . join('', @ls_opts);
}

sub escape {
  my $p = shift;
  $p =~ s/([;<>*|`&\$!#()[\]{}:'" ])/\\$1/g;
  return $p;



( run in 0.980 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )