omnibar 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +20 -0
- data/LICENSE.txt +21 -0
- data/README.md +28 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/omnibar +5 -0
- data/lib/omnibar.rb +11 -0
- data/lib/omnibar/ansi.rb +37 -0
- data/lib/omnibar/app.rb +84 -0
- data/lib/omnibar/calculate.rb +28 -0
- data/lib/omnibar/duck_duck_go.rb +8 -0
- data/lib/omnibar/github.rb +30 -0
- data/lib/omnibar/google.rb +8 -0
- data/lib/omnibar/popular.rb +21 -0
- data/lib/omnibar/query.rb +29 -0
- data/lib/omnibar/renderer.rb +44 -0
- data/lib/omnibar/version.rb +3 -0
- data/omnibar.gemspec +26 -0
- metadata +94 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b92696d806fad27d9518b1935f98a12d1ca8ceaa
|
4
|
+
data.tar.gz: e412de9c590de961ddf2b01b7f2f309c53e25dde
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 070515ddb8fb591a206a2c8c4fc00b368214131c3d8731a8fd4a208f4c3abd093f53a1329ab0c3911ca540e5dece082ec8837d4a9d8c8a6aa5b8115cdaa6d6ee
|
7
|
+
data.tar.gz: ba2cab69ca8b67c3a95764634081af03c6aa38ff79e5cef0dbb064dda276ea6ef2315274110f61d7f418d4cdb2c4dfc6d3dc6815216169fc01df4eeb53ce6e98
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Jacob Evan Shreve
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# Omnibar
|
2
|
+
|
3
|
+
Omnibar is a tool for quick access to multiple scripts and searches.
|
4
|
+
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Install as:
|
9
|
+
|
10
|
+
$ gem install omnibar
|
11
|
+
|
12
|
+
## Usage
|
13
|
+
|
14
|
+
Run `bin/omnibar` and start typing. Use the arrow keys to select the result you like, and press enter to go!
|
15
|
+
|
16
|
+
## Development
|
17
|
+
|
18
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
19
|
+
|
20
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
21
|
+
|
22
|
+
## Contributing
|
23
|
+
|
24
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/shreve/omnibar.
|
25
|
+
|
26
|
+
## License
|
27
|
+
|
28
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "omnibar"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/exe/omnibar
ADDED
data/lib/omnibar.rb
ADDED
data/lib/omnibar/ansi.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
module Omnibar
|
2
|
+
# This module contains helpers for various ansi-code operations
|
3
|
+
module ANSI
|
4
|
+
# ANSI color escape codes set the foreground and background colors.
|
5
|
+
# Forground color is a number between 30 and 37.
|
6
|
+
# Background color is a number between 40 and 47.
|
7
|
+
# The ones place represents the same color for both.
|
8
|
+
COLORS = [:black, :red, :green, :yellow, :blue, :magenta, :cyan, 'white', nil, :white].freeze
|
9
|
+
|
10
|
+
def self.clear_screen
|
11
|
+
$stdout.write "\e[2J"
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.move_cursor(row, col)
|
15
|
+
$stdout.write "\e[#{row + 1};#{col + 1}H"
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.color(text, fg: :white, bg: :black)
|
19
|
+
fg = COLORS.index(fg) + 30
|
20
|
+
bg = COLORS.index(bg) + 40
|
21
|
+
code = "\e[#{[fg, bg].compact.join(';')}m"
|
22
|
+
"#{code}#{text}\e[0m"
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.reset
|
26
|
+
"\e[0m"
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.size
|
30
|
+
win = IO.console.winsize
|
31
|
+
{
|
32
|
+
height: win[0],
|
33
|
+
width: win[1]
|
34
|
+
}
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/omnibar/app.rb
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'io/console'
|
4
|
+
|
5
|
+
require_relative 'ansi'
|
6
|
+
require_relative 'query'
|
7
|
+
require_relative 'renderer'
|
8
|
+
|
9
|
+
module Omnibar
|
10
|
+
class App
|
11
|
+
attr_accessor :input
|
12
|
+
attr_accessor :selection
|
13
|
+
|
14
|
+
@@queries = []
|
15
|
+
|
16
|
+
def self.add_query(query)
|
17
|
+
@@queries.push(query)
|
18
|
+
end
|
19
|
+
|
20
|
+
def initialize
|
21
|
+
@input = ''
|
22
|
+
@selection = 0
|
23
|
+
end
|
24
|
+
|
25
|
+
def run
|
26
|
+
IO.console.raw do
|
27
|
+
ANSI.clear_screen
|
28
|
+
ANSI.move_cursor(0, 0)
|
29
|
+
loop do
|
30
|
+
render
|
31
|
+
handle_input
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def render
|
37
|
+
Renderer.new(input, results, selection).render!
|
38
|
+
end
|
39
|
+
|
40
|
+
def handle_input(prefix = '')
|
41
|
+
char = prefix << $stdin.getc
|
42
|
+
case char
|
43
|
+
when "\u0003" # ctrl-c
|
44
|
+
quit
|
45
|
+
when "\u007F" # backspace
|
46
|
+
self.input = input[0..-2]
|
47
|
+
when "\e", "\e["
|
48
|
+
handle_input(char)
|
49
|
+
when "\e[A"
|
50
|
+
self.selection = [selection - 1, 0].max
|
51
|
+
when "\e[B"
|
52
|
+
self.selection = [selection + 1, visible_queries.count - 1].min
|
53
|
+
when "\r"
|
54
|
+
perform_action!
|
55
|
+
else
|
56
|
+
input << char
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def results
|
61
|
+
return [] if input.empty?
|
62
|
+
|
63
|
+
queries.map(&:preview_text).compact
|
64
|
+
end
|
65
|
+
|
66
|
+
def perform_action!
|
67
|
+
visible_queries[selection]&.perform!
|
68
|
+
self.input = ""
|
69
|
+
end
|
70
|
+
|
71
|
+
def queries
|
72
|
+
@@queries.map { |q| q.new(input) }
|
73
|
+
end
|
74
|
+
|
75
|
+
def visible_queries
|
76
|
+
queries.reject { |q| q.preview_text.nil? }
|
77
|
+
end
|
78
|
+
|
79
|
+
def quit
|
80
|
+
ANSI.clear_screen
|
81
|
+
exit 0
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Omnibar
|
2
|
+
class Calculate < Query
|
3
|
+
include Math
|
4
|
+
|
5
|
+
def result
|
6
|
+
begin
|
7
|
+
[input, value].join(' = ')
|
8
|
+
rescue Exception => _e
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def value
|
13
|
+
eval(input + '.to_f')
|
14
|
+
end
|
15
|
+
|
16
|
+
def perform!
|
17
|
+
`echo #{value} | xsel -i --clipboard`
|
18
|
+
end
|
19
|
+
|
20
|
+
def pi
|
21
|
+
PI
|
22
|
+
end
|
23
|
+
|
24
|
+
def e
|
25
|
+
E
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
class String
|
2
|
+
def &(other)
|
3
|
+
self == other[0...length]
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
7
|
+
module Omnibar
|
8
|
+
class Github < Query
|
9
|
+
def repos
|
10
|
+
%w(
|
11
|
+
wellopp/dashboard
|
12
|
+
wellopp/dispatch
|
13
|
+
wellopp/magic-docs
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
17
|
+
def result
|
18
|
+
repos.each do |repo|
|
19
|
+
user, name = repo.split('/')
|
20
|
+
return repo if (input & repo or input & user or input & name)
|
21
|
+
end
|
22
|
+
nil
|
23
|
+
end
|
24
|
+
|
25
|
+
def perform!
|
26
|
+
param = result.downcase.gsub(/\s/, '-')
|
27
|
+
open_in_browser "https://github.com/#{param}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Omnibar
|
2
|
+
class Popular < Query
|
3
|
+
def result
|
4
|
+
case input
|
5
|
+
when /^news/
|
6
|
+
'news.ycombinator.com'
|
7
|
+
when /^redd?i?t?/
|
8
|
+
'reddit.com'
|
9
|
+
when /^fac?e?b?o?o?k?/
|
10
|
+
"[facebook] you're bad and you should feel bad"
|
11
|
+
when /^twit?t?e?r?/
|
12
|
+
'twitter.com'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def perform!
|
17
|
+
return if input.match?(/^fac?e?b?o?o?k?/)
|
18
|
+
open_in_browser "https://#{result}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Omnibar
|
2
|
+
class Query
|
3
|
+
|
4
|
+
attr_reader :input
|
5
|
+
|
6
|
+
def initialize(input)
|
7
|
+
@input = input
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.inherited(subclass)
|
11
|
+
Omnibar::App.add_query(subclass)
|
12
|
+
super(subclass)
|
13
|
+
end
|
14
|
+
|
15
|
+
def preview_text
|
16
|
+
res = result
|
17
|
+
name = self.class.name.split('::').last
|
18
|
+
[name, res] unless result.nil? || result.empty?
|
19
|
+
end
|
20
|
+
|
21
|
+
def result
|
22
|
+
input
|
23
|
+
end
|
24
|
+
|
25
|
+
def open_in_browser(url)
|
26
|
+
Thread.new { `xdg-open "#{url}" >/dev/null 2>&1` }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Omnibar
|
2
|
+
class Renderer
|
3
|
+
attr_reader :input, :results, :selection
|
4
|
+
|
5
|
+
def initialize(input, results, selection)
|
6
|
+
@input = input
|
7
|
+
@results = results
|
8
|
+
@selection = selection
|
9
|
+
end
|
10
|
+
|
11
|
+
def render!
|
12
|
+
ANSI.clear_screen
|
13
|
+
ANSI.move_cursor(0, 0)
|
14
|
+
puts input_line
|
15
|
+
ANSI.move_cursor(1, 0)
|
16
|
+
results.each.with_index do |result, i|
|
17
|
+
text = [
|
18
|
+
lpad(result.first, max_label_length),
|
19
|
+
rpad(result.last, ANSI.size[:width] - max_label_length - 2)
|
20
|
+
].join(': ')
|
21
|
+
|
22
|
+
text = ANSI.color(text, fg: :black, bg: :yellow) if i == selection
|
23
|
+
print "#{text}\r\n"
|
24
|
+
end
|
25
|
+
ANSI.move_cursor(0, input_line.length)
|
26
|
+
end
|
27
|
+
|
28
|
+
def input_line
|
29
|
+
('-' * max_label_length) << '> ' << input
|
30
|
+
end
|
31
|
+
|
32
|
+
def rpad(text, length = ANSI.size[:width])
|
33
|
+
text + (' ' * (length - text.length))
|
34
|
+
end
|
35
|
+
|
36
|
+
def lpad(text, length = ANSI.size[:width])
|
37
|
+
(' ' * (length - text.length)) + text
|
38
|
+
end
|
39
|
+
|
40
|
+
def max_label_length
|
41
|
+
@mll ||= results.map(&:first).map(&:length).max || 10
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/omnibar.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "omnibar/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'omnibar'
|
8
|
+
spec.version = Omnibar::VERSION
|
9
|
+
spec.authors = ['Jacob Evan Shreve']
|
10
|
+
spec.email = ['shreve@umich.edu']
|
11
|
+
|
12
|
+
spec.summary = 'A command line butler'
|
13
|
+
spec.description = 'Ask omnibar, and ye shall receive'
|
14
|
+
spec.homepage = 'https://github.com/shreve/omnibar'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.16.a"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: omnibar
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jacob Evan Shreve
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-11-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.16.a
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.16.a
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: Ask omnibar, and ye shall receive
|
42
|
+
email:
|
43
|
+
- shreve@umich.edu
|
44
|
+
executables:
|
45
|
+
- omnibar
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".gitignore"
|
50
|
+
- Gemfile
|
51
|
+
- Gemfile.lock
|
52
|
+
- LICENSE.txt
|
53
|
+
- README.md
|
54
|
+
- Rakefile
|
55
|
+
- bin/console
|
56
|
+
- bin/setup
|
57
|
+
- exe/omnibar
|
58
|
+
- lib/omnibar.rb
|
59
|
+
- lib/omnibar/ansi.rb
|
60
|
+
- lib/omnibar/app.rb
|
61
|
+
- lib/omnibar/calculate.rb
|
62
|
+
- lib/omnibar/duck_duck_go.rb
|
63
|
+
- lib/omnibar/github.rb
|
64
|
+
- lib/omnibar/google.rb
|
65
|
+
- lib/omnibar/popular.rb
|
66
|
+
- lib/omnibar/query.rb
|
67
|
+
- lib/omnibar/renderer.rb
|
68
|
+
- lib/omnibar/version.rb
|
69
|
+
- omnibar.gemspec
|
70
|
+
homepage: https://github.com/shreve/omnibar
|
71
|
+
licenses:
|
72
|
+
- MIT
|
73
|
+
metadata: {}
|
74
|
+
post_install_message:
|
75
|
+
rdoc_options: []
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
requirements: []
|
89
|
+
rubyforge_project:
|
90
|
+
rubygems_version: 2.6.11
|
91
|
+
signing_key:
|
92
|
+
specification_version: 4
|
93
|
+
summary: A command line butler
|
94
|
+
test_files: []
|