first commit

This commit is contained in:
Rui Carmo 2011-04-16 19:16:28 +01:00
commit 8aa3518300
4 changed files with 501 additions and 0 deletions

77
README.mkd Normal file
View file

@ -0,0 +1,77 @@
---
Title: Solarized Colorscheme for BBEdit and TextWrangler
Description: Precision colors for machines and people
Author: Rui Carmo
Created: 2011 Apr 07
Modified: 2011 Apr 16
---
Solarized Colorscheme for BBEdit and TextWrangler
=================================================
Developed by Rui Carmo <rui.carmo@taoofmac.com>
If you have come across this colorscheme via the [repository] on
github page, visit the [Solarized homepage] or visit the main
[Solarized repository].
[Solarized homepage]: http://ethanschoonover.com/solarized
[Solarized repository]: https://github.com/altercation/solarized
Installation
------------
Since TextWrangler (and BBEdit) don't allow you to save theme files separately, these `.bbcolor` files are generated by John Gruber's [BBColors][b] utility (bundled for your convenience), which manipulates their preferences file directly.
To install these, place the files in `~/Library/Application\ Support/BBColors` and, with TextWrangler/BBEdit *closed*, invoke [BBColors][b] thusly:
1. For BBEdit:
./bbcolors -load "Solarized Dark"
2. For TextWrangler:
./bbcolors -load "Solarized Light" -tw
[b]:http://daringfireball.net/projects/bbcolors/
License
-------
Copyright (c) 2011 Rui Carmo
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
Since TextWrangler (and BBEdit) don't allow you to save theme files separately, these `.bbcolor` files are generated by John Gruber's [BBColors][b] utility (bundled), which manipulates their preferences file directly.
To install these, place the files in `~/Library/Application\ Support/BBColors` and, with TextWrangler/BBEdit *closed*, invoke [BBColors][b] thusly:
For BBEdit:
<pre>./bbcolors -load "Solarized Dark"</pre>
For TextWrangler:
<pre>./bbcolors -load "Solarized Light" -tw</pre>
[b]:http://daringfireball.net/projects/bbcolors/
When you restart your editor, the theme will have been applied.

19
Solarized Dark.bbcolors Normal file
View file

@ -0,0 +1,19 @@
"Color:Background" = "rgb(1044,8292,10466)";
"Color:Comment" = "rgb(28873,33399,33872)";
"Color:Foreground" = "rgb(60037,58327,52285)";
"Color:HTMLAnchor" = "rgb(48611,13976,4819)";
"Color:HTMLAttributeName" = "rgb(8359,30320,51269)";
"Color:HTMLAttributeValue" = "rgb(9620,37409,34407)";
"Color:HTMLImage" = "rgb(50946,7079,28519)";
"Color:HTMLTag" = "rgb(28873,33399,33872)";
"Color:InsertionPointLineHighlightColor" = "rgb(2581,10493,12998)";
"Color:Invisibles:Other" = "rgb(2581,10493,12998)";
"Color:Invisibles:Spaces" = "rgb(2581,10493,12998)";
"Color:Keywords" = "rgb(8359,30320,51269)";
"Color:NumericConstant" = "rgb(8359,30320,51269)";
"Color:PredefinedName" = "rgb(48611,13976,4819)";
"Color:PrimaryHighlight" = "rgb(21257,26684,28737)";
"Color:SecondaryHighlight" = "rgb(2581,10493,12998)";
"Color:String" = "rgb(9620,37409,34407)";
"Color:UseCustomHighlight" = 1;
"Color:XMLProcessingInstruction" = "rgb(42432,30639,1539)";

19
Solarized Light.bbcolors Normal file
View file

