omnibar 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,17 +3,29 @@ module Omnibar
3
3
  def result
4
4
  repo = search.find(input)
5
5
  return repo if repo
6
- return input if input.match?(/^[\w-]+\/[\w-]+$/)
6
+ return input if repo_full_name?
7
7
  end
8
8
 
9
- def search
10
- @fm = FuzzyMatch.new(Omnibar.config.github.repos)
9
+ def self.search
10
+ @fm ||= FuzzyMatch.new(Omnibar.config.github.repos)
11
11
  end
12
12
 
13
13
  def perform!
14
14
  param = result.downcase.gsub(/\s/, '-')
15
15
  open_in_browser "https://github.com/#{param}"
16
16
  end
17
+
18
+ def relevance
19
+ if repo_full_name?
20
+ 0.75
21
+ elsif result
22
+ input.levenshtein_similar(result)
23
+ end
24
+ end
25
+
26
+ def repo_full_name?
27
+ input.match?(/^[\w-]+\/[\w-]+$/)
28
+ end
17
29
  end
18
30
  end
19
31
 
@@ -1,5 +1,17 @@
1
1
  module Omnibar
2
2
  class Google < Query
3
+ def label
4
+ [
5
+ ANSI.color('G', res: false, fg: :blue),
6
+ ANSI.color('o', res: false, fg: :red),
7
+ ANSI.color('o', res: false, fg: :yellow),
8
+ ANSI.color('g', res: false, fg: :blue),
9
+ ANSI.color('l', res: false, fg: :green),
10
+ ANSI.color('e', res: false, fg: :red),
11
+ ANSI.reset
12
+ ].join
13
+ end
14
+
3
15
  def perform!
4
16
  param = input.gsub(/\s/, '+')
5
17
  open_in_browser "https://www.google.com/search?q=#{param}"
@@ -4,10 +4,14 @@ module Omnibar
4
4
  search.find(input)
5
5
  end
6
6
 
7
- def search
7
+ def self.search
8
8
  @fm ||= FuzzyMatch.new(Omnibar.config.popular.sites)
9
9
  end
10
10
 
11
+ def relevance
12
+ input.levenshtein_similar(result) if result
13
+ end
14
+
11
15
  def perform!
12
16
  return if input.match?(/^fac?e?b?o?o?k?/)
13
17
  open_in_browser "https://#{result}"
@@ -1,7 +1,6 @@
1
1
  module Omnibar
2
2
  class Snippet < Query
3
3
  def result
4
- key = search.find(input)
5
4
  value = snippets[key]
6
5
  "#{key} :: #{value}" if (key and value)
7
6
  end
@@ -10,12 +9,16 @@ module Omnibar
10
9
  Omnibar.config.snippets
11
10
  end
12
11
 
13
- def self.search
14
- @fz ||= FuzzyMatch.new(Omnibar.config.snippets.keys)
12
+ def key
13
+ search.find(input)
15
14
  end
16
15
 
17
- def search
18
- self.class.search
16
+ def relevance
17
+ input.levenshtein_similar(key) if result
18
+ end
19
+
20
+ def self.search
21
+ @fz ||= FuzzyMatch.new(Omnibar.config.snippets.keys)
19
22
  end
20
23
 
21
24
  def perform!
@@ -3,7 +3,11 @@ require 'ffi/aspell'
3
3
  module Omnibar
4
4
  class Spell < Query
5
5
  def result
6
- speller.suggestions(input.split(' ').last).first if input.match?(/^spe?l?l? \w+/)
6
+ return unless using_keyword?
7
+
8
+ words = input.split(' ')
9
+ return ' ' if words.length == 1
10
+ speller.suggestions(words.last).first
7
11
  end
8
12
 
9
13
  def self.speller
@@ -17,5 +21,14 @@ module Omnibar
17
21
  def perform!
18
22
  copy_to_clipboard result
19
23
  end
24
+
25
+ def using_keyword?
26
+ input.match?(/^spe?l?l?/)
27
+ end
28
+
29
+ def relevance
30
+ return 1 if using_keyword?
31
+ 0
32
+ end
20
33
  end
21
34
  end
@@ -16,12 +16,16 @@ module Omnibar
16
16
  search.find(input)
17
17
  end
18
18
 
19
+ def relevance
20
+ input.levenshtein_similar(result) if result
21
+ end
22
+
19
23
  def search
20
24
  @fz ||= FuzzyMatch.new(COMMANDS.keys)
21
25
  end
22
26
 
23
27
  def perform!
24
- puts COMMANDS[result]
28
+ run_silently COMMANDS[result]
25
29
  end
26
30
  end
27
31
  end
@@ -3,26 +3,38 @@ module Omnibar
3
3
  attr_reader :input
4
4
 
5
5
  def initialize(input)
6
- @input = input.strip
6
+ @input = input
7
7
  end
8
8
 
9
9
  def self.inherited(subclass)
10
10
  Omnibar.config.queries.push(subclass)
11
11
  super(subclass)
12
+ subclass.prepend(MethodAugmentations)
12
13
  end
13
14
 
14
15
  # TODO: Convert result to class
