qv 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/bin/qv +13 -0
- data/lib/qv/note.rb +51 -0
- data/lib/qv/qv.rb +72 -0
- data/lib/qv.rb +1 -0
- metadata +48 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8ff5184ee5ffd84e08dea09380e965d26c45f5e7
|
4
|
+
data.tar.gz: 38fa5347b2806aeba1b9b516d91a5445d2db7e5d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 57f63b83b79211c39958281fd569c1f2ea51e1c404904bad0e3b4bea3231fb382020567f315bde15b41677bb212d7ab82e83089e9da38c82ab5ad6bceb9cc3e7
|
7
|
+
data.tar.gz: efb323e5c802687031395883c8449febcbf935e256b9bb01bb507557ac714e26310221068f73d3eb537ae7a0fefa3dd45d3104488664f950c39bf018e1557fdd
|
data/bin/qv
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/bin/env ruby
|
2
|
+
require 'qv'
|
3
|
+
|
4
|
+
NOTES_DIR = File.read(File.join(ENV["HOME"],".nvalt")).match(/(?<=notes_dir = ).*$/)[0] ||
|
5
|
+
File.join(ENV["HOME"],"notes")
|
6
|
+
|
7
|
+
if ARGV.empty?
|
8
|
+
results = get_input
|
9
|
+
launch_editor(results)
|
10
|
+
else
|
11
|
+
puts Note.sort_notes_by_date(get_matching_notes(ARGV.join(" "))).map {|note|
|
12
|
+
note.path}
|
13
|
+
end
|
data/lib/qv/note.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
class Note
|
2
|
+
attr_reader :filename
|
3
|
+
|
4
|
+
def initialize(args)
|
5
|
+
@filename = args[:file]
|
6
|
+
@title = title
|
7
|
+
@path = path
|
8
|
+
end
|
9
|
+
|
10
|
+
def title
|
11
|
+
@title || File.basename(@filename, File.extname(@filename))
|
12
|
+
end
|
13
|
+
|
14
|
+
def path
|
15
|
+
@path || File.join(NOTES_DIR,@filename)
|
16
|
+
end
|
17
|
+
|
18
|
+
def get_io
|
19
|
+
File.open(@path)
|
20
|
+
end
|
21
|
+
|
22
|
+
def matches?(search_term)
|
23
|
+
get_io.read.match(/^.*#{search_term}.*$/i)
|
24
|
+
end
|
25
|
+
|
26
|
+
def title_matches?(search_term)
|
27
|
+
@title.match(/^.*#{search_term}.*$/i)
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.sort_notes_by_date(notes)
|
31
|
+
notes.sort_by! { |note|
|
32
|
+
File.mtime(note.path)}
|
33
|
+
notes.reverse!
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.get_notes
|
37
|
+
note_names = Dir.entries(NOTES_DIR).reject do |note_filename|
|
38
|
+
exceptions = [
|
39
|
+
"..",
|
40
|
+
".",
|
41
|
+
"Interim Note-Changes",
|
42
|
+
"Notes & Settings"
|
43
|
+
]
|
44
|
+
exceptions.include?(note_filename) ||
|
45
|
+
note_filename.start_with?(".")
|
46
|
+
end
|
47
|
+
note_names.map do |file|
|
48
|
+
Note.new(:file => file)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/lib/qv/qv.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'qv/note'
|
2
|
+
require 'io/console'
|
3
|
+
|
4
|
+
def get_matching_notes(search_term)
|
5
|
+
matches =
|
6
|
+
Note.get_notes.map do |note|
|
7
|
+
if note.matches?(search_term) || note.title_matches?(search_term)
|
8
|
+
note
|
9
|
+
else
|
10
|
+
nil
|
11
|
+
end
|
12
|
+
end
|
13
|
+
matches.select { |note| note }
|
14
|
+
end
|
15
|
+
|
16
|
+
def get_input
|
17
|
+
search_term = ""
|
18
|
+
io = IO.console
|
19
|
+
position = 0
|
20
|
+
returned = false
|
21
|
+
|
22
|
+
until returned
|
23
|
+
char = io.getch
|
24
|
+
case char
|
25
|
+
when "\u007F" # backspace
|
26
|
+
search_term.slice!(-1)
|
27
|
+
when "\u0003" # C-c
|
28
|
+
exit
|
29
|
+
when "\e" # esc
|
30
|
+
exit
|
31
|
+
when "\u0015" # C-u
|
32
|
+
search_term.replace ""
|
33
|
+
when "\r" # hard return
|
34
|
+
returned = true
|
35
|
+
when "\n" # C-j
|
36
|
+
position = position + 1
|
37
|
+
when "\v" # C-k
|
38
|
+
position = position - 1
|
39
|
+
else
|
40
|
+
search_term << char
|
41
|
+
end
|
42
|
+
matches = Note.sort_notes_by_date(get_matching_notes(search_term))
|
43
|
+
display_list(search_term, matches, position)
|
44
|
+
end
|
45
|
+
matches[position]
|
46
|
+
end
|
47
|
+
|
48
|
+
def display_list(search_term, matches, id = 0)
|
49
|
+
system("clear")
|
50
|
+
puts "#{search_term}: #{matches.count}"
|
51
|
+
notes = matches.take(IO.console.winsize.first-2)
|
52
|
+
puts notes.map {|note|
|
53
|
+
if notes.index(note) == id
|
54
|
+
"* #{note.title}"
|
55
|
+
else
|
56
|
+
note.title
|
57
|
+
end
|
58
|
+
}
|
59
|
+
end
|
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
|
+
|
72
|
+
|
data/lib/qv.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'qv/qv'
|
metadata
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: qv
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- David Gwilliam
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-01-06 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: nvalt-a-like for the cli
|
14
|
+
email: dhgwilliam@gmail.com
|
15
|
+
executables:
|
16
|
+
- qv
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/qv.rb
|
21
|
+
- lib/qv/note.rb
|
22
|
+
- lib/qv/qv.rb
|
23
|
+
- bin/qv
|
24
|
+
homepage: https://github.com/dhgwilliam/qv
|
25
|
+
licenses:
|
26
|
+
- Apache 2.0
|
27
|
+
metadata: {}
|
28
|
+
post_install_message:
|
29
|
+
rdoc_options: []
|
30
|
+
require_paths:
|
31
|
+
- lib
|
32
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - '>='
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0'
|
37
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
requirements: []
|
43
|
+
rubyforge_project:
|
44
|
+
rubygems_version: 2.0.14
|
45
|
+
signing_key:
|
46
|
+
specification_version: 4
|
47
|
+
summary: nvalt-a-like for the cli
|
48
|
+
test_files: []
|