Skip to content
This repository has been archived by the owner on Mar 1, 2024. It is now read-only.

Add custom color palettes to iterm plist #172

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions sprout-osx-apps/attributes/iterm2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,15 @@
default['sprout']['iterm2']['dmg']['checksum'] = '2afad022b1e1f08b3ed40f0c2bde7bf7cce003852c83f85948c7f57a5578d9c5'

default['sprout']['iterm2']['app']['path'] = "/Applications/iTerm.app"
default['sprout']['iterm2']['color']['custom_urls'] = [
'https://raw.github.com/altercation/solarized/master/iterm2-colors-solarized/Solarized%20Dark.itermcolors',
'https://raw.github.com/altercation/solarized/master/iterm2-colors-solarized/Solarized%20Light.itermcolors',
'https://raw.github.com/baskerville/iTerm-2-Color-Themes/master/arthur.itermcolors',
'https://raw.github.com/baskerville/iTerm-2-Color-Themes/master/n0tch2k.itermcolors',
'https://raw.github.com/baskerville/iTerm-2-Color-Themes/master/pnevma.itermcolors',
'https://raw.github.com/baskerville/iTerm-2-Color-Themes/master/square.itermcolors',
'https://raw.github.com/baskerville/iTerm-2-Color-Themes/master/thayer.itermcolors',
'https://raw.github.com/baskerville/iTerm-2-Color-Themes/master/wryan.itermcolors',
'https://raw.github.com/baskerville/iTerm-2-Color-Themes/master/zenburn.itermcolors'
]
default['sprout']['iterm2']['color']['default'] = 'Solarized Dark'
38 changes: 34 additions & 4 deletions sprout-osx-apps/recipes/iterm2.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,35 @@
require 'net/http'
require 'uri'

app_properties = node['sprout']['iterm2']['app']
dmg_properties = node['sprout']['iterm2']['dmg']

unless File.exists?(app_properties['path'])
def fetch_http_url(url)
uri = URI.parse(url)
http = Net::HTTP.new(uri.host, uri.port)
if uri.scheme == 'https'
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
end

response = http.request(Net::HTTP::Get.new(uri.path))
response.body
end

def get_color_schemes
color_schemes = {}
node['sprout']['iterm2']['color']['custom_urls'].each do |url|
filename = URI.decode(URI(url).path.split('/').last)
scheme_name = File.basename(filename, '.itermcolors')
scheme_xml = Plist::parse_xml(fetch_http_url(url))
color_schemes[scheme_name] = Plist::Emit.dump(scheme_xml, false)
end
color_schemes
end

gem_package("plist")

unless File.exists?(app_properties['path'])
remote_file "#{Chef::Config[:file_cache_path]}/iTerm2.zip" do
source dmg_properties['source']
checksum dmg_properties['checksum']
Expand All @@ -20,10 +47,13 @@
group "admin"
end

cookbook_file "/Users/#{node['current_user']}/Library/Preferences/com.googlecode.iterm2.plist" do
source "com.googlecode.iterm2.plist"
color_schemes = get_color_schemes
template "/Users/#{node['current_user']}/Library/Preferences/com.googlecode.iterm2.plist" do
source "com.googlecode.iterm2.plist.erb"
user node['current_user']
mode "0600"
variables({
:color_schemes => color_schemes
})
end

end
Loading