qv 0.0.2 → 0.0.4
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 +4 -4
- data/bin/qv +23 -6
- data/lib/qv/note.rb +8 -2
- data/lib/qv/qv.rb +0 -10
- data/lib/qv/qvconfig.rb +16 -6
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9b1aefa212d360c47f09fada9bce7dab2ab66a91
|
|
4
|
+
data.tar.gz: c2957cad24754fb39c078f314574bb37cc976fec
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 95b021266380b66186026d784f116af2198474c4e5fbb4f07d71eb230d4456033c71da5f803dac92c2660e85dc98b65179f57e91326a18d8dd87c551dbe7e4ce
|
|
7
|
+
data.tar.gz: 0613afb761f3422dbfbfb196bec3bdfd4060acee4144a181adf51103e1b613dc73a712d6bd60b20842ded1cfb3e29b637438f1befb0ca43b51ec3b5cf686c73f
|
data/bin/qv
CHANGED
|
@@ -1,11 +1,28 @@
|
|
|
1
1
|
#!/bin/env ruby
|
|
2
2
|
require 'qv'
|
|
3
|
+
require 'slop'
|
|
3
4
|
|
|
5
|
+
opts = Slop.parse :help => true do
|
|
6
|
+
banner 'qv [options] [static query]'
|
|
7
|
+
on 'c', 'config=', 'specify a config file location'
|
|
8
|
+
on 'e', 'edit', 'open the top result (for static queries)'
|
|
4
9
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
else
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
run do |opts, args|
|
|
11
|
+
if opts[:config]
|
|
12
|
+
QV.read_config(:config_file => opts[:config])
|
|
13
|
+
else
|
|
14
|
+
QV.read_config
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
if args.empty?
|
|
18
|
+
get_input.edit
|
|
19
|
+
else
|
|
20
|
+
static_list = Note.sort_notes_by_date( get_matching_notes(args.join(" ")))
|
|
21
|
+
if opts[:edit]
|
|
22
|
+
static_list.first.edit
|
|
23
|
+
else
|
|
24
|
+
puts static_list.map {|note| note.path}
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
11
28
|
end
|
data/lib/qv/note.rb
CHANGED
|
@@ -14,7 +14,7 @@ class Note
|
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
def path
|
|
17
|
-
@path || File.join(
|
|
17
|
+
@path || File.join(QV.notes_dir,@filename)
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
def get_io
|
|
@@ -29,6 +29,12 @@ class Note
|
|
|
29
29
|
@title.match(/^.*#{search_term}.*$/i)
|
|
30
30
|
end
|
|
31
31
|
|
|
32
|
+
def edit
|
|
33
|
+
editor = ENV["EDITOR"] || '/usr/bin/vim'
|
|
34
|
+
exec "#{editor} \"#{path}\";clear"
|
|
35
|
+
system "clear"
|
|
36
|
+
end
|
|
37
|
+
|
|
32
38
|
def self.sort_notes_by_date(notes)
|
|
33
39
|
notes.sort_by! { |note|
|
|
34
40
|
File.mtime(note.path)}
|
|
@@ -36,7 +42,7 @@ class Note
|
|
|
36
42
|
end
|
|
37
43
|
|
|
38
44
|
def self.get_notes
|
|
39
|
-
note_names = Dir.entries(
|
|
45
|
+
note_names = Dir.entries(QV.notes_dir).reject do |note_filename|
|
|
40
46
|
exceptions = [
|
|
41
47
|
"..",
|
|
42
48
|
".",
|
data/lib/qv/qv.rb
CHANGED
|
@@ -58,15 +58,5 @@ def display_list(search_term, matches, id = 0)
|
|
|
58
58
|
}
|
|
59
59
|
end
|
|
60
60
|
|
|
61
|
-
def launch_editor(note)
|
|
62
|
-
editor = ENV["EDITOR"] || '/usr/bin/vim'
|
|
63
|
-
begin
|
|
64
|
-
exec "#{editor} \"#{note.path}\";clear" if note
|
|
65
|
-
rescue => e
|
|
66
|
-
puts e
|
|
67
|
-
puts "No matching note found"
|
|
68
|
-
end
|
|
69
|
-
system "clear"
|
|
70
|
-
end
|
|
71
61
|
|
|
72
62
|
|
data/lib/qv/qvconfig.rb
CHANGED
|
@@ -1,9 +1,19 @@
|
|
|
1
|
-
class
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
class QV
|
|
2
|
+
@@notes_dir = File.join( ENV["HOME"], "notes" )
|
|
3
|
+
@@config_file = File.join( ENV["HOME"], ".qvrc" )
|
|
4
|
+
|
|
5
|
+
def self.notes_dir
|
|
6
|
+
@@notes_dir
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def self.read_config(args = {})
|
|
10
|
+
@@config_file = args[:config_file] if args[:config_file]
|
|
11
|
+
if File.exist?(@@config_file)
|
|
12
|
+
@@notes_dir = File.expand_path(File.read(@@config_file).match(/(?<=notes_dir = ).*$/)[0])
|
|
13
|
+
end
|
|
7
14
|
end
|
|
8
15
|
|
|
16
|
+
def self.set_notes_dir(args = {})
|
|
17
|
+
@@notes_dir = File.expand_path(args[:notes_dir])
|
|
18
|
+
end
|
|
9
19
|
end
|