@ -0,0 +1,19 @@
"Color:Background" = "rgb(64843,62779,56626)";
"Color:Comment" = "rgb(28873,33399,33872)";
"Color:Foreground" = "rgb(1044,8292,10466)";
"Color:HTMLAnchor" = "rgb(48611,13976,4819)";
"Color:HTMLAttributeName" = "rgb(8359,30320,51269)";
"Color:HTMLAttributeValue" = "rgb(9620,37409,34407)";
"Color:HTMLImage" = "rgb(50946,7079,28519)";
"Color:HTMLTag" = "rgb(28873,33399,33872)";
"Color:InsertionPointLineHighlightColor" = "rgb(60037,58327,52285)";
"Color:Invisibles:Other" = "rgb(60037,58327,52285)";
"Color:Invisibles:Spaces" = "rgb(60037,58327,52285)";
"Color:Keywords" = "rgb(8359,30320,51269)";
"Color:NumericConstant" = "rgb(8359,30320,51269)";
"Color:PredefinedName" = "rgb(48611,13976,4819)";
"Color:PrimaryHighlight" = "rgb(33160,37018,36938)";
"Color:SecondaryHighlight" = "rgb(60037,58327,52285)";
"Color:String" = "rgb(9620,37409,34407)";
"Color:UseCustomHighlight" = 1;
"Color:XMLProcessingInstruction" = "rgb(42432,30639,1539)";

386
bbcolors Executable file
View file

