whale 0.1.0 → 0.3.0
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/whale +42 -29
- data/lib/whale.rb +11 -12
- 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: f6394ed84b098d65ca2be4a0dbd00904ea2d03c4
|
4
|
+
data.tar.gz: e402d341944f3c971d4db7b0da4ceed8ecd1f73d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d32425414eb367cb0bdd12220aaaa89bddc1cf3bd5b07f7a75867b39383875b461039feea6482e3eae34df739dbcdd5ee7b0ad8fe78a1d2708986c0942fcb5d
|
7
|
+
data.tar.gz: 4ba0d9abf19474b056ee134f65d650626a86fe194377a8e712a15b842797b838fbb1d82c044a0fe88e80f9f642a952a5a5aa6ca1ad7069d91729345519076351
|
data/bin/whale
CHANGED
@@ -2,20 +2,19 @@
|
|
2
2
|
require 'whale'
|
3
3
|
require 'logger'
|
4
4
|
|
5
|
-
|
6
5
|
USAGE = <<ENDUSAGE
|
7
6
|
Usage:
|
8
|
-
whale [
|
7
|
+
whale [filter] [-h] [-p paths] [-r] [-f file] [-e id] [-s tag]
|
9
8
|
[-w] [-n] [-t] [-v] [-d]
|
10
9
|
ENDUSAGE
|
11
10
|
|
12
11
|
HELP = <<ENDHELP
|
13
|
-
|
12
|
+
filter Filter to apply on the entries
|
14
13
|
-h, --help View this message
|
15
14
|
-p, --paths Colon-separated list of paths to search
|
16
15
|
-r, --recursive Search for files recursively
|
17
|
-
-f, --
|
18
|
-
-e, --edit Open the editor
|
16
|
+
-f, --file The file to read
|
17
|
+
-e, --edit Open the editor at the given entry
|
19
18
|
-s, --sort Sort entries by tag value
|
20
19
|
-w, --write Write the entries to stdout
|
21
20
|
-n, --name List the tag names
|
@@ -23,6 +22,25 @@ HELP = <<ENDHELP
|
|
23
22
|
-v, --version Show the version number
|
24
23
|
-d, --debug Set the logging level to debug
|
25
24
|
|
25
|
+
whale is a tool for keeping your ideas organized. Write ideas into some
|
26
|
+
files and tag them with labels. whale can then filter and sort the entries
|
27
|
+
based on the tags. Each entry ends with one or more taglines, which consist
|
28
|
+
of a semicolon followed by space-separated tags. Tags are assigned a
|
29
|
+
value by writing tag=value. Taglines at the beginning of the file are
|
30
|
+
applied to every entry in the file.
|
31
|
+
|
32
|
+
filter
|
33
|
+
Show entries with tags satisfying the filter. The filter is a string
|
34
|
+
consisting of Ruby regexes and operators in reverse polish notation.
|
35
|
+
A regex evaluates to true if at least one tag name in an entry matches it.
|
36
|
+
One can further match on the tag value by writing = followed by a regex.
|
37
|
+
Options for regexes are specified by writing in the form /(?option:regex)/.
|
38
|
+
The symbols for AND, OR, and NOT are &, |, and *, respectively.
|
39
|
+
|
40
|
+
Example:
|
41
|
+
whale "/action/ /done/ * &" gives entries with tags matching 'action' but
|
42
|
+
not 'done'.
|
43
|
+
|
26
44
|
-p, --paths
|
27
45
|
Specify the paths to search. Each path is separated by a colon. Any files
|
28
46
|
with the .wl or .whale extension are read.
|
@@ -30,13 +48,8 @@ HELP = <<ENDHELP
|
|
30
48
|
-r, --recursive
|
31
49
|
Search for files recursively.
|
32
50
|
|
33
|
-
-f, --
|
34
|
-
|
35
|
-
consisting of Ruby regexes and operators in reverse polish notation.
|
36
|
-
A regex evaluates to true if at least one tag name in an entry matches it.
|
37
|
-
One can further match on the tag value by writing = followed by a regex.
|
38
|
-
Options for regexes are specified by writing /(?option:regex)/.
|
39
|
-
The symbols for AND, OR, and NOT are &, |, and *, respectively.
|
51
|
+
-f, --file file
|
52
|
+
The file to read.
|
40
53
|
|
41
54
|
-e, --edit id
|
42
55
|
Edit the entry with id id using the text editor specified by the environment
|
@@ -67,17 +80,20 @@ Environment
|
|
67
80
|
WHALEPATH
|
68
81
|
A colon separated list of default paths to search when paths is not
|
69
82
|
provided.
|
83
|
+
|
84
|
+
Installation
|
85
|
+
gem install whale
|
70
86
|
ENDHELP
|
71
87
|
|
72
|
-
args = {
|
73
|
-
unflagged_args = [:
|
88
|
+
args = {}
|
89
|
+
unflagged_args = [:filter]
|
74
90
|
next_arg = unflagged_args.first
|
75
91
|
|
76
92
|
ARGV.each do |arg|
|
77
93
|
case arg
|
78
94
|
when '-h','--help' then args[:help] = true
|
79
95
|
when '-p','--paths' then next_arg = :paths
|
80
|
-
when '-f','--
|
96
|
+
when '-f','--file' then next_arg = :file
|
81
97
|
when '-e','--edit' then next_arg = :edit
|
82
98
|
when '-n','--name' then args[:name] = true
|
83
99
|
when '-t','--tags' then next_arg = :tags
|
@@ -87,13 +103,9 @@ ARGV.each do |arg|
|
|
87
103
|
when '-v','--version' then args[:version] = true
|
88
104
|
when '-d','--debug' then args[:debug] = true
|
89
105
|
else
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
args[next_arg] = arg
|
94
|
-
unflagged_args.delete next_arg
|
95
|
-
next_arg = unflagged_args.first
|
96
|
-
end
|
106
|
+
args[next_arg] = arg
|
107
|
+
unflagged_args.delete next_arg
|
108
|
+
next_arg = unflagged_args.first
|
97
109
|
end
|
98
110
|
end
|
99
111
|
|
@@ -107,25 +119,26 @@ if args[:version]
|
|
107
119
|
exit
|
108
120
|
end
|
109
121
|
|
122
|
+
files = []
|
123
|
+
files << args[:file] if args[:file]
|
110
124
|
paths = []
|
111
125
|
paths += ENV['WHALEPATH'].split(':') if ENV['WHALEPATH']
|
112
126
|
paths += args[:paths].split(':') if args[:paths]
|
113
127
|
|
114
128
|
logger.debug(paths)
|
115
129
|
|
116
|
-
paths.each { |p| args[:
|
117
|
-
list_files_in_path(p, args[:recursive], logger) }
|
130
|
+
paths.each { |p| files += list_files_in_path(p, args[:recursive], logger) }
|
118
131
|
|
119
|
-
logger.debug(
|
132
|
+
logger.debug(files)
|
120
133
|
|
121
|
-
if args[:help] or
|
134
|
+
if args[:help] or files.empty?
|
122
135
|
puts USAGE
|
123
136
|
puts HELP if args[:help]
|
124
137
|
exit
|
125
138
|
end
|
126
139
|
|
127
140
|
entries = []
|
128
|
-
|
141
|
+
files.each do |file|
|
129
142
|
begin
|
130
143
|
entries += parse_file(file, logger)
|
131
144
|
rescue Errno::ENOENT
|
@@ -135,12 +148,12 @@ args[:files].each do |file|
|
|
135
148
|
end
|
136
149
|
end
|
137
150
|
|
138
|
-
logger.info("Parsed #{
|
151
|
+
logger.info("Parsed #{files.length} files " +
|
139
152
|
"and #{entries.length} entries")
|
140
153
|
|
141
154
|
if args[:filter]
|
142
155
|
filter = Filter.new
|
143
|
-
filter.
|
156
|
+
filter.parse_filter(args[:filter], logger)
|
144
157
|
filter_entries(entries, filter, logger)
|
145
158
|
end
|
146
159
|
|
data/lib/whale.rb
CHANGED
@@ -4,7 +4,7 @@ require 'set'
|
|
4
4
|
require 'logger'
|
5
5
|
|
6
6
|
MAJOR_VERSION = 0
|
7
|
-
MINOR_VERSION =
|
7
|
+
MINOR_VERSION = 3
|
8
8
|
REVISION = 0
|
9
9
|
|
10
10
|
$DEFAULT_TAGS = [:title, :body, :line, :file, :tags]
|
@@ -130,14 +130,14 @@ end
|
|
130
130
|
|
131
131
|
def write_entries(entries)
|
132
132
|
entries.each do |e|
|
133
|
-
|
134
|
-
|
133
|
+
puts(e.tags[:title])
|
134
|
+
print("#{e.tags[:body]}")
|
135
135
|
# extension: implement wrapping
|
136
136
|
e.tags.each do |t, v|
|
137
137
|
next if $DEFAULT_TAGS.find_index(t)
|
138
|
-
|
139
|
-
|
140
|
-
|
138
|
+
print(";#{t}")
|
139
|
+
print("=#{v}") if v != true
|
140
|
+
print("\n")
|
141
141
|
end
|
142
142
|
end
|
143
143
|
end
|
@@ -198,9 +198,9 @@ end
|
|
198
198
|
def list_tags(tags)
|
199
199
|
s = ""
|
200
200
|
tags.each do |tag|
|
201
|
-
s << "#{tag}
|
201
|
+
s << "#{tag} "
|
202
202
|
end
|
203
|
-
puts s
|
203
|
+
puts s
|
204
204
|
end
|
205
205
|
|
206
206
|
# List files in the path with the given extension
|
@@ -215,7 +215,7 @@ def list_files_in_path(path, recursive, logger)
|
|
215
215
|
end
|
216
216
|
|
217
217
|
EMPTY_LINE = /\A\s*\Z/
|
218
|
-
|
218
|
+
TAGLINE = /\A;(.*)\Z/
|
219
219
|
|
220
220
|
# Extract entries from file.
|
221
221
|
# param @file a file name to read
|
@@ -229,9 +229,7 @@ def parse_file(file, logger)
|
|
229
229
|
File.open(file, 'r') do |f|
|
230
230
|
f.each_line do |line|
|
231
231
|
lineno += 1
|
232
|
-
|
233
|
-
next if EMPTY_LINE.match line
|
234
|
-
if (m = LABEL_LINE.match line)
|
232
|
+
if (m = TAGLINE.match line)
|
235
233
|
logger.debug("#{f.path}, #{lineno}, reading tag")
|
236
234
|
is_reading_tag = true
|
237
235
|
matched_line = m[1]
|
@@ -242,6 +240,7 @@ def parse_file(file, logger)
|
|
242
240
|
parse_tags entry, matched_line
|
243
241
|
end
|
244
242
|
elsif is_reading_tag
|
243
|
+
next if EMPTY_LINE.match line
|
245
244
|
logger.debug("#{f.path}, #{lineno}, new entry")
|
246
245
|
is_reading_tag = false
|
247
246
|
entries << entry if !entry.nil?
|