Merge pull request #8840 from vitorgalvao/remove-alfred
Removed alfred command support
This commit is contained in:
commit
0ae2edd707
14
USAGE.md
14
USAGE.md
|
@ -84,7 +84,6 @@ more information.
|
|||
* `doctor` -- checks for configuration issues
|
||||
* `cleanup` -- cleans up cached downloads (with `--outdated`, only cleans old downloads)
|
||||
* `home` -- opens the homepage of the given Cask; or with no arguments, the homebrew-cask project page
|
||||
* `alfred` -- modifies Alfred's search scope to include installed Casks
|
||||
* `update` -- a synonym for `brew update`
|
||||
* `zap` -- try to remove *all* files associated with a Cask (including resources which may be shared with other applications)
|
||||
|
||||
|
@ -250,16 +249,3 @@ The last three forms are intended for users who wish to maintain private Casks.
|
|||
|
||||
You can add Casks to your existing (or new) Taps: just create a directory named
|
||||
`Casks` inside your Tap, put your Cask files there, and everything will just work.
|
||||
|
||||
## Alfred Integration
|
||||
|
||||
Many users combine Homebrew-cask with [Alfred 2](http://www.alfredapp.com/) to great effect. Just add
|
||||
the Cask staging area to Alfred's "search scope" by either
|
||||
|
||||
* running `brew cask alfred link`, or
|
||||
* manually adding `/opt/homebrew-cask/Caskroom` via Alfred's preferences GUI
|
||||
|
||||
Applications will then become available in Alfred immediately after a `brew
|
||||
cask install`. Your fingertips will thank you.
|
||||
|
||||
Oh, and you can `brew cask install alfred` too! Not bad, eh?
|
||||
|
|
|
@ -38,10 +38,6 @@ names, and other aspects of this manual are still subject to change.
|
|||
Check the given Casks for installability.
|
||||
If no tokens are given on the command line, all Casks are audited.
|
||||
|
||||
* `alfred`:
|
||||
Modify Alfred's search scope to include the Caskroom directory where
|
||||
Applications are stored.
|
||||
|
||||
* `cat` <token> [ <token> ... ]:
|
||||
Dump the given Cask definition file to the standard output.
|
||||
|
||||
|
@ -231,8 +227,6 @@ The homebrew-cask home page: <http://caskroom.io>.
|
|||
|
||||
The homebrew-cask GitHub page: <https://github.com/caskroom/homebrew-cask>.
|
||||
|
||||
Alfred.app: <http://www.alfredapp.com>
|
||||
|
||||
`brew`(1), `curl`(1)
|
||||
|
||||
## AUTHORS
|
||||
|
|
|
@ -4,7 +4,6 @@ require 'optparse'
|
|||
require 'shellwords'
|
||||
|
||||
require 'hbc/cli/base'
|
||||
require 'hbc/cli/alfred'
|
||||
require 'hbc/cli/audit'
|
||||
require 'hbc/cli/cat'
|
||||
require 'hbc/cli/cleanup'
|
||||
|
|
|
@ -1,193 +0,0 @@
|
|||
require 'rubygems'
|
||||
|
||||
class Hbc::CLI::Alfred < Hbc::CLI::Base
|
||||
DEFAULT_SCOPES = [
|
||||
'/Applications',
|
||||
'/Applications/Xcode.app/Contents/Applications',
|
||||
'/Developer/Applications',
|
||||
'/Library/PreferencePanes',
|
||||
'/System/Library/CoreServices/Applications',
|
||||
'/System/Library/PreferencePanes',
|
||||
'~/Library/Caches/Metadata/',
|
||||
'~/Library/Mobile Documents/',
|
||||
'~/Library/PreferencePanes'
|
||||
]
|
||||
PRIMARY_DOMAIN = 'com.runningwithcrayons.Alfred-Preferences'
|
||||
PRIMARY_SCOPES_KEY = 'features.defaultresults.scope'
|
||||
|
||||
# http://www.alfredforum.com/topic/4810-alfred%E2%80%99s-scope-can-no-longer-be-changed-programatically/?p=29434
|
||||
LOCALPREFS_SUBPATH = '/Alfred.alfredpreferences/preferences/local/*/features/defaultresults/prefs.plist'
|
||||
LOCALPREFS_SYNCDIR_KEY = 'syncfolder'
|
||||
LOCALPREFS_SCOPES_KEY = 'scope'
|
||||
|
||||
def self.run(*args)
|
||||
subcommand = args.first
|
||||
|
||||
if args.length > 1 && args.last.is_a?(Class)
|
||||
@system_command = args.last
|
||||
else
|
||||
@system_command = Hbc::SystemCommand
|
||||
end
|
||||
|
||||
case subcommand
|
||||
when 'link' then link
|
||||
when 'unlink' then unlink
|
||||
when 'status' then status
|
||||
else
|
||||
usage
|
||||
end
|
||||
end
|
||||
|
||||
def self.help
|
||||
"used to modify Alfred's scope to include the Caskroom"
|
||||
end
|
||||
|
||||
def self.assert_installed
|
||||
unless alfred_2_installed?
|
||||
opoo "Could not find Alfred 2 preferences. Alfred 2 is probably not installed."
|
||||
end
|
||||
if alfred_localprefs? and localprefs_scopes_files.size < 1
|
||||
raise Hbc::CaskError.new "Alfred 2.4+ detected, but local preferences file not found. Try running Alfred first."
|
||||
end
|
||||
alfred_2_installed?
|
||||
end
|
||||
|
||||
def self.link
|
||||
return unless assert_installed
|
||||
|
||||
if linked?
|
||||
opoo "Alfred appears to be already linked. Updating defaults anyway."
|
||||
end
|
||||
odebug 'Linking Alfred scopes'
|
||||
save_alfred_scopes(linked? ? alfred_scopes : alfred_scopes + [ Hbc.caskroom.to_s ])
|
||||
ohai "Successfully linked Alfred to homebrew-cask."
|
||||
end
|
||||
|
||||
def self.unlink
|
||||
return unless assert_installed
|
||||
|
||||
unless linked?
|
||||
opoo "Alfred appears to be already unlinked. Updating defaults anyway."
|
||||
end
|
||||
odebug 'Unlinking Alfred scopes'
|
||||
save_alfred_scopes(alfred_scopes.reject { |x| x == Hbc.caskroom.to_s })
|
||||
ohai "Successfully unlinked Alfred from homebrew-cask."
|
||||
end
|
||||
|
||||
def self.status
|
||||
return unless assert_installed
|
||||
|
||||
if linked?
|
||||
ohai "Alfred is happily linked to homebrew-cask!"
|
||||
else
|
||||
ohai "Alfred is not linked to homebrew-cask."
|
||||
end
|
||||
if alfred_localprefs? and localprefs_scopes_files.size > 1
|
||||
opoo "Multiple local preference files detected. 'brew cask alfred status' may be inaccurate."
|
||||
end
|
||||
end
|
||||
|
||||
def self.save_alfred_scopes(scopes)
|
||||
alfred_preference(PRIMARY_SCOPES_KEY, %Q{(#{scopes.map { |s| "'#{s}'" }.join(',')})})
|
||||
end
|
||||
|
||||
def self.alfred_version
|
||||
begin
|
||||
# reset the version every time when running under the test harness
|
||||
# todo: I don't know the right way to detect that; using const_get
|
||||
Hbc.const_get(:FakeSystemCommand)
|
||||
@alfred_version = nil
|
||||
rescue StandardError => e
|
||||
end
|
||||
return @alfred_version if @alfred_version
|
||||
v = alfred_primary_preference('version')
|
||||
@alfred_version = begin
|
||||
Gem::Version.new(v).to_s.to_f
|
||||
rescue StandardError => e
|
||||
0
|
||||
end
|
||||
end
|
||||
|
||||
def self.alfred_2_installed?
|
||||
alfred_version >= 2.0
|
||||
end
|
||||
|
||||
def self.alfred_localprefs?
|
||||
alfred_version >= 2.4
|
||||
end
|
||||
|
||||
def self.linked?
|
||||
alfred_scopes.include?(Hbc.caskroom.to_s)
|
||||
end
|
||||
|
||||
# output looks like this:
|
||||
# (
|
||||
# "/some/path",
|
||||
# "/other/path"
|
||||
# )
|
||||
#
|
||||
# and we would like %w[/some/path /other/path]
|
||||
SCOPE_REGEXP = /^\s*"(.*)",?$/
|
||||
|
||||
def self.alfred_scopes
|
||||
scopes = alfred_preference(PRIMARY_SCOPES_KEY).split("\n").map do |line|
|
||||
$1 if line.match(SCOPE_REGEXP)
|
||||
end.compact
|
||||
|
||||
scopes.empty? ? DEFAULT_SCOPES : scopes
|
||||
end
|
||||
|
||||
def self.localprefs_scopes_files
|
||||
# local prefs file is used in Alfred 2.4 and above for Yosemite compatibility
|
||||
prefs_path = alfred_primary_preference(LOCALPREFS_SYNCDIR_KEY).strip
|
||||
Pathname.glob(Pathname.new(prefs_path + LOCALPREFS_SUBPATH).expand_path)
|
||||
end
|
||||
|
||||
def self.alfred_preference(key, value=nil)
|
||||
if alfred_localprefs? and key == PRIMARY_SCOPES_KEY
|
||||
alfred_file_preference(localprefs_scopes_files, LOCALPREFS_SCOPES_KEY, value)
|
||||
else
|
||||
alfred_primary_preference(key, value)
|
||||
end
|
||||
end
|
||||
|
||||
def self.alfred_primary_preference(key, value=nil)
|
||||
if value
|
||||
odebug 'Writing Alfred primary preferences'
|
||||
@system_command.run('/usr/bin/defaults', :args => ['write', PRIMARY_DOMAIN, key, value.to_s])
|
||||
else
|
||||
odebug 'Reading Alfred primary preferences'
|
||||
@system_command.run('/usr/bin/defaults', :args => ['read', PRIMARY_DOMAIN, key]).stdout
|
||||
end
|
||||
end
|
||||
|
||||
def self.alfred_file_preference(files, key, value=nil)
|
||||
unless files and files.length > 0
|
||||
raise Hbc::CaskError.new "Required 'files' argument empty"
|
||||
end
|
||||
Array(files).map do |file|
|
||||
if value
|
||||
odebug 'Writing Alfred local preferences'
|
||||
@system_command.run('/usr/bin/defaults', :args => ['write', file, key, value.to_s])
|
||||
else
|
||||
odebug 'Reading Alfred local preferences'
|
||||
@system_command.run('/usr/bin/defaults', :args => ['read', file, key]).stdout
|
||||
end
|
||||
# hack/limitation: if there happen to be multiple local preference
|
||||
# files, we only return the value from the first one.
|
||||
end.first
|
||||
end
|
||||
|
||||
def self.usage
|
||||
ohai 'brew cask alfred', <<-ALFREDHELP.undent
|
||||
manages integration with Alfred; allows applications installed via
|
||||
homebrew-cask to be launched by Alfred, by adding the Caskroom
|
||||
directory to Alfred's search paths
|
||||
|
||||
subcommands:
|
||||
status - reports whether Alfred is linked
|
||||
link - adds Caskroom to alfred search paths
|
||||
unlink - removes Caskroom from Alfred search paths
|
||||
ALFREDHELP
|
||||
end
|
||||
end
|
|
@ -1,159 +0,0 @@
|
|||
require 'test_helper'
|
||||
|
||||
# slightly different format for read/write
|
||||
scope = (Hbc::CLI::Alfred::DEFAULT_SCOPES).map { |s| %Q{"#{s}"} }
|
||||
DEFAULT_READ_SCOPE = %Q{(\n#{scope.join(",\n ")}\n)}
|
||||
scope = (Hbc::CLI::Alfred::DEFAULT_SCOPES + [Hbc.caskroom.to_s]).map { |s| %Q{"#{s}"} }
|
||||
ALTERED_READ_SCOPE = %Q{(\n#{scope.join(",\n ")}\n)}
|
||||
|
||||
scope = (Hbc::CLI::Alfred::DEFAULT_SCOPES).map { |s| %Q{'#{s}'} }
|
||||
DEFAULT_WRITE_SCOPE = %Q{(#{scope.join(',')})}
|
||||
scope = (Hbc::CLI::Alfred::DEFAULT_SCOPES + [Hbc.caskroom.to_s]).map { |s| %Q{'#{s}'} }
|
||||
ALTERED_WRITE_SCOPE = %Q{(#{scope.join(',')})}
|
||||
|
||||
DEFAULT_SYNCDIR = '~/Library/Application Support/Alfred 2'
|
||||
|
||||
def fake_alfred_read_primary_preference(key, response)
|
||||
Hbc::FakeSystemCommand.stubs_command(['/usr/bin/defaults', 'read', 'com.runningwithcrayons.Alfred-Preferences', key], response)
|
||||
end
|
||||
|
||||
def fake_alfred_write_primary_preference(key, value)
|
||||
Hbc::FakeSystemCommand.stubs_command(['/usr/bin/defaults', 'write', 'com.runningwithcrayons.Alfred-Preferences', key, value])
|
||||
end
|
||||
|
||||
def fake_alfred_read_local_preference(key, response)
|
||||
local_files = Pathname.glob(Pathname.new(DEFAULT_SYNCDIR + Hbc::CLI::Alfred::LOCALPREFS_SUBPATH).expand_path)
|
||||
local_files.each do |file|
|
||||
Hbc::FakeSystemCommand.stubs_command(['/usr/bin/defaults', 'read', file, key], response)
|
||||
end
|
||||
end
|
||||
|
||||
def fake_alfred_write_local_preference(key, value)
|
||||
local_files = Pathname.glob(Pathname.new(DEFAULT_SYNCDIR + Hbc::CLI::Alfred::LOCALPREFS_SUBPATH).expand_path)
|
||||
local_files.each do |file|
|
||||
Hbc::FakeSystemCommand.stubs_command(['/usr/bin/defaults', 'write', file, key, value])
|
||||
end
|
||||
end
|
||||
|
||||
def fake_alfred_installed(installed=true)
|
||||
if installed
|
||||
fake_alfred_read_primary_preference 'version', '2.0.3'
|
||||
else
|
||||
fake_alfred_read_primary_preference 'version', <<-VERSION.undent
|
||||
2013-05-11 13:32:51.086 defaults[5072:707]
|
||||
The domain/default pair of (com.runningwithcrayons.Alfred-Preferences, version) does not exist
|
||||
VERSION
|
||||
end
|
||||
end
|
||||
|
||||
describe Hbc::CLI::Alfred do
|
||||
describe "status" do
|
||||
it "properly reports when alfred is not installed" do
|
||||
fake_alfred_installed(false)
|
||||
fake_alfred_read_local_preference('scope', DEFAULT_READ_SCOPE)
|
||||
|
||||
TestHelper.must_output(self, lambda {
|
||||
Hbc::CLI::Alfred.run('status', Hbc::FakeSystemCommand)
|
||||
}, "Warning: Could not find Alfred 2 preferences. Alfred 2 is probably not installed.")
|
||||
end
|
||||
|
||||
it "properly reports when alfred is installed but unlinked" do
|
||||
fake_alfred_installed(true)
|
||||
|
||||
fake_alfred_read_primary_preference 'features.defaultresults.scope', DEFAULT_READ_SCOPE
|
||||
|
||||
TestHelper.must_output(self, lambda {
|
||||
Hbc::CLI::Alfred.run('status', Hbc::FakeSystemCommand)
|
||||
}, "==> Alfred is not linked to homebrew-cask.")
|
||||
end
|
||||
end
|
||||
|
||||
describe "link" do
|
||||
it "properly reports when alfred is not installed" do
|
||||
fake_alfred_installed(false)
|
||||
|
||||
TestHelper.must_output(self, lambda {
|
||||
Hbc::CLI::Alfred.run('link', Hbc::FakeSystemCommand)
|
||||
}, "Warning: Could not find Alfred 2 preferences. Alfred 2 is probably not installed.")
|
||||
end
|
||||
|
||||
it "warns when alfred is already linked" do
|
||||
fake_alfred_installed(true)
|
||||
fake_alfred_read_primary_preference 'features.defaultresults.scope', ALTERED_READ_SCOPE
|
||||
fake_alfred_read_local_preference 'scope', ALTERED_READ_SCOPE
|
||||
fake_alfred_write_primary_preference 'features.defaultresults.scope', ALTERED_WRITE_SCOPE
|
||||
fake_alfred_write_local_preference 'scope', ALTERED_WRITE_SCOPE
|
||||
|
||||
# todo: the message text is out of expected order because of mixing STDERR/STDOUT
|
||||
TestHelper.must_output(self, lambda {
|
||||
Hbc::CLI::Alfred.run('link', Hbc::FakeSystemCommand)
|
||||
}, "==> Successfully linked Alfred to homebrew-cask.\nWarning: Alfred appears to be already linked. Updating defaults anyway.")
|
||||
end
|
||||
|
||||
it "links when it needs to" do
|
||||
fake_alfred_installed(true)
|
||||
fake_alfred_read_primary_preference 'features.defaultresults.scope', DEFAULT_READ_SCOPE
|
||||
fake_alfred_read_local_preference 'scope', DEFAULT_READ_SCOPE
|
||||
fake_alfred_write_primary_preference 'features.defaultresults.scope', ALTERED_WRITE_SCOPE
|
||||
fake_alfred_write_local_preference 'scope', ALTERED_WRITE_SCOPE
|
||||
|
||||
TestHelper.must_output(self, lambda {
|
||||
Hbc::CLI::Alfred.run('link', Hbc::FakeSystemCommand)
|
||||
}, "==> Successfully linked Alfred to homebrew-cask.")
|
||||
end
|
||||
|
||||
it "links with default scopes if the preference hasn't been customized" do
|
||||
fake_alfred_installed(true)
|
||||
fake_alfred_read_primary_preference 'features.defaultresults.scope', <<-SCOPE_RESPONSE.undent
|
||||
2013-05-11 13:32:51.086 defaults[5072:707]
|
||||
The domain/default pair of (com.runningwithcrayons.Alfred-Preferences, features.defaultresults.scope) does not exist
|
||||
SCOPE_RESPONSE
|
||||
fake_alfred_read_local_preference 'scope', <<-SCOPE_RESPONSE.undent
|
||||
2013-05-11 13:32:51.086 defaults[5072:707]
|
||||
The domain/default pair of (<file>, scope) does not exist
|
||||
SCOPE_RESPONSE
|
||||
|
||||
fake_alfred_write_primary_preference 'features.defaultresults.scope', ALTERED_WRITE_SCOPE
|
||||
fake_alfred_write_local_preference 'scope', ALTERED_WRITE_SCOPE
|
||||
|
||||
TestHelper.must_output(self, lambda {
|
||||
Hbc::CLI::Alfred.run('link', Hbc::FakeSystemCommand)
|
||||
}, "==> Successfully linked Alfred to homebrew-cask.")
|
||||
end
|
||||
end
|
||||
|
||||
describe "unlink" do
|
||||
it "properly reports when alfred is not installed" do
|
||||
fake_alfred_installed(false)
|
||||
|
||||
TestHelper.must_output(self, lambda {
|
||||
Hbc::CLI::Alfred.run('unlink', Hbc::FakeSystemCommand)
|
||||
}, "Warning: Could not find Alfred 2 preferences. Alfred 2 is probably not installed.")
|
||||
end
|
||||
|
||||
it "warns when alfred is already unlinked" do
|
||||
fake_alfred_installed(true)
|
||||
fake_alfred_read_primary_preference 'features.defaultresults.scope', DEFAULT_READ_SCOPE
|
||||
fake_alfred_read_local_preference 'scope', DEFAULT_READ_SCOPE
|
||||
fake_alfred_write_primary_preference 'features.defaultresults.scope', DEFAULT_WRITE_SCOPE
|
||||
fake_alfred_write_local_preference 'scope', DEFAULT_WRITE_SCOPE
|
||||
|
||||
# todo: the message text is out of expected order because of mixing STDERR/STDOUT
|
||||
TestHelper.must_output(self, lambda {
|
||||
Hbc::CLI::Alfred.run('unlink', Hbc::FakeSystemCommand)
|
||||
}, "==> Successfully unlinked Alfred from homebrew-cask.\nWarning: Alfred appears to be already unlinked. Updating defaults anyway.")
|
||||
end
|
||||
|
||||
it "unlinks when it needs to" do
|
||||
fake_alfred_installed(true)
|
||||
fake_alfred_read_primary_preference 'features.defaultresults.scope', ALTERED_READ_SCOPE
|
||||
fake_alfred_read_local_preference 'scope', ALTERED_READ_SCOPE
|
||||
fake_alfred_write_primary_preference 'features.defaultresults.scope', DEFAULT_WRITE_SCOPE
|
||||
fake_alfred_write_local_preference 'scope', DEFAULT_WRITE_SCOPE
|
||||
|
||||
TestHelper.must_output(self, lambda {
|
||||
Hbc::CLI::Alfred.run('unlink', Hbc::FakeSystemCommand)
|
||||
}, "==> Successfully unlinked Alfred from homebrew-cask.")
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue