GithubHelp home page GithubHelp logo

trapd00r / file-lscolor Goto Github PK

View Code? Open in Web Editor NEW
41.0 6.0 6.0 114 KB

Colorize input filenames just like ls(1) does

Home Page: https://metacpan.org/release/File-LsColor

Perl 98.61% Shell 1.39%
dircolors lscolors ls coreutils cli colors terminal terminal-colors

file-lscolor's Introduction

Donate - Every tiny cent helps a lot!

NAME

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

SYNOPSIS

use File::LsColor qw(:all);
# Is equal to:
use File::LsColor qw(
  ls_color
  ls_color_custom
  ls_color_default
  ls_color_internal
);

my @files = glob("$ENV{HOME}/*");

print ls_color($_), "\n" for(@files);

# or specify own pattern

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

# or use the internal mappings

@files = ls_color_internal(@files);

# or use the defaults (only ANSI colors)

@files = ls_color_default(@files);

...

# returns a hashref with all defined filetypes and their attributes
my $ls_colors = get_ls_colors();

# what's the defined attributes for directories?

my $dir_color = lookup_ls_color('di');

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 | @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.

In scalar context a string joined by '' is returned.

ls_color_default()

The same thing as ls_color(), but uses the default LS_COLORS values from GNU ls. Those are only ANSI colors.

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:*.pm=38;5;197;1", @perl_files);

get_ls_colors()

Returns a hash reference where a key is the extension and its value is the attributes attached to it.

lookup_ls_color()

Given a valid name, returns the defined attributes associated with it. Else, returns undef.

File::LsColor out in the wild

AUTHOR

Magnus Woldrich
CPAN ID: WOLDRICH
[email protected]
http://japh.se
https://github.com/trapd00r

REPORTING BUGS

Report bugs on https://github.com/trapd00r/File-LsColor or to [email protected]

COPYRIGHT

Copyright 2011, 2018, 2019- the File::LsColor "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.

file-lscolor's People

Contributors

numirias avatar trapd00r avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

file-lscolor's Issues

output differ from ls

Hi,
file 'abc' which is a perl ascii text executable, is not displayed with the executable color as ls does.

I tried ls_color and ls_color_custom($ENV{LS_COLORS}, $path), both color wrong.

t/03-ls_color.t fails (with newer Term::ExtendedColor?)

On some of my smokers:

...
#   Failed test 'ls_color_custom() OK'
#   at t/03-ls_color.t line 6.
#          got: '�[38;5;100m�[1mmain.c�[m'
#     expected: '�[38;5;100m�[38;1mmain.c�[m'
# Looks like you failed 1 test of 6.
t/03-ls_color.t ...... 
Dubious, test returned 1 (wstat 256, 0x100)
Failed 1/6 subtests 
...

This seems to happen with newer versions of Term::ExtendedColor (>= 0.500):

****************************************************************
Regression 'mod:Term::ExtendedColor'
****************************************************************
Name           	       Theta	      StdErr	 T-stat
[0='const']    	      1.0000	      0.0000	9673489717902510.00
[1='eq_0.226'] 	      0.0000	      0.0000	   1.71
[2='eq_0.230'] 	      0.0000	      0.0000	   1.10
[3='eq_0.239'] 	      0.0000	      0.0000	   2.72
[4='eq_0.240'] 	      0.0000	      0.0000	   2.82
[5='eq_0.242'] 	      0.0000	      0.0000	   2.61
[6='eq_0.300'] 	      0.0000	      0.0000	   6.14
[7='eq_0.302'] 	      0.0000	      0.0000	   0.88
[8='eq_0.500'] 	     -1.0000	      0.0000	-9408412159285668.00
[9='eq_0.501'] 	     -1.0000	      0.0000	-5584991892634090.00
[10='eq_0.502']	     -1.0000	      0.0000	-9293988296281330.00

R^2= 1.000, N= 135, K= 11
****************************************************************

ls_colors doesn't put colors when the extension is in capital case

I remarked that ls_colors, both the terminal and the module subroutine doesn't colorize filenames which have capital case.
For example,
viddeo.MP4 and video.MKV aren't colorized.
I have tested it and they are colored, though, when using the ls command: ls *.MP4 *.MKV

It would be nice if this module could do it because it's not that uncommon to download files that an extension that is capitalized.
Thank you !

Failed test 'Pod coverage on File::LsColor'

The pod coverage test is failing:

#   Failed test 'Pod coverage on File::LsColor'
#   at /usr/perl5.16.3t/lib/site_perl/5.16.3/Test/Pod/Coverage.pm line 133.
# Coverage for File::LsColor is 85.7%, with 1 naked subroutine:
# 	ls_color_lookup
# Looks like you failed 1 test of 1.
t/02-pod-coverage.t .. 
Dubious, test returned 1 (wstat 256, 0x100)
Failed 1/1 subtests 

Additionally the synopsis test also fails:

#   Failed test 'lib/File/LsColor.pm'
#   at /usr/perl5.16.3t/lib/site_perl/5.16.3/Test/Synopsis.pm line 24.
# syntax error at lib/File/LsColor.pm line 348, near "...
# 
# # returns a hashref with all defined filetypes and their attributes
# my "
# Global symbol "$ls_colors" requires explicit package name at lib/File/LsColor.pm line 348.
# Looks like you failed 1 test of 1.
t/021-synopsis.t ..... 
Dubious, test returned 1 (wstat 256, 0x100)
Failed 1/1 subtests 

Fails if LS_COLORS environment variable is not set

See subject. If there's no LS_COLORS then test suite fails starting with:

PERL_DL_NONLAZY=1 "/usr/perl5.20.1Dp/bin/perl" "-MExtUtils::Command::MM" "-MTest::Harness" "-e" "undef *Test::Harness::Switches; test_harness(0, 'blib/lib', 'blib/arch')" t/*.t

#   Failed test 'use File::LsColor;'
#   at t/00-load.t line 6.
#     Tried to use 'File::LsColor'.
#     Error:  LS_COLORS variable not set! Nothing to do...
#  at t/00-load.t line 6.
# Compilation failed in require at t/00-load.t line 6.
# BEGIN failed--compilation aborted at t/00-load.t line 6.
# Looks like you failed 1 test of 1.
t/00-load.t .......... 
Dubious, test returned 1 (wstat 256, 0x100)
Failed 1/1 subtests 
... (etc) ...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.