Skip to content

Instantly share code, notes, and snippets.

@muralisc
Forked from thumphries/xdefaults2iterm.pl
Created June 15, 2017 14:30
Show Gist options
  • Select an option

  • Save muralisc/22c591fae9ac436765a02de3235a23e2 to your computer and use it in GitHub Desktop.

Select an option

Save muralisc/22c591fae9ac436765a02de3235a23e2 to your computer and use it in GitHub Desktop.

Revisions

  1. timothy revised this gist Oct 8, 2012. 1 changed file with 3 additions and 9 deletions.
    12 changes: 3 additions & 9 deletions xdefaults2iterm.pl
    Original file line number Diff line number Diff line change
    @@ -5,10 +5,6 @@

    use strict;

    use Color::Rgb;

    my $rgb = new Color::Rgb(rgb_txt=>"rgb.txt");

    print <<eof;
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    @@ -39,13 +35,11 @@
    print "</dict>\n</plist>";

    sub do_color {
    my $color = shift;
    my $ret = "";
    my @colors = $rgb->hex2rgb("#$2");
    my $i = 0;
    for(@colors) {
    my $ret = '';
    for (shift =~ m/.{2}/gs) {
    $ret .= "\t\t<key>$cols{$i} Component</key>\n\t\t<real>";
    $ret .= sprintf("%.16f", $colors[$i]/255);
    $ret .= sprintf("%.16f", hex($_)/255);
    $ret .= "</real>\n";
    $i++;
    }
  2. timothy revised this gist Oct 8, 2012. 1 changed file with 7 additions and 8 deletions.
    15 changes: 7 additions & 8 deletions xdefaults2iterm.pl
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,8 @@
    #!/usr/bin/perl -w

    # Convert .Xdefaults or similar terminal colors to iTerm2 scheme
    # Only supports simple hex colors, no funny stuff

    use strict;

    use Color::Rgb;
    @@ -21,23 +25,18 @@
    while (<>) {
    if(/^[^!]*color(\d+):\s+#(\w{6})/) {
    print "\t<key>Ansi $1 Color</key>\n\t<dict>\n";
    my $out = &do_color($2);
    print $out;
    print &do_color($2);
    print "\t</dict>\n";
    } elsif(/^[^!]*(fore|back)ground:\s+#(\w{6})/) {
    my $fb = $1;
    $fb =~ tr/fb/FB/;
    print "\t<key>" . $fb . "ground Color</key>\n\t<dict>\n";
    my $out = &do_color($2);
    print $out;
    print &do_color($2);
    print "\t</dict>\n";
    }
    }

    print <<eof;
    </dict>
    </plist>
    eof
    print "</dict>\n</plist>";

    sub do_color {
    my $color = shift;
  3. timothy created this gist Oct 8, 2012.
    54 changes: 54 additions & 0 deletions xdefaults2iterm.pl
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,54 @@
    #!/usr/bin/perl -w
    use strict;

    use Color::Rgb;

    my $rgb = new Color::Rgb(rgb_txt=>"rgb.txt");

    print <<eof;
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
    eof

    my %cols = (
    2 => "Blue",
    1 => "Green",
    0 => "Red",
    );

    while (<>) {
    if(/^[^!]*color(\d+):\s+#(\w{6})/) {
    print "\t<key>Ansi $1 Color</key>\n\t<dict>\n";
    my $out = &do_color($2);
    print $out;
    print "\t</dict>\n";
    } elsif(/^[^!]*(fore|back)ground:\s+#(\w{6})/) {
    my $fb = $1;
    $fb =~ tr/fb/FB/;
    print "\t<key>" . $fb . "ground Color</key>\n\t<dict>\n";
    my $out = &do_color($2);
    print $out;
    print "\t</dict>\n";
    }
    }

    print <<eof;
    </dict>
    </plist>
    eof

    sub do_color {
    my $color = shift;
    my $ret = "";
    my @colors = $rgb->hex2rgb("#$2");
    my $i = 0;
    for(@colors) {
    $ret .= "\t\t<key>$cols{$i} Component</key>\n\t\t<real>";
    $ret .= sprintf("%.16f", $colors[$i]/255);
    $ret .= "</real>\n";
    $i++;
    }
    return $ret;
    }