From 14c09ef73000ae3a29c2002e303ae38dd0d5436e Mon Sep 17 00:00:00 2001 From: Fabio Gallonetto Date: Sun, 7 Apr 2013 16:35:32 +0100 Subject: [PATCH 1/2] Add autoinstall of Solarized iTerm2 themes The rake script now detects the available iTerm2 profiles and installs the solarized scheme where needed. It's an interactive procedure that requires selection by the user. --- Rakefile | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 62 insertions(+), 5 deletions(-) diff --git a/Rakefile b/Rakefile index e37f33e..ffa9199 100644 --- a/Rakefile +++ b/Rakefile @@ -166,11 +166,60 @@ def install_term_theme run %{ /usr/libexec/PlistBuddy -c "Add :'Custom Color Presets':'Solarized Dark' dict" ~/Library/Preferences/com.googlecode.iterm2.plist } run %{ /usr/libexec/PlistBuddy -c "Merge 'iTerm2/Solarized Dark.itermcolors' :'Custom Color Presets':'Solarized Dark'" ~/Library/Preferences/com.googlecode.iterm2.plist } - puts "======================================================" - puts "To make sure your profile is using the solarized theme" - puts "Please check your settings under:" - puts "Preferences> Profiles> [your profile]> Colors> Load Preset.." - puts "======================================================" + # If iTerm2 is not installed or has never run, we can't autoinstall the profile since the plist is not there + if !File.exists?(File.join(ENV['HOME'], '/Library/Preferences/com.googlecode.iterm2.plist')) + puts "======================================================" + puts "To make sure your profile is using the solarized theme" + puts "Please check your settings under:" + puts "Preferences> Profiles> [your profile]> Colors> Load Preset.." + puts "======================================================" + return + end + + # Ask the user which theme he wants to install + message = "Which theme would you like to apply to your iTerm2 profile?" + color_scheme = ask message, iTerm_available_themes + color_scheme_file = File.join('iTerm2', "#{color_scheme}.itermcolors") + + # Ask the user on which profile he wants to install the theme + profiles = iTerm_profile_list + message = "I've found #{profiles.size} #{profiles.size>1 ? 'profiles': 'profile'} on your iTerm2 configuration, which one would you like to apply the Solarized theme to?" + profiles << 'All' + selected = ask message, profiles + + if selected == 'All' + (profiles.size-1).times { |idx| apply_theme_to_iterm_profile_idx idx, color_scheme_file } + else + apply_theme_to_iterm_profile_idx profiles.index(selected), color_scheme_file + end +end + +def iTerm_available_themes + Dir['iTerm2/*.itermcolors'].map { |value| File.basename(value, '.itermcolors')} +end + +def iTerm_profile_list + profiles=Array.new + begin + profiles << %x{ /usr/libexec/PlistBuddy -c "Print :'New Bookmarks':#{profiles.size}:Name" ~/Library/Preferences/com.googlecode.iterm2.plist 2>/dev/null} + end while $?.exitstatus==0 + profiles.pop + profiles +end + +def ask(message, values) + puts message + while true + values.each_with_index { |val, idx| puts " #{idx+1}. #{val}" } + selection = STDIN.gets.chomp + if (Float(selection)==nil rescue true) || selection.to_i < 0 || selection.to_i > values.size+1 + puts "ERROR: Invalid selection.\n\n" + else + break + end + end + selection = selection.to_i-1 + values[selection] end def install_prezto @@ -256,6 +305,14 @@ def list_vim_submodules Hash[*result.flatten] end +def apply_theme_to_iterm_profile_idx(index, color_scheme_path) + values = Array.new + 16.times { |i| values << "Ansi #{i} Color" } + values << ['Background Color', 'Bold Color', 'Cursor Color', 'Cursor Text Color', 'Foreground Color', 'Selected Text Color', 'Selection Color'] + values.flatten.each { |entry| run %{ /usr/libexec/PlistBuddy -c "Delete :'New Bookmarks':#{index}:'#{entry}'" ~/Library/Preferences/com.googlecode.iterm2.plist } } + + run %{ /usr/libexec/PlistBuddy -c "Merge '#{color_scheme_path}' :'New Bookmarks':#{index}" ~/Library/Preferences/com.googlecode.iterm2.plist } +end def success_msg(action) puts "" From 744b93be5c1ec67c13c67f4d74aa887a9fb6ec51 Mon Sep 17 00:00:00 2001 From: Fabio Gallonetto Date: Sun, 7 Apr 2013 16:38:25 +0100 Subject: [PATCH 2/2] Add solarized theme to console vim --- vim/plugin/settings/yadr-appearance.vim | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/vim/plugin/settings/yadr-appearance.vim b/vim/plugin/settings/yadr-appearance.vim index 4c71ef2..15a00c8 100644 --- a/vim/plugin/settings/yadr-appearance.vim +++ b/vim/plugin/settings/yadr-appearance.vim @@ -1,12 +1,13 @@ " Make it beautiful - colors and fonts + +" http://ethanschoonover.com/solarized/vim-colors-solarized +colorscheme solarized +set background=dark + if has("gui_running") "tell the term has 256 colors set t_Co=256 - " http://ethanschoonover.com/solarized/vim-colors-solarized - colorscheme solarized - set background=dark - " Show tab number (useful for Cmd-1, Cmd-2.. mapping) " For some reason this doesn't work as a regular set command, " (the numbers don't show up) so I made it a VimEnter event