rbnotes 0.4.8 → 0.4.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/main.yml +18 -0
- data/.gitignore +0 -1
- data/CHANGELOG.md +46 -1
- data/Gemfile +1 -1
- data/Gemfile.lock +7 -7
- data/README.md +1 -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/etc/zsh/_rbnotes +93 -0
- data/exe/rbnotes +11 -1
- data/lib/rbnotes.rb +1 -5
- 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 +73 -10
- data/lib/rbnotes/commands/pick.rb +22 -4
- 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 +207 -66
- data/lib/rbnotes/version.rb +2 -2
- data/rbnotes.gemspec +1 -1
- metadata +13 -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: 55b7ddb12d306be2cb815400d4e729deff8badfbde55ede0f9edba78c380eb44
|
4
|
+
data.tar.gz: ae0720108810db518693959f3a8faf20c7ca985d6aaf3c39bac94327d45f25db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8fc47bdc0c93bc964714c89d791655f1d385de0dfbf6af5202ec18c17f1be951efb02fcd4d9b0ac9b298cbb163e8a9e836a5c4d752bf9bad5299cc0d38983463
|
7
|
+
data.tar.gz: d2a3db96531609429775b9caf32308691afc6023ffaf2d8aae39df3d763e99b497a3efe763e821033ab725240e925ddd23a5385dac15d0a3bd5f3cb9f7c23ac1
|
@@ -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,7 +5,52 @@ 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
|
-
|
8
|
+
|
9
|
+
## [0.4.13] - 2021-03-30
|
10
|
+
### Changed
|
11
|
+
- Use GitHub/Actions instead of Travis-CI.
|
12
|
+
- Add `--week` option to `pick` command. (#88)
|
13
|
+
|
14
|
+
### Fixed
|
15
|
+
- Fix issue #98: remove redundant args
|
16
|
+
(Rbnotes::Utils.read_multiple_timestamps). (#98)
|
17
|
+
- Update `textrepo`. -> 0.5.8 (#97)
|
18
|
+
|
19
|
+
## [0.4.12] - 2020-12-18
|
20
|
+
### Changed
|
21
|
+
- Make clear the spec of `list` command args. (#94)
|
22
|
+
- Add a feature to use a template file for `add` command. (#87)
|
23
|
+
- Add new keywords for `list` command. (#90)
|
24
|
+
- `this_month` and `last_month`
|
25
|
+
- Add a new option, `verbose` for `list` command. (#76)
|
26
|
+
|
27
|
+
### Fixed
|
28
|
+
- Fix issue #80: suppress unnecessary error message.
|
29
|
+
|
30
|
+
## [0.4.11] - 2020-12-07
|
31
|
+
### Added
|
32
|
+
- Add a new command `statistics`. (#73)
|
33
|
+
- limited features
|
34
|
+
- Add a completion file for `zsh`.
|
35
|
+
- a new file `etc/zsh/_rbnotes`
|
36
|
+
|
37
|
+
### Changed
|
38
|
+
- Add a new option for `import` to use `mtime`. (#82)
|
39
|
+
- Add a feature to show multiple notes at once. (#79)
|
40
|
+
|
41
|
+
### Fixed
|
42
|
+
- Fix issue #77: no error with a non-existing config file.
|
43
|
+
|
44
|
+
## [0.4.10] - 2020-11-20
|
45
|
+
### Added
|
46
|
+
- Add a new command `commands` to show all command names. (#71)
|
47
|
+
|
48
|
+
### Fixed
|
49
|
+
- Fix issue #69: crashes with invalid timestamp pattern.
|
50
|
+
|
51
|
+
## [0.4.9] - 2020-11-17
|
52
|
+
### Added
|
53
|
+
- Add a new option `--week` to the `list` command. (#67)
|
9
54
|
|
10
55
|
## [0.4.8] - 2020-11-16
|
11
56
|
### Fixed
|
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.13)
|
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.3
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Rbnotes
|
2
2
|
|
3
|
-
[![Build Status](https://
|
3
|
+
[![Build Status](https://github.com/mnbi/rbnotes/workflows/Build/badge.svg)](https://github.com/mnbi/rbnotes/actions?query=workflow%3A"Build")
|
4
4
|
|
5
5
|
Rbnotes is a simple utility to write a note in the single repository.
|
6
6
|
|
data/Rakefile
CHANGED
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
|