Skip to content

Commit

Permalink
Moved capi link indexing to Ruby; fixed installation order
Browse files Browse the repository at this point in the history
  • Loading branch information
Davis W. Frank authored and pivotal committed Jul 24, 2018
1 parent 4c39a61 commit bdd1d36
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 23 deletions.
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.4.2
5 changes: 5 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
source 'https://rubygems.org'

gem 'plist'
gem 'rainbow'
gem 'thor'
17 changes: 17 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
GEM
remote: https://rubygems.org/
specs:
plist (3.4.0)
rainbow (3.0.0)
thor (0.20.0)

PLATFORMS
ruby

DEPENDENCIES
plist
rainbow
thor

BUNDLED WITH
1.16.2
10 changes: 6 additions & 4 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,15 @@ source ./setup-misc.sh

# Instal CLI cf-httpie plugin
source ./setup-httpie.sh
}

# Add gem dependencies for CAPI-Workspace
source ./setup-gems.sh

# Index capi.land links in Spotlight
source ./setup-capi-land-links.sh
./setup-capi-land-links
}


# Add some gems for the CAPI command
source ./setup-gems.sh

function open_picklecat() {
open http://dn.ht/picklecat/
Expand Down
77 changes: 77 additions & 0 deletions setup-capi-land-links
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/usr/bin/env ruby

require 'plist'

class Bookmarks
def initialize(path)
@path = path
@plist_hash = Plist.parse_xml(`plutil -convert xml1 -o - #{@path}`)
end

def folder_names
@plist_hash['Children'].collect {|b| b['Title']}
end

def reset_capi_folder
@capi_folder_index = if folder_names.include? 'CAPI'
capi_folder_index = folder_names.find_index {|f| f == 'CAPI'}
capi_folder = @plist_hash['Children'][capi_folder_index]
capi_folder['Children'] = []
capi_folder_index
else
@plist_hash['Children'].push(
{ 'Title' => 'CAPI',
'WebBookmarkType' => 'WebBookmarkTypeList',
'Children' => []
})
@plist_hash['Children'].count - 1
end
end

def insert_links_into_capi_folder(new_links)
capi_folder = @plist_hash['Children'][@capi_folder_index]
capi_folder_links = capi_folder['Children']

new_links.each do |name, url|
capi_folder_links.push(bookmark_hash_for(name, url))
end
end

def write_file
File.open(@path, 'w') {|f| f.write @plist_hash.to_plist}
end

private

def bookmark_hash_for(name, url)
{'ReadingListNonSync' =>
{'neverFetchMetadata' => false},
'URIDictionary' =>
{'title' => name},
'URLString' => url,
'WebBookmarkType' => 'WebBookmarkTypeLeaf',
'previewText' => '',
'previewTextIsUserDefined' => true}
end
end

bookmarks = Bookmarks.new(File.join('/Users', 'pivotal', 'Library', 'Safari', 'Bookmarks.plist'))
bookmarks.reset_capi_folder
bookmarks.insert_links_into_capi_folder(
{
'CAPI Trello' => 'http://board.capi.land',
'Chris' => 'http://chris.capi.land',
'CI' => 'https://ci.capi.land',
'Elena' =>'http://elena.capi.land',
'Greg' => 'http://greg.capi.land',
'Mike' => 'http://mike.capi.land',
'Tim' => 'http://tim.capi.land',
'Video' =>'http://video.capi.land'
}
)
bookmarks.write_file

# Open Safari to re-read new links, then close
`open -a "Safari"`
sleep 2
`osascript -e 'quit app "Safari"'`
19 changes: 0 additions & 19 deletions setup-capi-land-links.sh

This file was deleted.

0 comments on commit bdd1d36

Please sign in to comment.