Skip to content

Commit

Permalink
better recognize python and ruby scripts in code2color
Browse files Browse the repository at this point in the history
  • Loading branch information
wofr06 committed Feb 18, 2024
1 parent 641d790 commit a215a5c
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions code2color
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
#!/usr/bin/env perl

#use strict;
use Getopt::Long;
use File::Basename;
use POSIX;
use Term::ANSIColor;

my $VERSION = "0.6";
my $vernr = "0.9.2"; # this is the underlying version of Peter Palfraders script
########################################################################
Expand Down Expand Up @@ -33,6 +27,10 @@ my $vernr = "0.9.2"; # this is the underlying version of Peter Palfraders script

my $LANG_TEST_LENGTH = 1024;

use strict;
use POSIX;
use Term::ANSIColor;

use Getopt::Std;
our($opt_h, $opt_l, $opt_v);
getopts('l:hv') || exit 2;
Expand Down Expand Up @@ -147,7 +145,7 @@ sub get_input_file {

if (not $langmode) {
my $test_code = substr($code, 0, $LANG_TEST_LENGTH);
# warn("language mode not given. guessing...\n");
#warn("language mode not given. guessing...\n");
$langmode = '';

for (sort keys %LANGUAGE) { # make it repeatable
Expand Down Expand Up @@ -1945,7 +1943,7 @@ $LANGUAGE{'povray'} = $LANGUAGE{'pov'};
# by Tom Good
$LANGUAGE{'python'} = {
'filename' => '(?i)\\.py$',
'regex' => '^\\s*#\\s*![^\\s]*python',
'regex' => '^\\s*#\\s*!([^\\s]*\\b|.*env\\s+)*python',
'patterns' => [
{
'name' => 'python comment',
Expand Down Expand Up @@ -2049,7 +2047,7 @@ $LANGUAGE{'python'} = {
# by Joshua Swink <jswink AT pacbell.net>
$LANGUAGE{'ruby'} = {
'filename' => '\\.rb$',
'regex' => '^\\s*#\\s*![^\\s]*\\bruby\\b',
'regex' => '^\\s*#\\s*!([^\\s]*\\b|.*env\\s+)ruby\\b',
'patterns' => [
{
'name' => 'comment',
Expand Down

0 comments on commit a215a5c

Please sign in to comment.