rbnotes 0.4.10 → 0.4.15

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7e6de4675ffb2b409f72f240e4509a6d254793d977a8dd68cc54cf6d0c839e3d
4
- data.tar.gz: 364d4deb47d049af7145024cfb3151639ea9cf0504963c1b72e5a15e465a84a6
3
+ metadata.gz: 54f0c34e51ca307615ee9995cf7daeb2f65dff0a3aaa41df305f3414ce6e197e
4
+ data.tar.gz: 48bb529501aabc93ec78dd3fa6d984e11eb4a5dfb8e823d8ea6bdcb80e065e9c
5
5
  SHA512:
6
- metadata.gz: bf90b255e23257a921f7a9254d4df5233f97394e73368f27f6a4a8e96989fa3aa76ab55fca69b201ecd9a15264d5d07cf974ee9b745854ca80d3c962accbe37a
7
- data.tar.gz: c9fca12a0a6a71562a968775b09e3ebf7bda202ce7251666ab7b727236c47f8b5981d7ee703b94bfc22fae038cc161f76b10ed413ca28bcac3a9d9e0417f7f83
6
+ metadata.gz: b51574083b7d894773b1f597e693209ea6a152533d0035342f4e88f764ac925bf8fe1effd0b81b1a17200d1d5b6e386a0f12c4d790746aae4a6ee7896aa3b990
7
+ data.tar.gz: 59032141edc6f7335d6f6b00c76da7c64f983be04825603b9f3feaa3213e4599b55eff19744df446e5d66b1f8248c523f926a155de3a9d1a5f94a907afea7646
@@ -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
@@ -35,7 +35,6 @@ build-iPhoneSimulator/
35
35
  ## Documentation cache and generated files:
36
36
  /.yardoc/
37
37
  /_yardoc/
38
- /doc/
39
38
  /rdoc/
40
39
 
41
40
  ## Environment normalization:
