qv 0.0.2 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d8cef291b3304ae82ca0d27334f6fd91f9a73f81
4
- data.tar.gz: 77d36219327308dbfe5fc01aae77805c7bb45a37
3
+ metadata.gz: 9b1aefa212d360c47f09fada9bce7dab2ab66a91
4
+ data.tar.gz: c2957cad24754fb39c078f314574bb37cc976fec
5
5
  SHA512:
6
- metadata.gz: 31f83fb488cc6138fe80fcc01da78f140523bf14face45c5962bf7179a1a0104c5b69683bab8d0d8d4453d3117bdcda45b19d0ae67359c6aaf49bc20a090cbb9
7
- data.tar.gz: 8fa8872e06619fe93c3b8588f415c411b08b76fdcad3c29775cf28a77cf1f40d16d3d4e14b15107e2ec73c93a9ed9f3ac81bee0b04f10eb292a621be1942b0ab
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
- if ARGV.empty?
6
- results = get_input
7
- launch_editor(results)
8
- else
9
- puts Note.sort_notes_by_date(get_matching_notes(ARGV.join(" "))).map {|note|
10
- note.path}
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(QvConfig::NOTES_DIR,@filename)
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(QvConfig::NOTES_DIR).reject do |note_filename|
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 QvConfig
2
-
3
- begin
4
- NOTES_DIR = File.read(File.join(ENV["HOME"],".nvalt")).match(/(?<=notes_dir = ).*$/)[0]
5
- rescue
6
- NOTES_DIR = File.join(ENV["HOME"],"notes")
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Gwilliam