From bdd1d36470e7969a1d5a0e38ac56145e25ba11ce Mon Sep 17 00:00:00 2001 From: "Davis W. Frank" Date: Thu, 19 Jul 2018 18:00:03 -0700 Subject: [PATCH] Moved capi link indexing to Ruby; fixed installation order --- .ruby-version | 1 + Gemfile | 5 +++ Gemfile.lock | 17 +++++++++ install.sh | 10 +++--- setup-capi-land-links | 77 ++++++++++++++++++++++++++++++++++++++++ setup-capi-land-links.sh | 19 ---------- 6 files changed, 106 insertions(+), 23 deletions(-) create mode 100644 .ruby-version create mode 100644 Gemfile create mode 100644 Gemfile.lock create mode 100755 setup-capi-land-links delete mode 100755 setup-capi-land-links.sh diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000..8e8299d --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +2.4.2 diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..f840684 --- /dev/null +++ b/Gemfile @@ -0,0 +1,5 @@ +source 'https://rubygems.org' + +gem 'plist' +gem 'rainbow' +gem 'thor' diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..ce99f3a --- /dev/null +++ b/Gemfile.lock @@ -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 diff --git a/install.sh b/install.sh index 0547906..4e0463b 100755 --- a/install.sh +++ b/install.sh @@ -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/ diff --git a/setup-capi-land-links b/setup-capi-land-links new file mode 100755 index 0000000..2084b7b --- /dev/null +++ b/setup-capi-land-links @@ -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"'` diff --git a/setup-capi-land-links.sh b/setup-capi-land-links.sh deleted file mode 100755 index f7b9c1c..0000000 --- a/setup-capi-land-links.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash - -declare -a capi_links=("board" -"chris" -"greg" -"mike" -"tim" -"video") - -# open each link in Safari do it's Spotlight-indexed -echo "Indexing the following links in Safari:" -for link in "${capi_links[@]}" -do - echo "${link}.capi.land" - open -a safari http://$link.capi.land -done - -# close Safari -osascript -e 'quit app "Safari"'