data/CHANGELOG.md CHANGED
@@ -5,7 +5,51 @@ 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.
8
+ - Nothing to record here.
9
+
10
+ ## [0.4.15] - 2021-04-15
11
+ - Enable to use delimiters within a timestamp string. (#104)
12
+ - Fix issue #105: `list` ignores the 2nd arg when specified `-w`
13
+ option.
14
+
15
+ ## [0.4.14] - 2021-04-10
16
+ - Add `-n` option to `show` command. (#102)
17
+ - Fix issue #100: modify to catch Textrepo::MissingTimestampError.
18
+
19
+ ## [0.4.13] - 2021-03-30
20
+ ### Changed
21
+ - Use GitHub/Actions instead of Travis-CI.
22
+ - Add `--week` option to `pick` command. (#88)
23
+
24
+ ### Fixed
25
+ - Fix issue #98: remove redundant args
26
+ (Rbnotes::Utils.read_multiple_timestamps). (#98)
27
+ - Update `textrepo`. -> 0.5.8 (#97)
28
+
29
+ ## [0.4.12] - 2020-12-18
30
+ ### Changed
31
+ - Make clear the spec of `list` command args. (#94)
32
+ - Add a feature to use a template file for `add` command. (#87)
33
+ - Add new keywords for `list` command. (#90)
34
+ - `this_month` and `last_month`
35
+ - Add a new option, `verbose` for `list` command. (#76)
36
+
37
+ ### Fixed
38
+ - Fix issue #80: suppress unnecessary error message.
39
+
40
+ ## [0.4.11] - 2020-12-07
41
+ ### Added
42
+ - Add a new command `statistics`. (#73)
43
+ - limited features
44
+ - Add a completion file for `zsh`.
45
+ - a new file `etc/zsh/_rbnotes`
46
+
47
+ ### Changed
48
+ - Add a new option for `import` to use `mtime`. (#82)
49
+ - Add a feature to show multiple notes at once. (#79)
50
+
51
+ ### Fixed
52
+ - Fix issue #77: no error with a non-existing config file.
9
53
 
10
54
  ## [0.4.10] - 2020-11-20
11
55
  ### Added
data/Gemfile CHANGED
@@ -6,4 +6,4 @@ gemspec
6
6
  gem "rake", "~> 13.0"
7
7
  gem "minitest", "~> 5.0"
8
8
 
9
- gem 'textrepo', "~> 0.5.4"
9
+ gem 'textrepo', "~> 0.5.8"
data/Gemfile.lock CHANGED
@@ -1,16 +1,16 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rbnotes (0.4.10)
5
- textrepo (~> 0.5.4)
4
+ rbnotes (0.4.15)
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.2)
12
- rake (13.0.1)
13
- textrepo (0.5.7)
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.4)
23
+ textrepo (~> 0.5.8)
24
24
 
25
25
  BUNDLED WITH
26
- 2.1.4
26
+ 2.2.15
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # Rbnotes
2
2
 
3
- [![Build Status](https://travis-ci.org/mnbi/rbnotes.svg?branch=main)](https://travis-ci.org/mnbi/rbnotes)
3
+ [![Build Status](https://github.com/mnbi/rbnotes/workflows/Build/badge.svg)](https://github.com/mnbi/rbnotes/actions?query=workflow%3A"Build")
4
+ [![CodeFactor](https://www.codefactor.io/repository/github/mnbi/rbnotes/badge)](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
@@ -25,6 +25,6 @@ require "rdoc/task"
25
25
 
26
26
  RDoc::Task.new do |rdoc|
27
27
  rdoc.generator = "ri"
28
- rdoc.rdoc_dir = "doc"
28
+ rdoc.rdoc_dir = "rdoc"
29
29
  rdoc.rdoc_files.include("lib/**/*.rb")
30
30
  end
data/conf/config.yml CHANGED
@@ -5,4 +5,5 @@
5
5
  :repository_base: "~"
6
6
  :pager: "bat -l md"
7
7
  :picker: "fzf"
8
+ :picker_option: "-m"
8
9
  :editor: "/usr/local/bin/emacsclient"
data/conf/config_deve.yml CHANGED
@@ -5,4 +5,5 @@
5
5
  :repository_base: "tmp"
6
6
  :pager: "bat -l md"
7
7
  :picker: "fzf"
8
+ :picker_option: "-m"
8
9
  :editor: "/usr/local/bin/emacsclient"
@@ -0,0 +1,8 @@
1
+ ---
2
+ :run_mode: :development
3
+ :repository_type: :file_system
4
+ :repository_name: "notes"
5
+ :repository_base: "tmp"
6
+ :pager: "bat -l md"
7
+ :picker: "fzf"
8
+ :editor: "/usr/local/bin/emacsclient"
@@ -0,0 +1,7 @@
1
+ ---
2
+ :run_mode: :development
3
+ :repository_type: :file_system
4
+ :repository_name: "notes"
5
+ :repository_base: "tmp"
6
+ :pager: "bat -l md"
7
+ :editor: "/usr/local/bin/emacsclient"
@@ -0,0 +1,8 @@
1
+ ---
2
+ :run_mode: :development
3
+ :repository_type: :file_system
4
+ :repository_name: "notes"
5
+ :repository_base: "tmp"
6
+ :pager: "bat -l md"
7
+ :picker: "peco"
8
+ :editor: "/usr/local/bin/emacsclient"
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,15 +48,24 @@ app = App.new
48
48
  begin
49
49
  app.parse_global_options(ARGV)
50
50
  app.run(ARGV)
51
- rescue Errno::EPIPE => e
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,
67
+ NoConfFileError,
68
+ NoTemplateFileError,
60
69
  ArgumentError,
61
70
  Errno::EACCES => e
62
71
  puts e.message
data/lib/rbnotes.rb CHANGED
@@ -8,10 +8,6 @@ module Rbnotes
8
8
  require_relative "rbnotes/conf"
9
9
  require_relative "rbnotes/utils"
10
10
  require_relative "rbnotes/commands"
11
+ require_relative "rbnotes/statistics"
11
12
 
12
- class << self
13
- def utils
14
- Utils.instance
15
- end
16
- end
17
13
  end
@@ -61,10 +61,11 @@ Example usage:
61
61
  #{Rbnotes::NAME} commands [-d]
62
62
  #{Rbnotes::NAME} delete [TIMESTAMP]
63
63
  #{Rbnotes::NAME} export [TIMESTAMP [FILENAME]]
64
- #{Rbnotes::NAME} import FILE
64
+ #{Rbnotes::NAME} import [-m|--use-mtime] FILE
65
65
  #{Rbnotes::NAME} list [STAMP_PATTERN|KEYWORD]
66
66
  #{Rbnotes::NAME} search PATTERN [STAMP_PATTERN]
67
- #{Rbnotes::NAME} show [TIMESTAMP]
67
+ #{Rbnotes::NAME} show [TIMESTAMP...]
68
+ #{Rbnotes::NAME} statistics ([-y]|[-m])
68
69
  #{Rbnotes::NAME} update [-k] [TIMESTAMP]
69
70
 
70
71
  Further help for each command:
@@ -34,19 +34,7 @@ module Rbnotes::Commands
34
34
 
35
35
  def execute(args, conf)
36
36
  @opts = {}
37
- while args.size > 0
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
- tmpfile = Rbnotes.utils.run_with_tmpfile(editor, stamp.to_s)
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
- 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
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
  #