Class: Q::Glob

Inherits:
Command show all
Defined in:
lib/q/commands/glob.rb

Instance Attribute Summary

Attributes inherited from Command

#registered_shortcuts

Instance Method Summary collapse

Methods inherited from Command

#usage

Constructor Details

#initialize(patterns, usage) ⇒ Glob

Returns a new instance of Glob.



3
4
5
6
# File 'lib/q/commands/glob.rb', line 3

def initialize(patterns, usage)
	@patterns = patterns
	super(usage)
end

Instance Method Details

#execute(shortcut, terms) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/q/commands/glob.rb', line 8

def execute(shortcut, terms)
	matches = []
	@patterns.each do |pattern|
		matches = Dir.glob(interpolate_pattern(pattern, [shortcut.to_s] + terms))
		unless matches.empty?
			%x{open -a Safari "#{matches.first}"}
			break
		end
	end
	matches.first
end

#help(shortcut, terms) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/q/commands/glob.rb', line 20

def help(shortcut, terms)
	short = usage
	if terms.include?("-v") or terms.include?("--verbose")
		long = $/ + @patterns.join($/) + $/ + $/ + "(%{0}, %{1}, ... are replaced with the shortcut and terms)"
		short + $/ + long
	else
		short + $/ + "(use `q help #{shortcut} --verbose` or `q help #{shortcut} -v` for the relevant patterns)"
	end
end