From 20e2849d8c45208c5be0aff346110936828011a8 Mon Sep 17 00:00:00 2001 From: WF Date: Wed, 8 May 2024 15:05:20 +0200 Subject: [PATCH] introduce option L in vimcolor to display supported file types --- ChangeLog | 2 +- README.md | 2 +- vimcolor | 46 +++++++++++++++++++++++++++++++++------------- 3 files changed, 35 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index 24ccb35..2230a9c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,7 @@ **************************************************************************** # ChangeLog for lesspipe.sh # **************************************************************************** -- respect color scheme setting of vim in vimcolor +- respect color scheme setting of vim in vimcolor, add listing of file types - improve xml (and html) display using the xmq binary - fix color detection (-R) again - support for cpio archives diff --git a/README.md b/README.md index 0a84224..6575b9a 100644 --- a/README.md +++ b/README.md @@ -311,7 +311,7 @@ batcat --list-languages pygmentize -L lexers source-highlight --lang-list code2color -h -vim -c "echo getcompletion('', 'filetype')" -c quit +vimcolor -L ``` ### 5.2 Colored Directory listing diff --git a/vimcolor b/vimcolor index 7456f44..e61c9f6 100755 --- a/vimcolor +++ b/vimcolor @@ -22,14 +22,10 @@ use Term::ANSIColor qw(color colorvalid); use IPC::Open3; use Getopt::Std; -our ($opt_c, $opt_h, $opt_l); -&getopts('chl:') || usage(); +our ($opt_c, $opt_h, $opt_l, $opt_L); +&getopts('chl:L') || usage(); usage() if $opt_h; -my ($file) = shift; -my $filetype = $opt_l; -my $report_colors = $opt_c; - # do a clean up if we get a CTRL-C our ($tdir,$script_fh, $markup_fh); $SIG{INT} = sub { if ($tdir) { @@ -38,6 +34,11 @@ $SIG{INT} = sub { if ($tdir) { unlink $tdir; print "\n"; exit 1 }}; $tdir = File::Temp->newdir('/tmp/vimcolorXXXX'); +languages(@ARGV) if $opt_L; + +my ($file) = shift; +my $filetype = $opt_l; +my $report_colors = $opt_c; if (! $file or $file eq '-') { $file = "$tdir/inputfile"; @@ -59,14 +60,14 @@ my %ANSI_COLORS = ( ); # get colors from the active color scheme -my $colorcmds = "$tdir/commands"; +my $cmds = "$tdir/commands"; my $colorfile = "$tdir/colors"; -open F, ">$colorcmds" or die "$!"; -print F "redir! >$colorfile\ncolorscheme\n"; -print F "hi $_\n" for keys %ANSI_COLORS; -print F "redir END\nq!\n"; +open F, ">$cmds" or die "$!"; +print F "redir! >$colorfile|colorscheme|"; +print F "hi $_|" for keys %ANSI_COLORS; +print F "q!"; close F; -run('vim', qw(--not-a-term -RXZi NONE -S), $colorcmds, $colorfile); +run('vim', qw(--not-a-term -RXZi NONE -S), $cmds, $colorfile); open F, $colorfile or die $!; my ($key, %colattrs); my %t = map {$_, $_} qw(bold underline reverse italic blink undercurl standout); @@ -288,9 +289,27 @@ sub run { } } +sub languages { + my ($pat) = @_; + my $cmds = "$tdir/commands"; + my $typefile = "$tdir/types"; + open F, ">$cmds" or die "$!"; + print F "redir! >$typefile|echow getcompletion(\'$pat\', 'filetype')|q!"; + close F; + run('vim', qw(--not-a-term -RXZi NONE -S), $cmds, $typefile); + open F, $typefile or die $!; + $_ = ; $_ = ; + s/[\[\]',]//g; + print "$_\n"; + close F; + exit; +} + sub usage { print <