rbnotes 0.4.7 → 0.4.12
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 +41 -1
- data/Gemfile.lock +2 -2
- 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/etc/zsh/_rbnotes +93 -0
- data/exe/rbnotes +11 -1
- data/lib/rbnotes.rb +1 -0
- data/lib/rbnotes/commands.rb +5 -3
- data/lib/rbnotes/commands/add.rb +26 -1
- data/lib/rbnotes/commands/commands.rb +121 -0
- data/lib/rbnotes/commands/help.rb +1 -38
- data/lib/rbnotes/commands/import.rb +26 -5
- data/lib/rbnotes/commands/list.rb +93 -10
- data/lib/rbnotes/commands/pick.rb +5 -1
- data/lib/rbnotes/commands/search.rb +5 -1
- data/lib/rbnotes/commands/show.rb +60 -15
- data/lib/rbnotes/commands/statistics.rb +55 -0
- data/lib/rbnotes/commands/update.rb +1 -1
- data/lib/rbnotes/conf.rb +25 -11
- data/lib/rbnotes/error.rb +55 -3
- data/lib/rbnotes/statistics.rb +101 -0
- data/lib/rbnotes/utils.rb +111 -25
- data/lib/rbnotes/version.rb +2 -2
- metadata +9 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 517b5866c81f76286f87b2ed7d2e695c4dd09d5c7ab86f9557079232a58fde37
|
4
|
+
data.tar.gz: 1d89412445d155501f67cd0978a8070975ed722ee7440119cf5a9ba89ca946eb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f0bab361e6f4a7f22a59433369b221b6dffc1e16b79f9d4bdc4027d78c3d61a6e949ab2b81ae1ab3be4c5d52af6bd74aed4b36c70a93f31e710a42b7bb23731
|
7
|
+
data.tar.gz: af38ba13276090ae653fee8b1b3f67f3de57596851ce8b645f4ed3463c38d71c4a950b3382bff55ad98853c42e2cb3f2df0e7e7652f756f385d53ef15f917085
|
data/CHANGELOG.md
CHANGED
@@ -7,6 +7,46 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
|
|
7
7
|
## [Unreleased]
|
8
8
|
Nothing to record here.
|
9
9
|
|
10
|
+
## [0.4.12] - 2020-12-18
|
11
|
+
### Changed
|
12
|
+
- Make clear the spec of `list` command args. (#94)
|
13
|
+
- Add a feature to use a template file for `add` command. (#87)
|
14
|
+
- Add new keywords for `list` command. (#90)
|
15
|
+
- `this_month` and `last_month`
|
16
|
+
- Add a new option, `verbose` for `list` command. (#76)
|
17
|
+
|
18
|
+
### Fixed
|
19
|
+
- Fix issue #80: suppress unnecessary error message.
|
20
|
+
|
21
|
+
## [0.4.11] - 2020-12-07
|
22
|
+
### Added
|
23
|
+
- Add a new command `statistics`. (#73)
|
24
|
+
- limited features
|
25
|
+
- Add a completion file for `zsh`.
|
26
|
+
- a new file `etc/zsh/_rbnotes`
|
27
|
+
|
28
|
+
### Changed
|
29
|
+
- Add a new option for `import` to use `mtime`. (#82)
|
30
|
+
- Add a feature to show multiple notes at once. (#79)
|
31
|
+
|
32
|
+
### Fixed
|
33
|
+
- Fix issue #77: no error with a non-existing config file.
|
34
|
+
|
35
|
+
## [0.4.10] - 2020-11-20
|
36
|
+
### Added
|
37
|
+
- Add a new command `commands` to show all command names. (#71)
|
38
|
+
|
39
|
+
### Fixed
|
40
|
+
- Fix issue #69: crashes with invalid timestamp pattern.
|
41
|
+
|
42
|
+
## [0.4.9] - 2020-11-17
|
43
|
+
### Added
|
44
|
+
- Add a new option `--week` to the `list` command. (#67)
|
45
|
+
|
46
|
+
## [0.4.8] - 2020-11-16
|
47
|
+
### Fixed
|
48
|
+
- Fix issue #65: messy output of the `search` command.
|
49
|
+
|
10
50
|
## [0.4.7] - 2020-11-15
|
11
51
|
### Changed
|
12
52
|
- Beautify output of the `search` command. (#63)
|
@@ -35,7 +75,7 @@ Nothing to record here.
|
|
35
75
|
- Add individual help for each command. (#42)
|
36
76
|
|
37
77
|
### Fixed
|
38
|
-
- Fix `add` fails without modification
|
78
|
+
- Fix issue #48: `add` fails without modification.
|
39
79
|
|
40
80
|
## [0.4.2] - 2020-11-05
|
41
81
|
### Changed
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rbnotes (0.4.
|
4
|
+
rbnotes (0.4.12)
|
5
5
|
textrepo (~> 0.5.4)
|
6
6
|
unicode-display_width (~> 1.7)
|
7
7
|
|
@@ -10,7 +10,7 @@ GEM
|
|
10
10
|
specs:
|
11
11
|
minitest (5.14.2)
|
12
12
|
rake (13.0.1)
|
13
|
-
textrepo (0.5.
|
13
|
+
textrepo (0.5.7)
|
14
14
|
unicode-display_width (1.7.0)
|
15
15
|
|
16
16
|
PLATFORMS
|
data/conf/config.yml
CHANGED
data/conf/config_deve.yml
CHANGED
data/etc/zsh/_rbnotes
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
#compdef rbnotes
|
2
|
+
|
3
|
+
local __rbnotes_cmd __rbnotes_debug
|
4
|
+
|
5
|
+
__rbnotes_process() {
|
6
|
+
}
|
7
|
+
|
8
|
+
function _rbnotes() {
|
9
|
+
local context curcontext=$curcontext stat line
|
10
|
+
typeset -A opt_args
|
11
|
+
local ret=1
|
12
|
+
|
13
|
+
_arguments \
|
14
|
+
-C \
|
15
|
+
'(- *)'{-v,--version}'[print version]' \
|
16
|
+
'(- *)'{-h,--help}'[show help]' \
|
17
|
+
'(- *)'{-c,--conf}'[config file]: :->conffile' \
|
18
|
+
'1: :__rbnotes_commands' \
|
19
|
+
'*:: :->args'
|
20
|
+
|
21
|
+
case $state in
|
22
|
+
(conffile)
|
23
|
+
_files -g "*.yml" && ret=0
|
24
|
+
;;
|
25
|
+
(args)
|
26
|
+
case $words[1] in
|
27
|
+
(add)
|
28
|
+
_arguments \
|
29
|
+
-C \
|
30
|
+
'(-t --timestamp)'{-t,--timestamp}'[set timestamp]' \
|
31
|
+
'(-)*:: :->null_state' \
|
32
|
+
&& ret=0
|
33
|
+
;;
|
34
|
+
(export)
|
35
|
+
_directories && ret=0
|
36
|
+
;;
|
37
|
+
(help)
|
38
|
+
_arguments \
|
39
|
+
-C \
|
40
|
+
'1: :__rbnotes_commands' \
|
41
|
+
&& ret=0
|
42
|
+
;;
|
43
|
+
(import)
|
44
|
+
_files -g '*.md' && ret=0
|
45
|
+
;;
|
46
|
+
(list|pick)
|
47
|
+
_arguments \
|
48
|
+
-C \
|
49
|
+
'1: :__rbnotes_list_keywords' \
|
50
|
+
&& ret=0
|
51
|
+
;;
|
52
|
+
(update)
|
53
|
+
_arguments \
|
54
|
+
-C \
|
55
|
+
'(-k --keep)'{-k,--keep}'[keep timestamp]' \
|
56
|
+
'(-)*:: :->nul_state' \
|
57
|
+
&& ret=0
|
58
|
+
;;
|
59
|
+
esac
|
60
|
+
;;
|
61
|
+
esac
|
62
|
+
|
63
|
+
return ret
|
64
|
+
}
|
65
|
+
|
66
|
+
__rbnotes_commands() {
|
67
|
+
local -a _cmds
|
68
|
+
_cmds=( $(rbnotes commands -d) )
|
69
|
+
_describe -t commands Commands _cmds
|
70
|
+
}
|
71
|
+
|
72
|
+
__rbnotes_list_keywords() {
|
73
|
+
local -a _kw _this_month _this_year
|
74
|
+
_this_month=$(date "+%Y%m")
|
75
|
+
_last_month=$(date -v-1m "+%Y%m")
|
76
|
+
_this_year=$(date "+%Y")
|
77
|
+
_kw=(
|
78
|
+
{to,today}':Today'
|
79
|
+
{ye,yesterday}':Yesterday'
|
80
|
+
{tw,this_week}':This week'
|
81
|
+
{lw,last_week}':Last week'
|
82
|
+
"${_this_month}:This month"
|
83
|
+
"${_last_month}:Last month"
|
84
|
+
"${_this_year}:This year"
|
85
|
+
)
|
86
|
+
_describe -t keywords Keywords _kw
|
87
|
+
}
|
88
|
+
|
89
|
+
_rbnotes "$@"
|
90
|
+
|
91
|
+
# Local Variables:
|
92
|
+
# mode: shell-script
|
93
|
+
# End:
|
data/exe/rbnotes
CHANGED
@@ -48,14 +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,
|
65
|
+
InvalidTimestampPatternError,
|
66
|
+
InvalidTimestampPatternAsDateError,
|
67
|
+
NoConfFileError,
|
68
|
+
NoTemplateFileError,
|
59
69
|
ArgumentError,
|
60
70
|
Errno::EACCES => e
|
61
71
|
puts e.message
|
data/lib/rbnotes.rb
CHANGED
data/lib/rbnotes/commands.rb
CHANGED
@@ -58,13 +58,15 @@ Syntax:
|
|
58
58
|
|
59
59
|
Example usage:
|
60
60
|
#{Rbnotes::NAME} add [-t STAMP_PATTERN]
|
61
|
+
#{Rbnotes::NAME} commands [-d]
|
61
62
|
#{Rbnotes::NAME} delete [TIMESTAMP]
|
62
63
|
#{Rbnotes::NAME} export [TIMESTAMP [FILENAME]]
|
63
|
-
#{Rbnotes::NAME} import FILE
|
64
|
+
#{Rbnotes::NAME} import [-m|--use-mtime] FILE
|
64
65
|
#{Rbnotes::NAME} list [STAMP_PATTERN|KEYWORD]
|
65
66
|
#{Rbnotes::NAME} search PATTERN [STAMP_PATTERN]
|
66
|
-
#{Rbnotes::NAME} show [TIMESTAMP]
|
67
|
-
#{Rbnotes::NAME}
|
67
|
+
#{Rbnotes::NAME} show [TIMESTAMP...]
|
68
|
+
#{Rbnotes::NAME} statistics ([-y]|[-m])
|
69
|
+
#{Rbnotes::NAME} update [-k] [TIMESTAMP]
|
68
70
|
|
69
71
|
Further help for each command:
|
70
72
|
#{Rbnotes::NAME} help commands
|
data/lib/rbnotes/commands/add.rb
CHANGED
@@ -42,6 +42,9 @@ module Rbnotes::Commands
|
|
42
42
|
raise ArgumentError, "missing timestamp: %s" % args.unshift(arg) if stamp_str.nil?
|
43
43
|
stamp_str = complement_timestamp_pattern(stamp_str)
|
44
44
|
@opts[:timestamp] = Textrepo::Timestamp.parse_s(stamp_str)
|
45
|
+
when "-f", "--template-file"
|
46
|
+
template_path = args.shift
|
47
|
+
@opts[:template] = template_path
|
45
48
|
else
|
46
49
|
args.unshift(arg)
|
47
50
|
break
|
@@ -54,7 +57,8 @@ module Rbnotes::Commands
|
|
54
57
|
editor = Rbnotes.utils.find_program(candidates)
|
55
58
|
raise Rbnotes::NoEditorError, candidates if editor.nil?
|
56
59
|
|
57
|
-
|
60
|
+
template = read_template(conf)
|
61
|
+
tmpfile = Rbnotes.utils.run_with_tmpfile(editor, stamp.to_s, template)
|
58
62
|
|
59
63
|
unless FileTest.exist?(tmpfile)
|
60
64
|
puts "Cancel adding, since nothing to store"
|
@@ -127,5 +131,26 @@ HELP
|
|
127
131
|
end
|
128
132
|
stamp_str
|
129
133
|
end
|
134
|
+
|
135
|
+
def read_template(conf)
|
136
|
+
template = nil
|
137
|
+
template_path = @opts[:template] || conf[:template]
|
138
|
+
|
139
|
+
if template_path
|
140
|
+
raise Rbnotes::NoTemplateFileError, template_path unless FileTest.exist?(template_path)
|
141
|
+
template = File.readlines(template_path, chomp: true)
|
142
|
+
else
|
143
|
+
template_path = default_template_file(conf)
|
144
|
+
template = File.readlines(template_path, chomp: true) if FileTest.exist?(template_path)
|
145
|
+
end
|
146
|
+
|
147
|
+
template
|
148
|
+
end
|
149
|
+
|
150
|
+
def default_template_file(conf)
|
151
|
+
dir = File.join(conf[:config_home], "templates")
|
152
|
+
File.expand_path("default.md", dir)
|
153
|
+
end
|
154
|
+
|
130
155
|
end
|
131
156
|
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
module Rbnotes::Commands
|
2
|
+
##
|
3
|
+
# Prints all command names into a single line. When `-d` (or
|
4
|
+
# `--deve-commands`) was specified, development commands (such
|
5
|
+
# `conf`) would be also printed in addition to general commands.
|
6
|
+
|
7
|
+
class Commands < Command
|
8
|
+
|
9
|
+
def description # :nodoc:
|
10
|
+
"Print all command names into a single line"
|
11
|
+
end
|
12
|
+
|
13
|
+
def execute(args, conf)
|
14
|
+
@opts = {}
|
15
|
+
while args.size > 0
|
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
|
27
|
+
|
28
|
+
puts commands(@opts[:print_deve_commands]).join(" ")
|
29
|
+
end
|
30
|
+
|
31
|
+
def help
|
32
|
+
puts <<HELP
|
33
|
+
usage:
|
34
|
+
#{Rbnotes::NAME} [-d|--deve-commands]
|
35
|
+
|
36
|
+
Print all command names into a single line. If "-d" option (or
|
37
|
+
"--deve-commands") is specified, commands for development purpose are
|
38
|
+
also printed.
|
39
|
+
|
40
|
+
HELP
|
41
|
+
print_commands
|
42
|
+
end
|
43
|
+
|
44
|
+
# :stopdoc:
|
45
|
+
private
|
46
|
+
|
47
|
+
##
|
48
|
+
# Enumerates all command names.
|
49
|
+
#
|
50
|
+
# :call-seq:
|
51
|
+
# commands(builtins = false) -> [Array of Strings]
|
52
|
+
|
53
|
+
def commands(include_builtins = false)
|
54
|
+
names = external_commands.map { |cmd| cmd.to_s.downcase }
|
55
|
+
names += builtin_commands.map { |cmd| cmd.to_s.downcase } if include_builtins
|
56
|
+
names
|
57
|
+
end
|
58
|
+
|
59
|
+
def external_commands
|
60
|
+
Dir.glob("*.rb", :base => __dir__) { |rb|
|
61
|
+
require_relative rb
|
62
|
+
}
|
63
|
+
Rbnotes::Commands.constants.difference([:Builtins, :Command]).sort
|
64
|
+
end
|
65
|
+
|
66
|
+
def builtin_commands
|
67
|
+
Rbnotes::Commands::Builtins.constants.sort
|
68
|
+
end
|
69
|
+
|
70
|
+
def print_commands
|
71
|
+
Dir.glob("*.rb", :base => __dir__) { |rb|
|
72
|
+
require_relative rb
|
73
|
+
}
|
74
|
+
puts "#{Rbnotes::NAME.capitalize} Commands:"
|
75
|
+
print_commands_desc(external_commands)
|
76
|
+
puts
|
77
|
+
puts "for development purpose"
|
78
|
+
print_builtins_desc(builtin_commands)
|
79
|
+
end
|
80
|
+
|
81
|
+
def print_commands_desc(commands)
|
82
|
+
print_desc(Rbnotes::Commands, commands)
|
83
|
+
end
|
84
|
+
|
85
|
+
def print_builtins_desc(builtins)
|
86
|
+
print_desc(Rbnotes::Commands::Builtins, builtins)
|
87
|
+
end
|
88
|
+
|
89
|
+
class CmdNames
|
90
|
+
attr_reader :symbol, :name, :size
|
91
|
+
def initialize(cmd)
|
92
|
+
@symbol = cmd
|
93
|
+
@name = cmd.to_s.downcase
|
94
|
+
@size = name.size
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def print_desc(mod, commands)
|
99
|
+
cmds = commands.map { |cmd| CmdNames.new(cmd) }
|
100
|
+
name_part_size = cmds.map(&:size).max + 2
|
101
|
+
cmds.map { |cmd|
|
102
|
+
puts "#{spaces(4)}#{name_part(cmd.name, name_part_size)} #{desc_part(cmd.symbol, mod)}"
|
103
|
+
}
|
104
|
+
end
|
105
|
+
|
106
|
+
def name_part(name, size)
|
107
|
+
"#{name}#{spaces(size)}"[0, size]
|
108
|
+
end
|
109
|
+
|
110
|
+
def desc_part(symbol, mod)
|
111
|
+
mod.const_get(symbol, false).new.description
|
112
|
+
end
|
113
|
+
|
114
|
+
def spaces(size)
|
115
|
+
Array.new(size, " ").join
|
116
|
+
end
|
117
|
+
|
118
|
+
# :startdoc:
|
119
|
+
|
120
|
+
end
|
121
|
+
end
|
@@ -7,7 +7,7 @@ module Rbnotes::Commands
|
|
7
7
|
class Help < Command
|
8
8
|
|
9
9
|
def description # :nodoc:
|
10
|
-
"
|
10
|
+
"Print help of each command"
|
11
11
|
end
|
12
12
|
|
13
13
|
##
|
@@ -20,8 +20,6 @@ module Rbnotes::Commands
|
|
20
20
|
case cmd_name
|
21
21
|
when nil
|
22
22
|
self.help
|
23
|
-
when "commands"
|
24
|
-
print_commands
|
25
23
|
else
|
26
24
|
Commands.load(cmd_name).help
|
27
25
|
end
|
@@ -59,40 +57,5 @@ Further information:
|
|
59
57
|
HELP
|
60
58
|
end
|
61
59
|
|
62
|
-
# :stopdoc:
|
63
|
-
private
|
64
|
-
|
65
|
-
def print_commands
|
66
|
-
Dir.glob("*.rb", :base => __dir__) { |rb|
|
67
|
-
next if rb == "help.rb"
|
68
|
-
require_relative rb
|
69
|
-
}
|
70
|
-
commands = Commands.constants.difference([:Builtins, :Command])
|
71
|
-
builtins = Commands::Builtins.constants
|
72
|
-
|
73
|
-
puts "#{Rbnotes::NAME.capitalize} Commands:"
|
74
|
-
print_commands_desc(commands.sort)
|
75
|
-
puts
|
76
|
-
puts "for development purpose"
|
77
|
-
print_builtins_desc(builtins.sort)
|
78
|
-
end
|
79
|
-
|
80
|
-
def print_commands_desc(commands)
|
81
|
-
print_desc(Commands, commands)
|
82
|
-
end
|
83
|
-
|
84
|
-
def print_builtins_desc(builtins)
|
85
|
-
print_desc(Commands::Builtins, builtins)
|
86
|
-
end
|
87
|
-
|
88
|
-
def print_desc(mod, commands)
|
89
|
-
commands.map { |cmd|
|
90
|
-
name = "#{cmd.to_s.downcase} "[0, 8]
|
91
|
-
desc = mod.const_get(cmd, false).new.description
|
92
|
-
puts " #{name} #{desc}"
|
93
|
-
}
|
94
|
-
end
|
95
|
-
|
96
|
-
# :startdoc:
|
97
60
|
end
|
98
61
|
end
|