noty 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +45 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/noty +167 -0
- data/lib/noty.rb +5 -0
- data/lib/noty/version.rb +3 -0
- data/noty.gemspec +27 -0
- metadata +144 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 92ebd84abb7bd6e2244b75cbb9702ad4fae00813
|
4
|
+
data.tar.gz: 9c3767b0bda13dbe2b23afe18e511463343d2739
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 89042c9ce2695f8410c2f890137701c8e3743156f509d5e719dc32343a215c89fa6488c478a7e4ddc740ca6a301865032c3aac385e1eae566fdc4ffd9165487b
|
7
|
+
data.tar.gz: bcce25349a539868bb0709a7dd4000f878b27e6c2688c64dfdf874e97f18b6f5838563f05d62a259b74de7e50ae0bff2c45425624096d1a84d9eb457a68b4008
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Emad Elsaid
|
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,45 @@
|
|
1
|
+
# Noty
|
2
|
+
|
3
|
+
A bookmarks and snippets manager, stores bookmarks as YAML files and nippets as plain text, utilizes "Ag silver searcher" fast search to search your files when you need to open or copy a snippet, that makes its searching capabilities so enourmouse as it's inherited from AG.
|
4
|
+
|
5
|
+
Noty is smart, so it react depending on your input, so provide URL and it'll create a bookmark, provide some text and it will search for it in all bookmarks and snippets, if it didn't find any files it will prompt you to create a snippet.
|
6
|
+
|
7
|
+
Some common usages could be, bookmarking URL, save snippet of text you liked, save some canned responses and quickly copy it when needed.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
```bash
|
12
|
+
$ gem install noty
|
13
|
+
```
|
14
|
+
|
15
|
+
## Requirements
|
16
|
+
|
17
|
+
1. ag : silver searcher https://github.com/ggreer/the_silver_searcher
|
18
|
+
|
19
|
+
### For Linux:
|
20
|
+
1. xsel : could be found on most distros official repositories
|
21
|
+
2. xdg-open : should be installed with most opendesktop compatible desktop environments
|
22
|
+
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
Snippets and bookmarks manager.
|
27
|
+
|
28
|
+
**Usage:**
|
29
|
+
```bash
|
30
|
+
noty inputs
|
31
|
+
```
|
32
|
+
|
33
|
+
**Input types:**
|
34
|
+
|
35
|
+
1. **url:** e.g "http://www.example.com", add URL as a bookmark file
|
36
|
+
2. **keyword:** search bookmarks and perform action on it, a single word of multiple words or regex, it is passed to "ag silver searcher"
|
37
|
+
3. **snippet text:** any multiword text, it will search first if no files contain this text you'll be asked if you want to create a snippet for it
|
38
|
+
|
39
|
+
## Contributing
|
40
|
+
|
41
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/blazeeboy/noty.
|
42
|
+
|
43
|
+
## License
|
44
|
+
|
45
|
+
The gem is available as open source under the terms of the [MIT License](http://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 "noty"
|
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/noty
ADDED
@@ -0,0 +1,167 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'open-uri'
|
3
|
+
require 'yaml'
|
4
|
+
require 'fileutils'
|
5
|
+
require 'io/console'
|
6
|
+
|
7
|
+
STORAGE = File.expand_path(ENV['NOTES_PATH'] || '~/.notes')
|
8
|
+
FileUtils.mkdir_p STORAGE
|
9
|
+
|
10
|
+
# ------------------------------------------
|
11
|
+
# HELPERS
|
12
|
+
# ------------------------------------------
|
13
|
+
|
14
|
+
def edit(file_path)
|
15
|
+
editor = ENV['EDITOR'] || 'vi'.freeze
|
16
|
+
system "#{editor} #{file_path}"
|
17
|
+
end
|
18
|
+
|
19
|
+
def copy(file)
|
20
|
+
case RUBY_PLATFORM
|
21
|
+
when /darwin/
|
22
|
+
`cat #{file} | pbcopy`
|
23
|
+
when /linux/
|
24
|
+
`cat #{file} | xsel --clipboard --input`
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def open_url(url)
|
29
|
+
case RUBY_PLATFORM
|
30
|
+
when /darwin/
|
31
|
+
system "open #{url}"
|
32
|
+
when /linux/
|
33
|
+
system "xdg-open #{url}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# ------------------------------------------
|
38
|
+
# PRESENTATION METHODS
|
39
|
+
# ------------------------------------------
|
40
|
+
|
41
|
+
def short_display(file)
|
42
|
+
case File.extname(file)
|
43
|
+
when '.bookmark'
|
44
|
+
content = YAML.load_file(file)
|
45
|
+
puts content['title'].to_s + ' (' + content['url'].to_s + ')'
|
46
|
+
when '.snippet'
|
47
|
+
content = File.read(file)
|
48
|
+
puts content.tr("\n", ' ')[0..100]
|
49
|
+
else
|
50
|
+
puts File.open(file).read(100).to_s.lines.first
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def long_display(file)
|
55
|
+
puts File.read(file)
|
56
|
+
end
|
57
|
+
|
58
|
+
def choose(files)
|
59
|
+
if files.empty?
|
60
|
+
exit 0
|
61
|
+
elsif files.one?
|
62
|
+
long_display files.first
|
63
|
+
operations(files.first)
|
64
|
+
else
|
65
|
+
|
66
|
+
files.each_with_index do |file, index|
|
67
|
+
print "#{index + 1}. "
|
68
|
+
short_display file
|
69
|
+
end
|
70
|
+
|
71
|
+
print '-> (1..9) or Q to exit: '
|
72
|
+
puts choice = $stdin.getch
|
73
|
+
|
74
|
+
case choice
|
75
|
+
when 'q'
|
76
|
+
exit 0
|
77
|
+
when /\A[1-9]\z/
|
78
|
+
long_display files[choice.to_i - 1]
|
79
|
+
operations(files[choice.to_i - 1])
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def operations(file)
|
85
|
+
print '[E]dit [D]elete [O]pen [C]opy, Else to Quit: '
|
86
|
+
puts choice = $stdin.getch
|
87
|
+
|
88
|
+
case choice
|
89
|
+
when 'e'
|
90
|
+
edit file
|
91
|
+
when 'd'
|
92
|
+
File.delete file
|
93
|
+
when 'o'
|
94
|
+
content = YAML.load_file(file)
|
95
|
+
open_url content['url']
|
96
|
+
when 'c'
|
97
|
+
copy file
|
98
|
+
else
|
99
|
+
exit 0
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def create_snippet(text)
|
104
|
+
print 'Do you want to save it as a snippet? [y/N]: '
|
105
|
+
puts choice = $stdin.getch
|
106
|
+
return unless choice.casecmp 'y'
|
107
|
+
|
108
|
+
file_path = File.join(STORAGE, Time.now.to_i.to_s + '.snippet')
|
109
|
+
File.write(file_path, text)
|
110
|
+
end
|
111
|
+
|
112
|
+
# -----------------------------------------------------------
|
113
|
+
# TOP LEVEL COMMANDS
|
114
|
+
# -----------------------------------------------------------
|
115
|
+
def help
|
116
|
+
exec_name = File.basename(__FILE__)
|
117
|
+
puts <<-EOT
|
118
|
+
Snippets and bookmarks manager.
|
119
|
+
Usage:
|
120
|
+
#{exec_name} [command|inputs]
|
121
|
+
|
122
|
+
Commands:
|
123
|
+
#{exec_name} help, --help : print this message
|
124
|
+
|
125
|
+
Input types:
|
126
|
+
url: e.g "http://www.example.com", add URL as a bookmark file
|
127
|
+
keyword: search bookmarks and perform action on it, a single word of multiple words or regex, it is passed to "ag silver searcher"
|
128
|
+
snippet text: any multiword text, it will search first if no files contain this text you'll be asked if you want to create a snippet for it
|
129
|
+
EOT
|
130
|
+
end
|
131
|
+
|
132
|
+
def bookmark
|
133
|
+
url = ARGV.first
|
134
|
+
content = begin
|
135
|
+
open(url).read
|
136
|
+
rescue
|
137
|
+
""
|
138
|
+
end
|
139
|
+
file_path = File.join(STORAGE, Time.now.to_i.to_s + '.bookmark')
|
140
|
+
bookmark_object = {
|
141
|
+
'url' => url,
|
142
|
+
'title' => content.match(%r{<title>(.+)<\/title>}im).to_a[1]
|
143
|
+
}
|
144
|
+
File.write(file_path, bookmark_object.to_yaml)
|
145
|
+
edit file_path
|
146
|
+
end
|
147
|
+
|
148
|
+
def search
|
149
|
+
keyword = ARGV.join ' '
|
150
|
+
files = `ag -l "#{keyword}" #{STORAGE}`.lines
|
151
|
+
top_matches = files[0...9].map(&:chomp)
|
152
|
+
|
153
|
+
if top_matches.empty? && keyword.include?(' ')
|
154
|
+
create_snippet(keyword)
|
155
|
+
else
|
156
|
+
choose top_matches
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
send case ARGV.first
|
161
|
+
when /\Ahttp/
|
162
|
+
:bookmark
|
163
|
+
when 'help', '--help'
|
164
|
+
:help
|
165
|
+
else
|
166
|
+
:search
|
167
|
+
end
|
data/lib/noty.rb
ADDED
data/lib/noty/version.rb
ADDED
data/noty.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'noty/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "noty"
|
8
|
+
spec.version = Noty::VERSION
|
9
|
+
spec.authors = ["Emad Elsaid"]
|
10
|
+
spec.email = ["emad.elsaid@blacklane.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Terminal storage for bookmarks or snippets}
|
13
|
+
spec.description = File.read('README.md')
|
14
|
+
spec.homepage = "https://www.github.com/blazeeboy/noty"
|
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.14"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: noty
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Emad Elsaid
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-05-04 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.14'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.14'
|
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
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
description: |
|
56
|
+
# Noty
|
57
|
+
|
58
|
+
A bookmarks and snippets manager, stores bookmarks as YAML files and nippets as plain text, utilizes "Ag silver searcher" fast search to search your files when you need to open or copy a snippet, that makes its searching capabilities so enourmouse as it's inherited from AG.
|
59
|
+
|
60
|
+
Noty is smart, so it react depending on your input, so provide URL and it'll create a bookmark, provide some text and it will search for it in all bookmarks and snippets, if it didn't find any files it will prompt you to create a snippet.
|
61
|
+
|
62
|
+
Some common usages could be, bookmarking URL, save snippet of text you liked, save some canned responses and quickly copy it when needed.
|
63
|
+
|
64
|
+
## Installation
|
65
|
+
|
66
|
+
```bash
|
67
|
+
$ gem install noty
|
68
|
+
```
|
69
|
+
|
70
|
+
## Requirements
|
71
|
+
|
72
|
+
1. ag : silver searcher https://github.com/ggreer/the_silver_searcher
|
73
|
+
|
74
|
+
### For Linux:
|
75
|
+
1. xsel : could be found on most distros official repositories
|
76
|
+
2. xdg-open : should be installed with most opendesktop compatible desktop environments
|
77
|
+
|
78
|
+
|
79
|
+
## Usage
|
80
|
+
|
81
|
+
Snippets and bookmarks manager.
|
82
|
+
|
83
|
+
**Usage:**
|
84
|
+
```bash
|
85
|
+
noty inputs
|
86
|
+
```
|
87
|
+
|
88
|
+
**Input types:**
|
89
|
+
|
90
|
+
1. **url:** e.g "http://www.example.com", add URL as a bookmark file
|
91
|
+
2. **keyword:** search bookmarks and perform action on it, a single word of multiple words or regex, it is passed to "ag silver searcher"
|
92
|
+
3. **snippet text:** any multiword text, it will search first if no files contain this text you'll be asked if you want to create a snippet for it
|
93
|
+
|
94
|
+
## Contributing
|
95
|
+
|
96
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/blazeeboy/noty.
|
97
|
+
|
98
|
+
## License
|
99
|
+
|
100
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
101
|
+
email:
|
102
|
+
- emad.elsaid@blacklane.com
|
103
|
+
executables:
|
104
|
+
- noty
|
105
|
+
extensions: []
|
106
|
+
extra_rdoc_files: []
|
107
|
+
files:
|
108
|
+
- ".gitignore"
|
109
|
+
- ".travis.yml"
|
110
|
+
- Gemfile
|
111
|
+
- LICENSE.txt
|
112
|
+
- README.md
|
113
|
+
- Rakefile
|
114
|
+
- bin/console
|
115
|
+
- bin/setup
|
116
|
+
- exe/noty
|
117
|
+
- lib/noty.rb
|
118
|
+
- lib/noty/version.rb
|
119
|
+
- noty.gemspec
|
120
|
+
homepage: https://www.github.com/blazeeboy/noty
|
121
|
+
licenses:
|
122
|
+
- MIT
|
123
|
+
metadata: {}
|
124
|
+
post_install_message:
|
125
|
+
rdoc_options: []
|
126
|
+
require_paths:
|
127
|
+
- lib
|
128
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
requirements: []
|
139
|
+
rubyforge_project:
|
140
|
+
rubygems_version: 2.6.10
|
141
|
+
signing_key:
|
142
|
+
specification_version: 4
|
143
|
+
summary: Terminal storage for bookmarks or snippets
|
144
|
+
test_files: []
|