rbnotes 0.4.11 → 0.4.16
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/.github/workflows/main.yml +18 -0
- data/.gitignore +0 -1
- data/CHANGELOG.md +36 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +7 -7
- data/README.md +2 -1
- data/Rakefile +1 -1
- data/conf/config.yml +1 -0
- data/conf/config_deve.yml +1 -0
- data/conf/config_deve_fzf_no_opts.yml +8 -0
- data/conf/config_deve_no_picker.yml +7 -0
- data/conf/config_deve_peco.yml +8 -0
- data/exe/rbnotes +9 -1
- data/lib/rbnotes.rb +0 -5
- data/lib/rbnotes/commands/add.rb +45 -14
- data/lib/rbnotes/commands/commands.rb +17 -12
- data/lib/rbnotes/commands/import.rb +21 -10
- data/lib/rbnotes/commands/list.rb +69 -32
- data/lib/rbnotes/commands/pick.rb +40 -4
- data/lib/rbnotes/commands/show.rb +45 -3
- data/lib/rbnotes/commands/statistics.rb +32 -13
- data/lib/rbnotes/commands/update.rb +21 -10
- data/lib/rbnotes/conf.rb +20 -17
- data/lib/rbnotes/error.rb +37 -7
- data/lib/rbnotes/utils.rb +207 -72
- data/lib/rbnotes/version.rb +2 -2
- data/rbnotes.gemspec +1 -1
- metadata +9 -6
- data/.travis.yml +0 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a3f023516dcf1e39f18c6cd0195a548debfd635e23d476bdb7e89a6ddc5f981e
|
|
4
|
+
data.tar.gz: 52507a17c873c8732922e1cc5990fa41d74f36fca1f558fa5440090f3fcd9fe2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: '0946450a7eeda50688cc5dc836ce30e86d5db28e2af8dca8e84805026648ba018116e98d5b3d316339960a0273d1e717178c4832932418440e0db3c1d1b4e9a9'
|
|
7
|
+
data.tar.gz: 125c3c6fa116fc5cf13d82ba6fb522972b82364b61002de2adc6d36ab1f6d77051f89a948a7cc9ec28acce8179399b040bfc4d983e1c83c65bb2548cc44ee8eb
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
name: Build
|
|
2
|
+
|
|
3
|
+
on: [push,pull_request]
|
|
4
|
+
|
|
5
|
+
jobs:
|
|
6
|
+
build:
|
|
7
|
+
runs-on: ubuntu-latest
|
|
8
|
+
steps:
|
|
9
|
+
- uses: actions/checkout@v2
|
|
10
|
+
- name: Set up Ruby
|
|
11
|
+
uses: ruby/setup-ruby@v1
|
|
12
|
+
with:
|
|
13
|
+
ruby-version: 3.0.0
|
|
14
|
+
- name: Run the default task
|
|
15
|
+
run: |
|
|
16
|
+
gem install bundler -v 2.2.3
|
|
17
|
+
bundle install
|
|
18
|
+
bundle exec rake
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,42 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/)
|
|
|
5
5
|
and this project adheres to [Semantic Versioning](https://semver.org/).
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
|
+
- Nothing to record here.
|
|
9
|
+
|
|
10
|
+
## [0.4.16] - 2021-04-17
|
|
11
|
+
- Add a new configuration setting to change the default behavior of
|
|
12
|
+
the `list` (and `pick`) command. (#109)
|
|
13
|
+
|
|
14
|
+
## [0.4.15] - 2021-04-15
|
|
15
|
+
- Enable to use delimiters within a timestamp string. (#104)
|
|
16
|
+
- Fix issue #105: `list` ignores the 2nd arg when specified `-w`
|
|
17
|
+
option.
|
|
18
|
+
|
|
19
|
+
## [0.4.14] - 2021-04-10
|
|
20
|
+
- Add `-n` option to `show` command. (#102)
|
|
21
|
+
- Fix issue #100: modify to catch Textrepo::MissingTimestampError.
|
|
22
|
+
|
|
23
|
+
## [0.4.13] - 2021-03-30
|
|
24
|
+
### Changed
|
|
25
|
+
- Use GitHub/Actions instead of Travis-CI.
|
|
26
|
+
- Add `--week` option to `pick` command. (#88)
|
|
27
|
+
|
|
28
|
+
### Fixed
|
|
29
|
+
- Fix issue #98: remove redundant args
|
|
30
|
+
(Rbnotes::Utils.read_multiple_timestamps). (#98)
|
|
31
|
+
- Update `textrepo`. -> 0.5.8 (#97)
|
|
32
|
+
|
|
33
|
+
## [0.4.12] - 2020-12-18
|
|
34
|
+
### Changed
|
|
35
|
+
- Make clear the spec of `list` command args. (#94)
|
|
36
|
+
- Add a feature to use a template file for `add` command. (#87)
|
|
37
|
+
- Add new keywords for `list` command. (#90)
|
|
38
|
+
- `this_month` and `last_month`
|
|
39
|
+
- Add a new option, `verbose` for `list` command. (#76)
|
|
40
|
+
|
|
41
|
+
### Fixed
|
|
42
|
+
- Fix issue #80: suppress unnecessary error message.
|
|
43
|
+
|
|
8
44
|
## [0.4.11] - 2020-12-07
|
|
9
45
|
### Added
|
|
10
46
|
- Add a new command `statistics`. (#73)
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
rbnotes (0.4.
|
|
5
|
-
textrepo (~> 0.5.
|
|
4
|
+
rbnotes (0.4.16)
|
|
5
|
+
textrepo (~> 0.5.8)
|
|
6
6
|
unicode-display_width (~> 1.7)
|
|
7
7
|
|
|
8
8
|
GEM
|
|
9
9
|
remote: https://rubygems.org/
|
|
10
10
|
specs:
|
|
11
|
-
minitest (5.14.
|
|
12
|
-
rake (13.0.
|
|
13
|
-
textrepo (0.5.
|
|
11
|
+
minitest (5.14.4)
|
|
12
|
+
rake (13.0.3)
|
|
13
|
+
textrepo (0.5.8)
|
|
14
14
|
unicode-display_width (1.7.0)
|
|
15
15
|
|
|
16
16
|
PLATFORMS
|
|
@@ -20,7 +20,7 @@ DEPENDENCIES
|
|
|
20
20
|
minitest (~> 5.0)
|
|
21
21
|
rake (~> 13.0)
|
|
22
22
|
rbnotes!
|
|
23
|
-
textrepo (~> 0.5.
|
|
23
|
+
textrepo (~> 0.5.8)
|
|
24
24
|
|
|
25
25
|
BUNDLED WITH
|
|
26
|
-
2.
|
|
26
|
+
2.2.15
|
data/README.md
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# Rbnotes
|
|
2
2
|
|
|
3
|
-
[](https://github.com/mnbi/rbnotes/actions?query=workflow%3A"Build")
|
|
4
|
+
[](https://www.codefactor.io/repository/github/mnbi/rbnotes)
|
|
4
5
|
|
|
5
6
|
Rbnotes is a simple utility to write a note in the single repository.
|
|
6
7
|
|
data/Rakefile
CHANGED
data/conf/config.yml
CHANGED
data/conf/config_deve.yml
CHANGED
data/exe/rbnotes
CHANGED
|
@@ -48,16 +48,24 @@ app = App.new
|
|
|
48
48
|
begin
|
|
49
49
|
app.parse_global_options(ARGV)
|
|
50
50
|
app.run(ARGV)
|
|
51
|
-
rescue Errno::EPIPE =>
|
|
51
|
+
rescue Errno::EPIPE => _
|
|
52
52
|
# Fix issue #61: When the pipeline which rbnotes connects is
|
|
53
53
|
# discarded by the other program, the execption was raised. It does
|
|
54
54
|
# not end abnormally for rbnotes. So, just ignores the exception.
|
|
55
55
|
exit 0
|
|
56
|
+
rescue NoArgumentError => _
|
|
57
|
+
# Fix issue #80: Typically, this error raises when a command tries
|
|
58
|
+
# to read the standard input for its arguments and gets nil. It
|
|
59
|
+
# means user wants to cancel to execute. So, just ignore the error
|
|
60
|
+
# and exit.
|
|
61
|
+
exit 0
|
|
56
62
|
rescue MissingArgumentError, MissingTimestampError,
|
|
57
63
|
NoEditorError, ProgramAbortError,
|
|
58
64
|
Textrepo::InvalidTimestampStringError,
|
|
59
65
|
InvalidTimestampPatternError,
|
|
66
|
+
InvalidTimestampPatternAsDateError,
|
|
60
67
|
NoConfFileError,
|
|
68
|
+
NoTemplateFileError,
|
|
61
69
|
ArgumentError,
|
|
62
70
|
Errno::EACCES => e
|
|
63
71
|
puts e.message
|
data/lib/rbnotes.rb
CHANGED
data/lib/rbnotes/commands/add.rb
CHANGED
|
@@ -34,19 +34,7 @@ module Rbnotes::Commands
|
|
|
34
34
|
|
|
35
35
|
def execute(args, conf)
|
|
36
36
|
@opts = {}
|
|
37
|
-
|
|
38
|
-
arg = args.shift
|
|
39
|
-
case arg
|
|
40
|
-
when "-t", "--timestamp"
|
|
41
|
-
stamp_str = args.shift
|
|
42
|
-
raise ArgumentError, "missing timestamp: %s" % args.unshift(arg) if stamp_str.nil?
|
|
43
|
-
stamp_str = complement_timestamp_pattern(stamp_str)
|
|
44
|
-
@opts[:timestamp] = Textrepo::Timestamp.parse_s(stamp_str)
|
|
45
|
-
else
|
|
46
|
-
args.unshift(arg)
|
|
47
|
-
break
|
|
48
|
-
end
|
|
49
|
-
end
|
|
37
|
+
parse_opts(args)
|
|
50
38
|
|
|
51
39
|
stamp = @opts[:timestamp] || Textrepo::Timestamp.new(Time.now)
|
|
52
40
|
|
|
@@ -54,7 +42,8 @@ module Rbnotes::Commands
|
|
|
54
42
|
editor = Rbnotes.utils.find_program(candidates)
|
|
55
43
|
raise Rbnotes::NoEditorError, candidates if editor.nil?
|
|
56
44
|
|
|
57
|
-
|
|
45
|
+
template = read_template(conf)
|
|
46
|
+
tmpfile = Rbnotes.utils.run_with_tmpfile(editor, stamp.to_s, template)
|
|
58
47
|
|
|
59
48
|
unless FileTest.exist?(tmpfile)
|
|
60
49
|
puts "Cancel adding, since nothing to store"
|
|
@@ -112,7 +101,28 @@ HELP
|
|
|
112
101
|
end
|
|
113
102
|
|
|
114
103
|
# :stopdoc:
|
|
104
|
+
|
|
115
105
|
private
|
|
106
|
+
|
|
107
|
+
def parse_opts(args)
|
|
108
|
+
while args.size > 0
|
|
109
|
+
arg = args.shift
|
|
110
|
+
case arg
|
|
111
|
+
when "-t", "--timestamp"
|
|
112
|
+
stamp_str = args.shift
|
|
113
|
+
raise ArgumentError, "missing timestamp: %s" % args.unshift(arg) if stamp_str.nil?
|
|
114
|
+
stamp_str = complement_timestamp_pattern(stamp_str)
|
|
115
|
+
@opts[:timestamp] = Textrepo::Timestamp.parse_s(stamp_str)
|
|
116
|
+
when "-f", "--template-file"
|
|
117
|
+
template_path = args.shift
|
|
118
|
+
@opts[:template] = template_path
|
|
119
|
+
else
|
|
120
|
+
args.unshift(arg)
|
|
121
|
+
break
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
|
|
116
126
|
def complement_timestamp_pattern(pattern)
|
|
117
127
|
stamp_str = nil
|
|
118
128
|
case pattern.to_s.size
|
|
@@ -127,5 +137,26 @@ HELP
|
|
|
127
137
|
end
|
|
128
138
|
stamp_str
|
|
129
139
|
end
|
|
140
|
+
|
|
141
|
+
def read_template(conf)
|
|
142
|
+
template = nil
|
|
143
|
+
template_path = @opts[:template] || conf[:template]
|
|
144
|
+
|
|
145
|
+
if template_path
|
|
146
|
+
raise Rbnotes::NoTemplateFileError, template_path unless FileTest.exist?(template_path)
|
|
147
|
+
template = File.readlines(template_path, chomp: true)
|
|
148
|
+
else
|
|
149
|
+
template_path = default_template_file(conf)
|
|
150
|
+
template = File.readlines(template_path, chomp: true) if FileTest.exist?(template_path)
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
template
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
def default_template_file(conf)
|
|
157
|
+
dir = File.join(conf[:config_home], "templates")
|
|
158
|
+
File.expand_path("default.md", dir)
|
|
159
|
+
end
|
|
160
|
+
|
|
130
161
|
end
|
|
131
162
|
end
|
|
@@ -12,18 +12,7 @@ module Rbnotes::Commands
|
|
|
12
12
|
|
|
13
13
|
def execute(args, conf)
|
|
14
14
|
@opts = {}
|
|
15
|
-
|
|
16
|
-
arg = args.shift
|
|
17
|
-
case arg.to_s
|
|
18
|
-
when "" # no options
|
|
19
|
-
break
|
|
20
|
-
when "-d", "--deve-commands"
|
|
21
|
-
@opts[:print_deve_commands] = true
|
|
22
|
-
else # invalid options or args
|
|
23
|
-
args.unshift(arg)
|
|
24
|
-
raise ArgumentError, "invalid option or argument: %s" % args.join(" ")
|
|
25
|
-
end
|
|
26
|
-
end
|
|
15
|
+
parse_opts(args)
|
|
27
16
|
|
|
28
17
|
puts commands(@opts[:print_deve_commands]).join(" ")
|
|
29
18
|
end
|
|
@@ -42,8 +31,24 @@ HELP
|
|
|
42
31
|
end
|
|
43
32
|
|
|
44
33
|
# :stopdoc:
|
|
34
|
+
|
|
45
35
|
private
|
|
46
36
|
|
|
37
|
+
def parse_opts(args)
|
|
38
|
+
while args.size > 0
|
|
39
|
+
arg = args.shift
|
|
40
|
+
case arg.to_s
|
|
41
|
+
when "" # no options
|
|
42
|
+
break
|
|
43
|
+
when "-d", "--deve-commands"
|
|
44
|
+
@opts[:print_deve_commands] = true
|
|
45
|
+
else # invalid options or args
|
|
46
|
+
args.unshift(arg)
|
|
47
|
+
raise ArgumentError, "invalid option or argument: %s" % args.join(" ")
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
47
52
|
##
|
|
48
53
|
# Enumerates all command names.
|
|
49
54
|
#
|
|
@@ -29,16 +29,7 @@ module Rbnotes::Commands
|
|
|
29
29
|
|
|
30
30
|
def execute(args, conf)
|
|
31
31
|
@opts = {}
|
|
32
|
-
|
|
33
|
-
arg = args.shift
|
|
34
|
-
case arg
|
|
35
|
-
when "-m", "--use-mtime"
|
|
36
|
-
@opts[:use_mtime] = true
|
|
37
|
-
else
|
|
38
|
-
args.unshift(arg)
|
|
39
|
-
break
|
|
40
|
-
end
|
|
41
|
-
end
|
|
32
|
+
parse_opts(args)
|
|
42
33
|
|
|
43
34
|
file = args.shift
|
|
44
35
|
unless file.nil?
|
|
@@ -116,5 +107,25 @@ If birthtime is not available on the system, use mtime (modification
|
|
|
116
107
|
time).
|
|
117
108
|
HELP
|
|
118
109
|
end
|
|
110
|
+
|
|
111
|
+
# :stopdoc:
|
|
112
|
+
|
|
113
|
+
private
|
|
114
|
+
|
|
115
|
+
def parse_opts(args)
|
|
116
|
+
while args.size > 0
|
|
117
|
+
arg = args.shift
|
|
118
|
+
case arg
|
|
119
|
+
when "-m", "--use-mtime"
|
|
120
|
+
@opts[:use_mtime] = true
|
|
121
|
+
else
|
|
122
|
+
args.unshift(arg)
|
|
123
|
+
break
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
# :startdoc:
|
|
129
|
+
|
|
119
130
|
end
|
|
120
131
|
end
|
|
@@ -10,6 +10,8 @@ module Rbnotes::Commands
|
|
|
10
10
|
"List notes"
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
+
DEFAULT_BEHAVIOR = "today" # :nodoc:
|
|
14
|
+
|
|
13
15
|
##
|
|
14
16
|
# Shows a list of notes in the repository. Arguments are
|
|
15
17
|
# optional. If several args are passed, each of them must be a
|
|
@@ -24,10 +26,12 @@ module Rbnotes::Commands
|
|
|
24
26
|
#
|
|
25
27
|
# A keyword must be one of them:
|
|
26
28
|
#
|
|
27
|
-
#
|
|
28
|
-
#
|
|
29
|
-
#
|
|
30
|
-
#
|
|
29
|
+
# - "today" (or "to")
|
|
30
|
+
# - "yeasterday" (or "ye")
|
|
31
|
+
# - "this_week" (or "tw")
|
|
32
|
+
# - "last_week" (or "lw")
|
|
33
|
+
# - "this_month" (or "tm")
|
|
34
|
+
# - "last_month" (or "lm")
|
|
31
35
|
#
|
|
32
36
|
# Here is several examples of timestamp patterns.
|
|
33
37
|
#
|
|
@@ -52,38 +56,35 @@ module Rbnotes::Commands
|
|
|
52
56
|
|
|
53
57
|
def execute(args, conf)
|
|
54
58
|
@opts = {}
|
|
55
|
-
|
|
56
|
-
arg = args.shift
|
|
57
|
-
case arg
|
|
58
|
-
when "-w", "--week"
|
|
59
|
-
@opts[:enum_week] = true
|
|
60
|
-
else
|
|
61
|
-
args.unshift(arg)
|
|
62
|
-
break
|
|
63
|
-
end
|
|
64
|
-
end
|
|
59
|
+
parse_opts(args)
|
|
65
60
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
case arg.size
|
|
70
|
-
when "yyyymodd".size, "yyyymoddhhmiss".size, "yyyymoddhhmiss_sfx".size
|
|
71
|
-
stamp_str = "#{arg}000000"[0, 14]
|
|
72
|
-
timestamp = Textrepo::Timestamp.parse_s(stamp_str)
|
|
73
|
-
patterns = Rbnotes.utils.timestamp_patterns_in_week(timestamp)
|
|
74
|
-
else
|
|
75
|
-
raise InvalidTimestampPatternError,
|
|
76
|
-
"cannot convert to a date [%s]" % args.unshift(arg)
|
|
77
|
-
end
|
|
78
|
-
else
|
|
79
|
-
patterns = Rbnotes.utils.expand_keyword_in_args(args)
|
|
61
|
+
if args.empty?
|
|
62
|
+
default_behavior = conf[:list_default] || DEFAULT_BEHAVIOR
|
|
63
|
+
args << default_behavior
|
|
80
64
|
end
|
|
81
65
|
|
|
66
|
+
utils = Rbnotes.utils
|
|
67
|
+
patterns = utils.read_timestamp_patterns(args, enum_week: @opts[:enum_week])
|
|
68
|
+
|
|
82
69
|
@repo = Textrepo.init(conf)
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
70
|
+
notes = utils.find_notes(patterns, @repo)
|
|
71
|
+
output = []
|
|
72
|
+
if @opts[:verbose]
|
|
73
|
+
collect_timestamps_by_date(notes).each { |date, timestamps|
|
|
74
|
+
output << "#{date} (#{timestamps.size})"
|
|
75
|
+
timestamps.each { |timestamp|
|
|
76
|
+
pad = " "
|
|
77
|
+
output << utils.make_headline(timestamp,
|
|
78
|
+
@repo.read(timestamp), pad)
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
else
|
|
82
|
+
notes.each { |timestamp|
|
|
83
|
+
output << utils.make_headline(timestamp,
|
|
84
|
+
@repo.read(timestamp))
|
|
85
|
+
}
|
|
86
|
+
end
|
|
87
|
+
puts output
|
|
87
88
|
end
|
|
88
89
|
|
|
89
90
|
def help # :nodoc:
|
|
@@ -110,6 +111,8 @@ KEYWORD:
|
|
|
110
111
|
- "yeasterday" (or "ye")
|
|
111
112
|
- "this_week" (or "tw")
|
|
112
113
|
- "last_week" (or "lw")
|
|
114
|
+
- "this_month" (or "tm")
|
|
115
|
+
- "last_month" (or "lm")
|
|
113
116
|
|
|
114
117
|
An option "--week" is also acceptable. It specifies to enumerate all
|
|
115
118
|
days of a week. Typically, the option is used with a STAMP_PATTERN
|
|
@@ -124,5 +127,39 @@ would be as same as the KEYWORD, "this_week" was specified.
|
|
|
124
127
|
HELP
|
|
125
128
|
end
|
|
126
129
|
|
|
130
|
+
# :stopdoc:
|
|
131
|
+
|
|
132
|
+
private
|
|
133
|
+
|
|
134
|
+
def parse_opts(args)
|
|
135
|
+
while args.size > 0
|
|
136
|
+
arg = args.shift
|
|
137
|
+
case arg
|
|
138
|
+
when "-w", "--week"
|
|
139
|
+
@opts[:enum_week] = true
|
|
140
|
+
when "-v", "--verbose"
|
|
141
|
+
@opts[:verbose] = true
|
|
142
|
+
else
|
|
143
|
+
args.unshift(arg)
|
|
144
|
+
break
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
def collect_timestamps_by_date(timestamps)
|
|
150
|
+
result = {}
|
|
151
|
+
timestamps.map { |ts|
|
|
152
|
+
[ts.strftime("%Y-%m-%d"), ts]
|
|
153
|
+
}.reduce(result) { |r, pair|
|
|
154
|
+
date, stamp = pair
|
|
155
|
+
r[date] ||= []
|
|
156
|
+
r[date] << stamp
|
|
157
|
+
r
|
|
158
|
+
}
|
|
159
|
+
result
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
# :startdoc:
|
|
163
|
+
|
|
127
164
|
end
|
|
128
165
|
end
|