-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathiterm2-control.rb
More file actions
32 lines (27 loc) · 1.05 KB
/
iterm2-control.rb
File metadata and controls
32 lines (27 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
require 'rubygems' unless defined? Gem
require './bundle/bundler/setup'
require "cfpropertylist"
require "./alfred-helper"
def console_log(msg)
escape = proc{ |m| m.gsub("'", "'\\\\''") }
`logger -t 'Alfred Workflow' '#{escape[msg]}'`
end
# Get the arguments from {query}
args = ARGV.join(" ")
# Get a list of all the settings configured for the Terminal, by name
plist = CFPropertyList::List.new(:file => File.expand_path("~/Library/Preferences/com.googlecode.iTerm2.plist"))
data = CFPropertyList.native_types(plist.value)
term_settings = data["New Bookmarks"].map { |bmark| bmark["Name"] }
# Now search for matching items to the query
filtered_settings = term_settings.select do |setting_name|
setting_name.match(/#{args}/i)
end
workflow = Alfred::Workflow.new
filtered_settings.each do |setting|
display_setting = setting
if(match = setting.match(/(.*) \(Default\)/))
setting = match[1]
end
workflow << Alfred::Item.new(:arg => setting, :title => display_setting, :subtitle => "Open '#{setting}' iTerm2", :icon_path => "icon.png")
end
workflow.output!