15
16
  # TODO: Allow multiple results per query
16
17
  def preview_text
17
18
  res = result
18
- name = self.class.name.split('::').last.gsub(/[A-Z]/) { |w| ' ' << w }.strip
19
- [name, res.strip] unless res.nil? || res.empty?
19
+ [label, res.strip] unless res.nil? || res.empty?
20
20
  end
21
21
 
22
22
  def result
23
23
  input
24
24
  end
25
25
 
26
+ def label
27
+ self.class.name.split('::').last.gsub(/[A-Z]/) { |w| ' ' << w }.strip
28
+ end
29
+
30
+ def search
31
+ self.class.search
32
+ end
33
+
34
+ def relevance
35
+ 0
36
+ end
37
+
26
38
  def perform!; end
27
39
 
28
40
  def copy_to_clipboard(value)
@@ -34,7 +46,21 @@ module Omnibar
34
46
  end
35
47
 
36
48
  def run_silently(*command)
37
- `#{command.join(' ')} >/dev/null 2>&1`
49
+ `#{command.join(' ')} >/dev/null 2>&1 &`
50
+ end
51
+
52
+ module MethodAugmentations
53
+ def result
54
+ return if input == ''
55
+ super
56
+ end
57
+
58
+ def relevance
59
+ value = super
60
+ value = 1 if value == true
61
+ value = 0.01 unless value
62
+ value
63
+ end
38
64
  end
39
65
  end
40
66
  end
@@ -23,7 +23,6 @@ module Omnibar
23
23
  print current[i]
24
24
  end
25
25
 
26
- ANSI
27
26
  print current.cursor_position
28
27
  end
29
28
  end
@@ -34,7 +34,7 @@ module Omnibar
34
34
  end
35
35
 
36
36
  def queries
37
- Omnibar.config.queries.map { |q| q.new(input) }
37
+ Omnibar.config.queries.map { |q| q.new(input) }.sort_by(&:relevance).reverse
38
38
  end
39
39
 
40
40
  def visible_queries
@@ -42,7 +42,7 @@ module Omnibar
42
42
  end
43
43
 
44
44
  def current_query
45
- visible_queries[selection] || Query.new
45
+ visible_queries[selection] || Query.new('')
46
46
  end
47
47
 
48
48
  # TODO: Sort results based on relevance / certainty
@@ -1,3 +1,3 @@
1
1
  module Omnibar
2
- VERSION = '0.0.6'.freeze
2
+ VERSION = '0.0.7'.freeze
3
3
  end
@@ -36,30 +36,34 @@ module Omnibar
36
36
  text = [
37
37
  lpad(result.first, max_label_length),
38
38
  rpad(result.last, ANSI.size[:width] - max_label_length - 2)
39
- ].join(': ')
39
+ ]
40
40
 
41
41
  if i == @state.selection
42
- text = ANSI.color(text,
43
- fg: Omnibar.config.render.highlight.fg,
44
- bg: Omnibar.config.render.highlight.bg)
42
+ text.map { |t| highlight(t) }.join(highlight(': '))
43
+ else
44
+ text.join(': ')
45
45
  end
46
-
47
- text
48
46
  end
49
47
  end
50
48
 
49
+ def highlight(text)
50
+ ANSI.color(text,
51
+ fg: Omnibar.config.render.highlight.fg,
52
+ bg: Omnibar.config.render.highlight.bg)
53
+ end
54
+
51
55
  def rpad(text, length = ANSI.size[:width])
52
- textlength = text.length + non_ascii_chars(text).length
56
+ textlength = ANSI.strip(text).length + non_ascii_chars(text).length
53
57
  text + (' ' * [0, (length - textlength)].max)
54
58
  end
55
59
 
56
60
  def lpad(text, length = ANSI.size[:width])
57
- textlength = text.length + non_ascii_chars(text).length
61
+ textlength = ANSI.strip(text).length + non_ascii_chars(text).length
58
62
  (' ' * [0, (length - textlength)].max) + text
59
63
  end
60
64
 
61
65
  def max_label_length
62
- @mll ||= (@state.results.map(&:first).map(&:length).max || 0) + 1
66
+ @mll ||= (@state.results.map(&:first).map { |s| ANSI.strip(s) }.map(&:length).max || 0) + 1
63
67
  end
64
68
 
65
69
  def non_ascii_chars(string)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omnibar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jacob Evan Shreve
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-11-06 00:00:00.000000000 Z
11
+ date: 2017-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-configurable
@@ -122,11 +122,13 @@ files:
122
122
  - Rakefile
123
123
  - bin/console
124
124
  - bin/setup
125
+ - db/ansi.json
125
126
  - exe/omnibar
126
127
  - lib/ansi.rb
127
128
  - lib/omnibar.rb
128
129
  - lib/omnibar/app.rb
129
130
  - lib/omnibar/queries/calculate.rb
131
+ - lib/omnibar/queries/docs.rb
130
132
  - lib/omnibar/queries/duck_duck_go.rb
131
133
  - lib/omnibar/queries/emoji.rb
132
134
  - lib/omnibar/queries/github.rb