noty 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +30 -0
- data/exe/noty +13 -165
- data/lib/noty.rb +57 -2
- data/lib/noty/ask.rb +7 -0
- data/lib/noty/helpers.rb +30 -0
- data/lib/noty/models/bookmark.rb +64 -0
- data/lib/noty/models/snippet.rb +37 -0
- data/lib/noty/services/search.rb +18 -0
- data/lib/noty/storage.rb +6 -0
- data/lib/noty/ui.rb +43 -0
- data/lib/noty/version.rb +1 -1
- metadata +39 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1ee94f9f7f6768a48b1797a647e0f7db4b3f9875
|
4
|
+
data.tar.gz: 0e490608feb4bef1374a4683a15e8430647aacbd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 34bb28fd6ea2e39789a0e9f73a2c8a0665cae5e10a5a0ffc513735a21a38e97d360f04a1163bdb8b1b79b81af972795f3235e077d45c2a07129545269755bbce
|
7
|
+
data.tar.gz: c2d8c9c6b976d8bde17d18e558b7f4ea40664dcc9424c7c9f234f9f9ce88bc84b7d8d6b5b397f49c574e7da434407200106d97b5e71aaaa19fdb628945a46238
|
data/README.md
CHANGED
@@ -20,6 +20,14 @@ $ gem install noty
|
|
20
20
|
1. xsel : could be found on most distros official repositories
|
21
21
|
2. xdg-open : should be installed with most opendesktop compatible desktop environments
|
22
22
|
|
23
|
+
## Environment
|
24
|
+
|
25
|
+
by default Noty saves your files in `~/.notes` if you want to change that path, define an Environment variable in your shell init file `.bashrc` or `.zshrc`
|
26
|
+
|
27
|
+
```bash
|
28
|
+
export NOTES_PATH=/path/to/your/notes/dir
|
29
|
+
```
|
30
|
+
|
23
31
|
|
24
32
|
## Usage
|
25
33
|
|
@@ -36,6 +44,28 @@ Snippets and bookmarks manager.
|
|
36
44
|
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
45
|
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
46
|
|
47
|
+
## Examples
|
48
|
+
|
49
|
+
Add a bookmark
|
50
|
+
```bash
|
51
|
+
noty https://www.youtube.com
|
52
|
+
```
|
53
|
+
|
54
|
+
Search for bookmark
|
55
|
+
```bash
|
56
|
+
noty youtube
|
57
|
+
```
|
58
|
+
|
59
|
+
Add a snippet text
|
60
|
+
```bash
|
61
|
+
noty this is a long text that I need to save in my stash
|
62
|
+
```
|
63
|
+
|
64
|
+
Search for a snippet (same as searching for bookmarks)
|
65
|
+
```bash
|
66
|
+
noty need
|
67
|
+
```
|
68
|
+
|
39
69
|
## Contributing
|
40
70
|
|
41
71
|
Bug reports and pull requests are welcome on GitHub at https://github.com/blazeeboy/noty.
|
data/exe/noty
CHANGED
@@ -1,167 +1,15 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
require 'open-uri'
|
3
|
-
require 'yaml'
|
4
|
-
require 'fileutils'
|
5
|
-
require 'io/console'
|
6
2
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
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
|
3
|
+
$LOAD_PATH.unshift(File.dirname(File.realpath(__FILE__)) + '/../lib')
|
4
|
+
require 'noty'
|
5
|
+
|
6
|
+
Noty.send case ARGV.first
|
7
|
+
when /\Ahttp/
|
8
|
+
:bookmark
|
9
|
+
when 'help', '-h', '--help'
|
10
|
+
:help
|
11
|
+
when 'version', '-v', '--version'
|
12
|
+
:version
|
13
|
+
else
|
14
|
+
:search
|
15
|
+
end
|
data/lib/noty.rb
CHANGED
@@ -1,5 +1,60 @@
|
|
1
|
-
require
|
1
|
+
require 'noty/version'
|
2
|
+
require 'noty/ui'
|
3
|
+
require 'noty/storage'
|
4
|
+
require 'noty/models/bookmark'
|
5
|
+
require 'noty/models/snippet'
|
6
|
+
require 'noty/services/search'
|
2
7
|
|
3
8
|
module Noty
|
4
|
-
|
9
|
+
module_function
|
10
|
+
|
11
|
+
def version
|
12
|
+
puts "Noty version #{VERSION}"
|
13
|
+
end
|
14
|
+
|
15
|
+
def help
|
16
|
+
version
|
17
|
+
puts <<-EOT
|
18
|
+
Snippets and bookmarks manager.
|
19
|
+
|
20
|
+
Usage:
|
21
|
+
noty [command|inputs]
|
22
|
+
|
23
|
+
Commands:
|
24
|
+
help, -h, --help : print this message
|
25
|
+
version, -v, --version : print noty version
|
26
|
+
|
27
|
+
Input types:
|
28
|
+
url: e.g "http://www.example.com", add URL as a bookmark file
|
29
|
+
keyword: search bookmarks and perform action on it, a single word of multiple words or regex, it is passed to "ag silver searcher"
|
30
|
+
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
|
31
|
+
EOT
|
32
|
+
end
|
33
|
+
|
34
|
+
def search
|
35
|
+
keyword = ARGV.join ' '
|
36
|
+
result = Services.search(keyword)
|
37
|
+
|
38
|
+
if !result.empty?
|
39
|
+
UI.choose result
|
40
|
+
elsif keyword.include?(' ')
|
41
|
+
choice = ask 'Do you want to save it as a snippet? [y/N]: '
|
42
|
+
snippet if choice.casecmp 'y'
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def snippet
|
47
|
+
content = ARGV.join ' '
|
48
|
+
path = File.join(Noty::STORAGE_PATH, Time.now.to_i.to_s + '.snippet')
|
49
|
+
|
50
|
+
snippet = Snippet.new(path)
|
51
|
+
snippet.content = content
|
52
|
+
snippet.save
|
53
|
+
end
|
54
|
+
|
55
|
+
def bookmark
|
56
|
+
bm = Bookmark.from_url(ARGV.first)
|
57
|
+
bm.save
|
58
|
+
bm.edit
|
59
|
+
end
|
5
60
|
end
|
data/lib/noty/ask.rb
ADDED
data/lib/noty/helpers.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'open3'
|
2
|
+
|
3
|
+
module Noty
|
4
|
+
module Helpers
|
5
|
+
module_function
|
6
|
+
|
7
|
+
def edit(file_path)
|
8
|
+
editor = ENV['EDITOR'] || 'vi'.freeze
|
9
|
+
system "#{editor} #{file_path}"
|
10
|
+
end
|
11
|
+
|
12
|
+
def copy(text)
|
13
|
+
case RUBY_PLATFORM
|
14
|
+
when /darwin/
|
15
|
+
Open3.capture2('pbcopy', stdin_data: text)
|
16
|
+
when /linux/
|
17
|
+
Open3.capture2('xsel --clipboard --input', stdin_data: text)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def open_url(url)
|
22
|
+
case RUBY_PLATFORM
|
23
|
+
when /darwin/
|
24
|
+
system "open #{url}"
|
25
|
+
when /linux/
|
26
|
+
system "xdg-open #{url}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
require 'yaml'
|
3
|
+
require 'noty/storage'
|
4
|
+
require 'noty/helpers'
|
5
|
+
|
6
|
+
module Noty
|
7
|
+
class Bookmark
|
8
|
+
attr_accessor :path, :url, :title
|
9
|
+
|
10
|
+
def initialize(path)
|
11
|
+
content = File.exist?(path) ? YAML.load_file(path) : ''
|
12
|
+
|
13
|
+
@path = path
|
14
|
+
@url = content['url']
|
15
|
+
@title = content['title']
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.from_url(url)
|
19
|
+
file_path = File.join(STORAGE_PATH, Time.now.to_i.to_s + '.bookmark')
|
20
|
+
content = begin
|
21
|
+
open(url).read
|
22
|
+
rescue
|
23
|
+
''
|
24
|
+
end
|
25
|
+
bookmark = new(file_path)
|
26
|
+
bookmark.url = url
|
27
|
+
bookmark.title = content.match(%r{<title>(.+)<\/title>}im).to_a[1]
|
28
|
+
bookmark
|
29
|
+
end
|
30
|
+
|
31
|
+
def save
|
32
|
+
File.write(path, to_yaml)
|
33
|
+
end
|
34
|
+
|
35
|
+
def delete
|
36
|
+
File.delete path
|
37
|
+
end
|
38
|
+
|
39
|
+
def open
|
40
|
+
Helpers.open_url url
|
41
|
+
end
|
42
|
+
|
43
|
+
def edit
|
44
|
+
Helpers.edit path
|
45
|
+
end
|
46
|
+
|
47
|
+
def copy
|
48
|
+
Helpers.copy url
|
49
|
+
end
|
50
|
+
|
51
|
+
def to_s(short = false)
|
52
|
+
short ? title.to_s : "#{title} (#{url})"
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def to_yaml
|
58
|
+
{
|
59
|
+
'url' => url,
|
60
|
+
'title' => title
|
61
|
+
}.to_yaml
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'noty/storage'
|
2
|
+
require 'noty/helpers'
|
3
|
+
|
4
|
+
module Noty
|
5
|
+
class Snippet
|
6
|
+
attr_accessor :path, :content
|
7
|
+
|
8
|
+
def initialize(path)
|
9
|
+
@path = path
|
10
|
+
@content = File.exist?(path) ? File.read(path) : ''
|
11
|
+
end
|
12
|
+
|
13
|
+
def save
|
14
|
+
File.write(path, content)
|
15
|
+
end
|
16
|
+
|
17
|
+
def delete
|
18
|
+
File.delete path
|
19
|
+
end
|
20
|
+
|
21
|
+
def open
|
22
|
+
edit
|
23
|
+
end
|
24
|
+
|
25
|
+
def copy
|
26
|
+
Helpers.copy content
|
27
|
+
end
|
28
|
+
|
29
|
+
def edit
|
30
|
+
Helpers.edit path
|
31
|
+
end
|
32
|
+
|
33
|
+
def to_s(short = false)
|
34
|
+
short ? content.tr("\n", ' ')[0..100] : content.to_s
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Noty
|
2
|
+
module Services
|
3
|
+
module_function
|
4
|
+
|
5
|
+
def search(keyword)
|
6
|
+
files = `ag -l "#{keyword}" #{STORAGE_PATH}`.lines
|
7
|
+
top_matches = files[0...9].map(&:chomp)
|
8
|
+
top_matches.map do |file|
|
9
|
+
case File.extname(file)
|
10
|
+
when '.bookmark'
|
11
|
+
Bookmark.new(file)
|
12
|
+
when '.snippet'
|
13
|
+
Snippet.new(file)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/noty/storage.rb
ADDED
data/lib/noty/ui.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'noty/ask'
|
2
|
+
|
3
|
+
module Noty
|
4
|
+
module UI
|
5
|
+
module_function
|
6
|
+
|
7
|
+
def choose(objects)
|
8
|
+
return if objects.empty?
|
9
|
+
|
10
|
+
if objects.one?
|
11
|
+
puts objects.first.to_s(false)
|
12
|
+
operations(objects.first)
|
13
|
+
else
|
14
|
+
|
15
|
+
objects.each_with_index do |object, index|
|
16
|
+
puts "#{index + 1}. " + object.to_s(true)
|
17
|
+
end
|
18
|
+
|
19
|
+
choice = ask '-> (1..9) or else to exit: '
|
20
|
+
|
21
|
+
if choice =~ /\A[1-9]\z/
|
22
|
+
puts objects[choice.to_i - 1].to_s(false)
|
23
|
+
operations(objects[choice.to_i - 1])
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def operations(object)
|
29
|
+
case ask '[E]dit [D]elete [O]pen [C]opy, Else to Quit: '
|
30
|
+
when 'e'
|
31
|
+
object.edit
|
32
|
+
when 'd'
|
33
|
+
object.delete
|
34
|
+
when 'o'
|
35
|
+
object.open
|
36
|
+
when 'c'
|
37
|
+
object.copy
|
38
|
+
else
|
39
|
+
exit 0
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/noty/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: noty
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Emad Elsaid
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-05-
|
11
|
+
date: 2017-05-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -75,6 +75,14 @@ description: |
|
|
75
75
|
1. xsel : could be found on most distros official repositories
|
76
76
|
2. xdg-open : should be installed with most opendesktop compatible desktop environments
|
77
77
|
|
78
|
+
## Environment
|
79
|
+
|
80
|
+
by default Noty saves your files in `~/.notes` if you want to change that path, define an Environment variable in your shell init file `.bashrc` or `.zshrc`
|
81
|
+
|
82
|
+
```bash
|
83
|
+
export NOTES_PATH=/path/to/your/notes/dir
|
84
|
+
```
|
85
|
+
|
78
86
|
|
79
87
|
## Usage
|
80
88
|
|
@@ -91,6 +99,28 @@ description: |
|
|
91
99
|
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
100
|
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
101
|
|
102
|
+
## Examples
|
103
|
+
|
104
|
+
Add a bookmark
|
105
|
+
```bash
|
106
|
+
noty https://www.youtube.com
|
107
|
+
```
|
108
|
+
|
109
|
+
Search for bookmark
|
110
|
+
```bash
|
111
|
+
noty youtube
|
112
|
+
```
|
113
|
+
|
114
|
+
Add a snippet text
|
115
|
+
```bash
|
116
|
+
noty this is a long text that I need to save in my stash
|
117
|
+
```
|
118
|
+
|
119
|
+
Search for a snippet (same as searching for bookmarks)
|
120
|
+
```bash
|
121
|
+
noty need
|
122
|
+
```
|
123
|
+
|
94
124
|
## Contributing
|
95
125
|
|
96
126
|
Bug reports and pull requests are welcome on GitHub at https://github.com/blazeeboy/noty.
|
@@ -115,6 +145,13 @@ files:
|
|
115
145
|
- bin/setup
|
116
146
|
- exe/noty
|
117
147
|
- lib/noty.rb
|
148
|
+
- lib/noty/ask.rb
|
149
|
+
- lib/noty/helpers.rb
|
150
|
+
- lib/noty/models/bookmark.rb
|
151
|
+
- lib/noty/models/snippet.rb
|
152
|
+
- lib/noty/services/search.rb
|
153
|
+
- lib/noty/storage.rb
|
154
|
+
- lib/noty/ui.rb
|
118
155
|
- lib/noty/version.rb
|
119
156
|
- noty.gemspec
|
120
157
|
homepage: https://www.github.com/blazeeboy/noty
|