The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

File::LsColor - Colorize input filenames just like ls does

SYNOPSIS

    use File::LsColor qw(ls_color ls_color_custom ls_color_internal);

    for my $file(glob("$ENV{HOME}/*")) {
      print ls_color($file);
    }

    # or specify own pattern

    my @c = ls_color_custom('*.pl=38;5;196;1:*.pm=38;5;220', @files);

    # or use the internal mappings

    my @c

DESCRIPTION

This module provides functionality for using the LS_COLORS variable for colorizing output in a way that's immediately recognized.

Say that you have a list of filenames that's the result of some complex operation, and you wish to present the result to the user.

If said files have an extension and that extension is present in the users LS_COLORS variable, they will be colored just like they would have been if the filenames were output from ls(1) or tree(1).

EXPORTS

None by default.

FUNCTIONS

ls_color()

Arguments: @files | \@files

Returns: @files

Returns a list of filenames colored as specified by the environment LS_COLORS variable. If the LS_COLORS variable is not set, throws an exception. In this case, ls_color_internal() can be used.

ls_color_internal()

The same as ls_color(), with one minor difference; Instead of using the LS_COLORS variable from the environment, an internal specification is used. This specification contains about 250 extensions as of this writing.

ls_color_custom()

The first argument to ls_color_custom() should be a valid LS_COLORS definition, like so:

  ls_color_custom("*.pl=38;5;196", @perl_files);

AUTHOR

  Magnus Woldrich
  CPAN ID: WOLDRICH
  magnus@trapd00r.se
  http://japh.se

REPORTING BUGS

Report bugs on rt.cpan.org or to magnus@trapd00r.se

CONTRIBUTORS

None required yet.

COPYRIGHT

Copyright 2011 THIS MODULEs "AUTHOR" and "CONTRIBUTORS" as listed above.

LICENSE

This library is free software; you may redistribute it and/or modify it under the same terms as Perl itself.