-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmktheme2.pl
More file actions
executable file
·93 lines (74 loc) · 1.79 KB
/
mktheme2.pl
File metadata and controls
executable file
·93 lines (74 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#! /usr/bin/perl
# $Header:$
use strict;
use warnings;
use File::Basename;
use FileHandle;
use Getopt::Long;
use IO::File;
use POSIX;
use JSON;
#######################################################################
# Command line switches. #
#######################################################################
my %opts;
sub main
{
Getopt::Long::Configure('require_order');
Getopt::Long::Configure('no_ignore_case');
usage() unless GetOptions(\%opts,
'help',
);
usage(0) if $opts{help};
my %t;
foreach my $fn (@ARGV) {
my $fh = new FileHandle($fn);
local $/ = undef;
my $str = <$fh>;
my $json = JSON->new->allow_nonref;
my $info = $json->decode($str);
my $s = '';
$s .= "\"$info->{name}\":\n";
$s .= "{\n";
$s .= "\t\"author\": \"$info->{author}\",\n";
$s .= "\t\"filename\": \"$fn\",\n";
$s .= "\t\"background-color\": \"$info->{background}\",\n";
$s .= "\t\"foreground-color\": \"$info->{foreground}\",\n";
$s .= "\t\"color-palette-overrides\":\n";
$s .= "\t\t[";
my $comma = '';
foreach my $c (@{$info->{color}}) {
$s .= "$comma\"$c\"";
$comma = ", ";
}
$s .= "]\n";
$s .= "}\n";
$s .= "\n";
$t{$info->{name}} = $s;
}
my $comma = '';
print "{\n";
print " \"source\": \"http://terminal.sexy\",\n";
print "\n";
foreach my $s (sort(keys(%t))) {
print $comma, $t{$s};
$comma = ",";
}
print "}\n";
}
#######################################################################
# Print out command line usage. #
#######################################################################
sub usage
{ my $ret = shift;
my $msg = shift;
print $msg if $msg;
print <<EOF;
mktheme2.pl -- convert terminal.sexy json files to ctw format.
Usage: mktheme2.pl <list of filenames>
Switches:
EOF
exit(defined($ret) ? $ret : 1);
}
main();
0;