Merge pull request #290 from skwp/iterm2_solarized_autoinstall

Add autoinstall of Solarized iTerm2 themes
This commit is contained in:
Yan Pritzker 2013-04-08 07:31:48 -07:00
commit 6f17f40640
2 changed files with 67 additions and 9 deletions

View File

@ -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 "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 } run %{ /usr/libexec/PlistBuddy -c "Merge 'iTerm2/Solarized Dark.itermcolors' :'Custom Color Presets':'Solarized Dark'" ~/Library/Preferences/com.googlecode.iterm2.plist }
puts "======================================================" # If iTerm2 is not installed or has never run, we can't autoinstall the profile since the plist is not there
puts "To make sure your profile is using the solarized theme" if !File.exists?(File.join(ENV['HOME'], '/Library/Preferences/com.googlecode.iterm2.plist'))
puts "Please check your settings under:" puts "======================================================"
puts "Preferences> Profiles> [your profile]> Colors> Load Preset.." puts "To make sure your profile is using the solarized theme"
puts "======================================================" 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 end
def install_prezto def install_prezto
@ -256,6 +305,14 @@ def list_vim_submodules
Hash[*result.flatten] Hash[*result.flatten]
end 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) def success_msg(action)
puts "" puts ""

View File

@ -1,12 +1,13 @@
" Make it beautiful - colors and fonts " Make it beautiful - colors and fonts
" http://ethanschoonover.com/solarized/vim-colors-solarized
colorscheme solarized
set background=dark
if has("gui_running") if has("gui_running")
"tell the term has 256 colors "tell the term has 256 colors
set t_Co=256 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) " Show tab number (useful for Cmd-1, Cmd-2.. mapping)
" For some reason this doesn't work as a regular set command, " 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 " (the numbers don't show up) so I made it a VimEnter event