Skip to content

Instantly share code, notes, and snippets.

@nathanpc
Created August 1, 2023 11:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nathanpc/6f5f4aeddf5a220ba45c02892fae7e96 to your computer and use it in GitHub Desktop.
Save nathanpc/6f5f4aeddf5a220ba45c02892fae7e96 to your computer and use it in GitHub Desktop.
Converts an iTerm2 color profile made for newer versions of iTerm to work in iTerm2 version 2.0 for OS X Leopard.
#!/usr/bin/env perl
### fix-itermcolors.pl
### Converts an iTerm2 color profile made for newer versions of iTerm to work
### in iTerm2 version 2.0 for OS X Leopard.
###
### Author: Nathan Campos <nathan@innoveworkshop.com>
use strict;
use warnings;
use autodie;
# Slurps the file.
sub slurp {
my ($fname) = @_;
open my $fh, '<', $fname;
local $/ = undef;
my $data = <$fh>;
close $fh;
return $data;
}
# Read the iTerm color profile.
my $plist = slurp($ARGV[0]);
# Strip out invalid keys.
$plist =~ s/\s+<key>Alpha Component<\/key>[^\/]+.+//g;
$plist =~ s/\s+<key>Color Space<\/key>[^\/]+.+//g;
# Remove invalid dictionaries.
$plist =~ s/\s+<key>Badge Color<\/key>((?!<\/dict>)[\s\S])*<\/dict>\s?//gs;
$plist =~ s/\s+<key>Cursor Guide Color<\/key>((?!<\/dict>)[\s\S])*<\/dict>\s?//gs;
$plist =~ s/\s+<key>Link Color<\/key>((?!<\/dict>)[\s\S])*<\/dict>\s?//gs;
$plist =~ s/\s+<key>Tab Color<\/key>((?!<\/dict>)[\s\S])*<\/dict>\s?//gs;
# Print it out.
print $plist;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment