rbnotes 0.4.0 → 0.4.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 +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +1 -1
- data/README.md +37 -0
- data/lib/rbnotes/commands.rb +26 -9
- data/lib/rbnotes/commands/add.rb +51 -9
- data/lib/rbnotes/commands/search.rb +22 -24
- data/lib/rbnotes/version.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '09f402dd55c244533d8f8ba3518df3d13cde1c5952efad94598f210a43a88c11'
|
4
|
+
data.tar.gz: a824e8e2e33c1c1e67d2ff27ab22618d83aa7138a889db20d43f40491f6e1c82
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e52be521f1d1502ca2d36fd6853203436e15c3f830e17ff509529b0b7f08a2fad26a264714d81732603e6f6dabe69c2d40bebdb400b306f4fba1218c86c2ac52
|
7
|
+
data.tar.gz: c555b3b74717d45d18a6d63959356ff411457b2f3b47819ca53ecca38fc6de03a9e5d5839e622e5b65d3513c40dfe487b2649206697d075400c1121a61ea99d4
|
data/CHANGELOG.md
CHANGED
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
|
|
7
7
|
## [Unreleased]
|
8
8
|
Nothing to record here.
|
9
9
|
|
10
|
+
## [0.4.1] - 2020-11-04
|
11
|
+
### Added
|
12
|
+
- Add a feature to accept a timestamp in `add` command. (#34)
|
13
|
+
|
10
14
|
## [0.4.0] - 2020-11-03
|
11
15
|
### Added
|
12
16
|
- Add a new command `search` to perform full text search. (#33)
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -4,6 +4,9 @@
|
|
4
4
|
|
5
5
|
Rbnotes is a simple utility to write a note in the single repository.
|
6
6
|
|
7
|
+
This document provides the basic information to use rbnotes.
|
8
|
+
You may find more useful information in [Wiki pages](https://github.com/mnbi/rbnotes/wiki).
|
9
|
+
|
7
10
|
## Installation
|
8
11
|
|
9
12
|
Add this line to your application's Gemfile:
|
@@ -39,6 +42,8 @@ rbnotes [global_opts] [command] [command_opts] [args]
|
|
39
42
|
- imports existing files
|
40
43
|
- list
|
41
44
|
- lists notes in the repository with their timestamps and subject
|
45
|
+
- search
|
46
|
+
- search a word (or words) in the repository
|
42
47
|
- show
|
43
48
|
- shows the content of a note
|
44
49
|
- add
|
@@ -145,6 +150,38 @@ The short-hand notation of the home directory ("~") is usable.
|
|
145
150
|
|
146
151
|
- :pager : specify a pager program
|
147
152
|
- :editor : specify a editor program
|
153
|
+
- :searcher: specify a program to perform search
|
154
|
+
- :searcher_options: specify options to pass to the searcher program
|
155
|
+
|
156
|
+
Be careful to set `:searcher` and `:searcher_options`. The searcher
|
157
|
+
program must be expected to behave equivalent to `grep` with `-inRE`.
|
158
|
+
At least, its output must be the same format and it must runs
|
159
|
+
recursively to a directory.
|
160
|
+
|
161
|
+
If your favorite searcher is one of the followings, see the default
|
162
|
+
options which `textrepo` sets for those searchers. In most cases, you
|
163
|
+
don't have to set `:searcher_options` for them.
|
164
|
+
|
165
|
+
| searcher | default options in `textrepo` |
|
166
|
+
|:---------|:---------------------------------------------------|
|
167
|
+
| `grep` | `["-i", "-n", "-R", "-E"]` |
|
168
|
+
| `egrep` | `["-i", "-n", "-R"]` |
|
169
|
+
| `ggrep` | `["-i", "-n", "-R", "-E"]` |
|
170
|
+
| `gegrep` | `["-i", "-n", "-R"]` |
|
171
|
+
| `rg` | `["-S", "-n", "--no-heading", "--color", "never"]` |
|
172
|
+
|
173
|
+
Those searcher names are used in macOS (with Homebrew). Any other OS
|
174
|
+
might use different names.
|
175
|
+
|
176
|
+
- `grep` and `egrep` -> BSD grep (macOS default)
|
177
|
+
- `ggrep` and `gegrep` -> GNU grep
|
178
|
+
- `rg` -> ripgrep
|
179
|
+
|
180
|
+
If the name is different, `:searcher_options` should be set with the
|
181
|
+
same value. For example, if you system use the name `gnugrep` as GNU
|
182
|
+
grep, and you want to use it as the searcher (that is, set `gnugrep`
|
183
|
+
to `:searcher`), you should set `:searcher_options` value with `["-i",
|
184
|
+
"-n", "-R", "-E"]`.
|
148
185
|
|
149
186
|
##### Default values for mandatory variables
|
150
187
|
|
data/lib/rbnotes/commands.rb
CHANGED
@@ -32,23 +32,36 @@ module Rbnotes
|
|
32
32
|
class Help < Command
|
33
33
|
def execute(_, _)
|
34
34
|
puts <<USAGE
|
35
|
-
usage:
|
35
|
+
usage:
|
36
|
+
rbnotes [-c|--conf CONF_FILE] [command] [args]
|
37
|
+
|
38
|
+
option:
|
39
|
+
-c, --conf [CONF_FILE] : specifiy the configuration file
|
40
|
+
|
41
|
+
CONF_FILE must be written in YAML. To know about details of the
|
42
|
+
configuration file, see README.md or Wiki page.
|
36
43
|
|
37
44
|
command:
|
38
45
|
add : create a new note
|
39
46
|
import FILE : import a FILE into the repository
|
40
47
|
|
41
|
-
list
|
48
|
+
list [STAMP_PATTERN] : list notes those timestamp matches PATTERN
|
49
|
+
search PATTERN [STAMP_PATTERN] : search PATTERN
|
50
|
+
|
51
|
+
STAMP_PATTERN must be:
|
42
52
|
|
43
|
-
PATTERN must be:
|
44
53
|
(a) full qualified timestamp (with suffix): "20201030160200"
|
45
54
|
(b) year and date part: "20201030"
|
46
|
-
(c) year part
|
47
|
-
(d)
|
55
|
+
(c) year and month part: "202010"
|
56
|
+
(d) year part only: "2020"
|
57
|
+
(e) date part only: "1030"
|
48
58
|
|
49
|
-
|
50
|
-
|
51
|
-
|
59
|
+
PATTERN is a word (or words) to search, it may also be a regular
|
60
|
+
expression.
|
61
|
+
|
62
|
+
show [STAMP] : show the note specified with STAMP
|
63
|
+
update [STAMP] : edit the note with external editor
|
64
|
+
delete [STAMP] : delete the note specified with STAMP
|
52
65
|
|
53
66
|
STAMP must be a sequence of digits to represent year, date and
|
54
67
|
time (and suffix), such "20201030160200" or "20201030160200_012".
|
@@ -59,11 +72,15 @@ command:
|
|
59
72
|
version : print version
|
60
73
|
help : show help
|
61
74
|
|
62
|
-
|
75
|
+
command for development:
|
63
76
|
conf : print the current configuraitons
|
64
77
|
repo : print the repository path
|
65
78
|
stamp TIME_STR : convert TIME_STR into a timestamp
|
66
79
|
time STAMP : convert STAMP into a time string
|
80
|
+
|
81
|
+
For more information, see Wiki page.
|
82
|
+
- https://github.com/mnbi/rbnotes/wiki
|
83
|
+
|
67
84
|
USAGE
|
68
85
|
end
|
69
86
|
end
|
data/lib/rbnotes/commands/add.rb
CHANGED
@@ -1,9 +1,20 @@
|
|
1
1
|
module Rbnotes::Commands
|
2
|
+
|
2
3
|
##
|
3
|
-
# Adds a new note to the repository.
|
4
|
-
# at the execution time, then it is attached to the
|
5
|
-
# timestamp has already existed in the repository, the
|
6
|
-
# fails.
|
4
|
+
# Adds a new note to the repository. If no options, a new timestamp
|
5
|
+
# is generated at the execution time, then it is attached to the
|
6
|
+
# note. If the timestamp has already existed in the repository, the
|
7
|
+
# command fails.
|
8
|
+
#
|
9
|
+
# Accepts an option with `-t STAMP_PATTERN` (or `--timestamp`), a
|
10
|
+
# timestamp is generated according to `STAMP_PATTERN`.
|
11
|
+
#
|
12
|
+
# STAMP_PATTERN could be one of followings:
|
13
|
+
#
|
14
|
+
# "20201104172230_078" : full qualified timestamp string
|
15
|
+
# "20201104172230" : full qualified timestamp string (no suffix)
|
16
|
+
# "202011041722" : year, date and time (omit second part)
|
17
|
+
# "11041722" : date and time (omit year and second part)
|
7
18
|
#
|
8
19
|
# This command starts the external editor program to prepare text to
|
9
20
|
# store. The editor program will be searched in the following order:
|
@@ -14,23 +25,37 @@ module Rbnotes::Commands
|
|
14
25
|
# 4. "vi"
|
15
26
|
#
|
16
27
|
# If none of the above editor is available, the command fails.
|
17
|
-
|
28
|
+
|
18
29
|
class Add < Command
|
19
30
|
include ::Rbnotes::Utils
|
20
31
|
|
21
32
|
def execute(args, conf)
|
22
|
-
|
33
|
+
@opts = {}
|
34
|
+
while args.size > 0
|
35
|
+
arg = args.shift
|
36
|
+
case arg
|
37
|
+
when "-t", "--timestamp"
|
38
|
+
stamp_str = args.shift
|
39
|
+
raise ArgumentError, "missing timestamp: %s" % args.unshift(arg) if stamp_str.nil?
|
40
|
+
stamp_str = complement_timestamp_pattern(stamp_str)
|
41
|
+
@opts[:timestamp] = Textrepo::Timestamp.parse_s(stamp_str)
|
42
|
+
else
|
43
|
+
args.unshift(arg)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
stamp = @opts[:timestamp] || Textrepo::Timestamp.new(Time.now)
|
23
48
|
|
24
49
|
candidates = [conf[:editor], ENV["EDITOR"], "nano", "vi"].compact
|
25
50
|
editor = find_program(candidates)
|
26
51
|
raise Rbnotes::NoEditorError, candidates if editor.nil?
|
27
52
|
|
28
|
-
tmpfile = run_with_tmpfile(editor,
|
53
|
+
tmpfile = run_with_tmpfile(editor, stamp.to_s)
|
29
54
|
text = File.readlines(tmpfile)
|
30
55
|
|
31
56
|
repo = Textrepo.init(conf)
|
32
57
|
begin
|
33
|
-
repo.create(
|
58
|
+
repo.create(stamp, text)
|
34
59
|
rescue Textrepo::DuplicateTimestampError => e
|
35
60
|
puts e.message
|
36
61
|
puts "Just wait a second, then retry."
|
@@ -39,11 +64,28 @@ module Rbnotes::Commands
|
|
39
64
|
rescue StandardError => e
|
40
65
|
puts e.message
|
41
66
|
else
|
42
|
-
puts "Add a note [%s]" %
|
67
|
+
puts "Add a note [%s]" % stamp.to_s
|
43
68
|
ensure
|
44
69
|
# Don't forget to remove the temporary file.
|
45
70
|
File.delete(tmpfile)
|
46
71
|
end
|
47
72
|
end
|
73
|
+
|
74
|
+
# :stopdoc:
|
75
|
+
private
|
76
|
+
def complement_timestamp_pattern(pattern)
|
77
|
+
stamp_str = nil
|
78
|
+
case pattern.to_s.size
|
79
|
+
when "yyyymoddhhmiss_lll".size, "yyyymoddhhmiss".size
|
80
|
+
stamp_str = pattern.dup
|
81
|
+
when "yyyymoddhhmi".size # omit sec part
|
82
|
+
stamp_str = "#{pattern}00"
|
83
|
+
when "moddhhmi".size # omit year and sec part
|
84
|
+
stamp_str = "#{Time.now.year}#{pattern}00"
|
85
|
+
else
|
86
|
+
raise Textrepo::InvalidTimestampStringError, pattern
|
87
|
+
end
|
88
|
+
stamp_str
|
89
|
+
end
|
48
90
|
end
|
49
91
|
end
|
@@ -1,29 +1,27 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
##
|
4
|
-
# Searches a given pattern in notes those have timestamps match a
|
5
|
-
# given timestamp pattern. The first argument is a pattern to search.
|
6
|
-
# It is a String object represents a portion of text or it may a
|
7
|
-
# String represents a regular expression. The second argument is
|
8
|
-
# optional and it is a timestamp pattern to specify the search target.
|
9
|
-
#
|
10
|
-
# A pattern for search is mandatory. If no pattern, raises
|
11
|
-
# Rbnotes::MissingArgumentError.
|
12
|
-
#
|
13
|
-
# Example of PATTERN:
|
14
|
-
# ""rbnotes" (a word)
|
15
|
-
# "macOS Big Sur" (a few words)
|
16
|
-
# "2[0-9]{3}(0[1-9]|1[0-2])(0[1-9]|[12][0-9]|3[01])" (a regular expression)
|
17
|
-
#
|
18
|
-
# A timestamp pattern is optional. If no timestamp pattern, all notes
|
19
|
-
# in the repository would be target of search.
|
20
|
-
#
|
21
|
-
# See the document of `Rbnotes::Commands::List#execute` to know about
|
22
|
-
# a timestamp pattern.
|
1
|
+
module Rbnotes
|
23
2
|
|
24
|
-
|
3
|
+
##
|
4
|
+
# Searches a given pattern in notes those have timestamps match a
|
5
|
+
# given timestamp pattern. The first argument is a pattern to search.
|
6
|
+
# It is a String object represents a portion of text or it may a
|
7
|
+
# String represents a regular expression. The second argument is
|
8
|
+
# optional and it is a timestamp pattern to specify the search target.
|
9
|
+
#
|
10
|
+
# A pattern for search is mandatory. If no pattern, raises
|
11
|
+
# Rbnotes::MissingArgumentError.
|
12
|
+
#
|
13
|
+
# Example of PATTERN for search:
|
14
|
+
#
|
15
|
+
# "rbnotes" (a word)
|
16
|
+
# "macOS Big Sur" (a few words)
|
17
|
+
# "2[0-9]{3}(0[1-9]|1[0-2])(0[1-9]|[12][0-9]|3[01])" (a regular expression)
|
18
|
+
#
|
19
|
+
# A timestamp pattern is optional. If no timestamp pattern, all notes
|
20
|
+
# in the repository would be target of search.
|
21
|
+
#
|
22
|
+
# See the document of `Rbnotes::Commands::List#execute` to know about
|
23
|
+
# a timestamp pattern.
|
25
24
|
|
26
|
-
module Rbnotes
|
27
25
|
class Commands::Search < Commands::Command
|
28
26
|
def execute(args, conf)
|
29
27
|
pattern = args.shift
|
data/lib/rbnotes/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rbnotes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mnbi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-11-
|
11
|
+
date: 2020-11-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: textrepo
|