@ -0,0 +1,386 @@
#!/usr/bin/env perl
#
# bbcolors -- A text color scheme manager for BBEdit and TextWrangler.
#
# Copyright (c) 2006 John Gruber
# <http://daringfireball.net/projects/bbcolors/>
#
# This program is free software; you may redistribute it and/or
# modify it under the same terms as Perl itself.
#
use warnings;
use strict;
use Getopt::Long;
use Pod::Usage;
use encoding 'utf8';
use utf8;
use vars qw($VERSION);
$VERSION = '1.0.1';
# Sun 15 Oct 2006
my $delete_setname;
my $load_setname;
my $save_setname;
my $language;
my $bbopen = 0; # If set, open a disk browser window showing the current saved color sets.
my $reckless = 0; # If set, apply defaults changes even if app is running.
my $zap = 0; # If set, clear all existing text color prefs, resetting to BBEdit defaults.
my %app = (
name => "BBEdit",
bundle => "com.barebones.bbedit",
creator => "R*ch",
tool => "bbedit",
);
# This should work even on systems not using English; the true names aren't localized:
my $bbcolors_support_folder = "$ENV{HOME}/Library/Application Support/BBColors";
unless (-d $bbcolors_support_folder) {
mkdir $bbcolors_support_folder
or die "Can't create application support folder: $!";
}
GetOptions (
"delete=s" => \$delete_setname,
"list" => \&list_color_sets,
"load=s" => \$load_setname,
"save=s" => \$save_setname,
"reckless" => \$reckless,
"language=s" => \$language,
"bbedit" => , # Do nothing; uses BBEdit by default
"textwrangler|tw" => sub {%app = (
name => "TextWrangler",
bundle => "com.barebones.textwrangler",
creator => "!Rch",
tool => "edit",
)},
"open" => \&open_sets_folder_in_finder,
"bbopen" => \$bbopen,
"zap" => \$zap,
'help|?' => sub { pod2usage(1); },
'man' => sub { pod2usage(-verbose => 2); },
"version" => sub { print "Version $VERSION\n"; exit 0; },
) or pod2usage(2);
# Save first:
if ($save_setname) {
open (SETFILE, '>:utf8', "$bbcolors_support_folder/$save_setname.bbcolors")
or die "Can't open file for writing: $!";
my @lines = qx(defaults read $app{bundle} | egrep \\"Color:);
if ($language) {
# Only save color prefs for the language "$language"
$language = quotemeta $language;
@lines = grep(/"Color:.+:$language/, @lines);
}
my $len = 0; # Longest key string
foreach (@lines) {
if (m{^\s*(.+?) = (.+);\s*$}ms) {
my $key = $1; # Should already have quotes around it
my $val = $2;
$key = unescape_plist_string($key);
$len = length $key if (length $key > $len);
$_ = "$key = $val;";
}
}
# Loop through again to print; I can't figure out a way to do this
# in one loop and still get the pretty-printed alignment.
foreach (@lines) {
if (m{^\s*(.+?) = (.+);\s*$}ms) {
my $key = $1; # Should already have quotes around it
my $val = $2;
$val = " " . $val unless $val =~ m/^"/; # Looks better with a space before non-string values.
printf SETFILE ("%-${len}s = %s;\n", $key, $val);
}
}
close SETFILE;
}
# Then Zap:
if ($zap) {
if ( is_editor_running($app{name}) and ! $reckless ) {
print "Won't zap prefs while $app{name} is running.\n";
exit 0;
}
else {
my @lines = qx(defaults read $app{bundle} | egrep \\"Color:);
if ($language) {
# Only zap color prefs for the language "$language"
$language = quotemeta $language;
@lines = grep(/"Color:[^"]+:$language/, @lines);
}
foreach (@lines) {
if (m{^\s*(.+?) = (.+);\s*$}ms) {
my $key = $1; # Should already have quotes around it
$key = unescape_plist_string($key);
my $res = qx(defaults delete $app{bundle} $key );
}
else {
print STDERR "Can't parse line: «$_»\n";
}
}
}
}
# Then load:
if ($load_setname) {
if ( is_editor_running($app{name}) and ! $reckless ) {
print "Won't load prefs while $app{name} is running.\n";
exit 0;
}
else {
open (SETFILE, '<:utf8', "$bbcolors_support_folder/$load_setname.bbcolors")
or do {print "No such scheme: '$load_setname'\nTry 'bbcolors -list' to see available schemes.\n"; exit;};
while (<SETFILE>) {
#
# These lines should look like:
# "Color:CTagsIdentifier" = "rgb(39321,0,26214)";
# "Color:ColorAttributesSeparately" = 1;
#
next if m{^[ \t]*//}ms; # Treat // lines as comments.
if (m{^\s*(.+?)[ \t]*=[ \t]*(.+);\s*$}ms) {
my $key = $1; # These two captures keep the quotes around the key...
my $val = $2; # ...and value.
my $type = "-string";
if ($val =~ m{^\d+$}) {
# If the value is nothing but digits, treat it as an integer.
# This seems to work even if it's actually a boolean. (I.e.
# there's no need to guess whether 1 and 0 are bools or ints.)
$type = "-integer";
}
if ($language) {
my $quoted = quotemeta $language;
next if ($key !~ m/$quoted"$/);
}
my $res = qx(defaults write $app{bundle} $key $type $val );
}
else {
# Do nothing with lines that don't match.
}
}
}
}
# Then delete:
if ($delete_setname) {
if (-f "$bbcolors_support_folder/$delete_setname.bbcolors") {
unlink "$bbcolors_support_folder/$delete_setname.bbcolors"
or die "Unable to delete $bbcolors_support_folder/$delete_setname.bbcolors: $!";
}
else {
print "Color scheme '$delete_setname' does not exist.\n";
}
}
# bbopen last; that way it won't fire up your editor before you diddle with the prefs
if ($bbopen) {
system($app{tool}, $bbcolors_support_folder);
}
#### End of main script. ####
sub unescape_plist_string {
my $str = shift;
# Un-double backslashes
$str =~ s{\\\\}{\\}g;
# Unescape Unicode chars:
$str =~ s{ \\U([[:xdigit:]]{4}) }{ chr(hex($1)) }egx;
return $str;
}
sub escape_plist_string {
my $str = shift;
# Encode Unicode chars into plist \U hex escapes;
# e.g. "Langüage" -> "Lang\U00fcage"
$str =~ s{ (\P{IsASCII}) }{ sprintf("\\U%04x", ord($1)) }egx;
# Double all backslashes:
$str =~ s{\\}{\\\\}g;
return $str;
}
sub is_editor_running {
my $app_name = shift;
my @processes = qx( ps -xc -o command );
chomp @processes;
my $count = grep { $_ eq $app_name } @processes;
return $count;
}
sub list_color_sets {
my $count = 0;
opendir(FOLDER, $bbcolors_support_folder)
or die "Can't open $bbcolors_support_folder: $!";
while( my $file = readdir FOLDER ) {
if (-T "$bbcolors_support_folder/$file" and $file =~ m/[.]bbcolors$/) {
$count++;
$file =~ s/[.]bbcolors$//; # trim the extension
print "$file\n";
}
}
print "No color sets available in $bbcolors_support_folder\n" unless $count;
closedir(FOLDER);
}
sub open_sets_folder_in_finder {
system("open", $bbcolors_support_folder);
}
__END__
=head1 NAME
bbcolors - Save and load text color sets for BBEdit.
=head1 SYNOPSIS
bbcolors -save "scheme name"
bbcolors -load "scheme name"
bbcolors -man
=head1 DESCRIPTION
B<bbcolors> saves and loads "sets" of text color preferences for BBEdit.
=head1 OPTIONS
=over 8
=item B<-delete> F<setname>
Delete the saved bbcolors scheme named 'setname'. Does not effect current BBEdit preferences.
=item B<-list>
List all color sets.
=item B<-load> F<setname>
Replace current BBEdit text colors with scheme named "setname".
=item B<-save> F<setname>
Save current BBEdit text colors to scheme named "setname', overwriting any existing scheme with that name.
=item B<-zap>
Deletes all current BBEdit (or TextWrangler) color settings, including those keyed to specific languages. For example, if you set custom colors for the Perl language in BBEdit, and then use bbcolors to load a new colorset that does not contain Perl-specific colors, your previously-set custom colors for Perl will remain in place. If you use the B<-zap> option when loading the new scheme, however, your custom color settings will be deleted, and your Perl files will be displayed using the default colors of the just-loaded color scheme.
=item B<-lang> F<"language name">
Target a specific language when saving, loading, or zapping.
=over 4
=item *
If saving, only save those colors set for the specified language. (The <-save> command normally saves all colors.)
=item *
If loading, only load those colors from the named scheme which are keyed to the specified language.
=item *
If zapping, only zap the preferences keyed to the specified language.
=back
=item B<-open>
Open the ~/Library/Application Support/BBColors/ folder in the Finder. If the folder doesn't exist, it will be created.
=item B<-bbopen>
Open the ~/Library/Application Support/BBColors/ folder in a new disk browser window using BBEdit (or TextWrangler, if used in conjunction with the B<-tw> option). If the folder doesn't exist, it will be created.
=item B<-bbedit>
Explicitly use with BBEdit (as opposed to TextWrangler). This option is on by default.
=item B<-textwrangler>
=item B<-tw>
Use TextWrangler instead of BBEdit.
=item B<-help>
Print a brief help message and exit.
=item B<-man>
Print the full bbcolors manual page.
=item B<-version>
Print the current bbcolors version number.
=back
=head1 A NOTE ON TEXT ENCODING
B<bbcolors> should work just fine with languages modules and saved color sets whose names contain non-ASCII characters. The only provision is that all input and output is assumed to be UTF-8.
=head1 VERSION HISTORY
=over 8
=item 1.0.1 - Sun 15 Oct 2006
Switched to a more efficient method of testing whether BBEdit and TextWrangler are currently running. Cleaned up the documentation slightly, replacing several instances of "color set" with "color scheme".
=back
=head1 COPYRIGHT AND LICENSE
Copyright (c) 2006 John Gruber. <http://daringfireball.net/>
This program is free software; you may redistribute it and/or modify it under the same terms as Perl itself.
=cut