zoi 0.1.0 → 0.1.4

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: dcf9ada58a6c4d261304bf85581a811ca84745c1820e7f08e1141cb11f1605d8
4
- data.tar.gz: e3edf9ec712d10b3edc73b299d5144c1d6befd3e1d25810467ef5cffaf26577f
3
+ metadata.gz: dc7a5b36e248634f14b08f1253f8805a0031adeb4a1fc8de3204f2c5fb5ead75
4
+ data.tar.gz: 570d172ae486c9804f395daca114b5c5d9287ea29770550ff4e392a4aa1c359a
5
5
  SHA512:
6
- metadata.gz: 572cf635f41310c624aa38ae43dbe1b34cdf10830bcadc7367334eb463806ffc2783e847f60a5929d5014d2f7ccba895f99c37ffc751e5b676213b5b2c630e9e
7
- data.tar.gz: ca5cfb874c5e37f3028b114b5d6c77141d9a0de891f833dca34db903df10d6d10915849a49e413e2d662d9be14427e3c9bb45200fa5a61e395027483ae834f89
6
+ metadata.gz: c43de2e301a4abd44d9e490c3b6285e45ba63cc2bd778e8020172519cc9ec99cdaa94855346435394af8d86ab562c9ab9287805e2118735e05cbca997b2a19cc
7
+ data.tar.gz: 259ab4bf3026b5f9b7161d51c26f75eb4c9c4f1559860a6a7d68c008a81adf3bf1afaf606a9c54b3ebb2d86bfb4229493685eb4660a2ebee64ee007f5cd86de5
@@ -17,5 +17,7 @@ jobs:
17
17
  ruby-version: ${{ matrix.ruby }}
18
18
  - name: Install dependencies
19
19
  run: bundle install
20
+ - name: RuboCop
21
+ run: bundle exec rubocop
20
22
  - name: Run tests
21
23
  run: ruby test/*.rb
data/.rubocop.yml ADDED
@@ -0,0 +1,2 @@
1
+ inherit_gem:
2
+ rubocop-shopify: rubocop.yml
data/CHANGELOG.adoc CHANGED
@@ -1,4 +1,36 @@
1
- == 0.1.0 (July 7, 2021)
1
+ == 0.1.4 (January 6, 2022)
2
+
3
+ === Enhancements
4
+ * Add a configuration file, __~/.zoirc.json__ https://github.com/9sako6/zoi/pull/17[#17]
5
+ ** You can optionally save the settings used by zoi to a configuration file, __~/.zoirc.json__. +
6
+ The type of editor used by zoi can be specified in the __~/.zoirc.json__ file. +
7
+ The following is the example of the __~/.zoirc.json__ file.
8
+ +
9
+ [source,json]
10
+ ----
11
+ {
12
+ "editor": "code"
13
+ }
14
+ ----
15
+ +
16
+ In that case, there is no need to pass the `EDITOR` environment variable at runtime.
17
+
18
+ == 0.1.3 (September 15, 2021)
19
+
20
+ === Enhancements
21
+ * Add `memo` command https://github.com/9sako6/zoi/pull/11[#11]
22
+
23
+ == 0.1.2 (September 11, 2021)
24
+
25
+ === Enhancements
26
+ * Add `root` command https://github.com/9sako6/zoi/pull/8[#8]
27
+
28
+ == 0.1.1 (July 29, 2021)
29
+
30
+ === Bug Fixes
31
+ * Fix load error of 'pathname' library https://github.com/9sako6/zoi/pull/3[#3]
32
+
33
+ == 0.1.0 (July 29, 2021)
2
34
 
3
35
  === Enhancements
4
36
  * Add basic commands https://github.com/9sako6/zoi/pull/2[#2]
data/Gemfile CHANGED
@@ -1,15 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- source 'https://rubygems.org'
3
+ source "https://rubygems.org"
4
4
 
5
5
  gemspec
6
6
 
7
- gem 'thor'
7
+ gem "thor"
8
8
 
9
9
  group :development do
10
- gem 'rake', '~> 12.0'
10
+ gem "rake", "~> 12.0"
11
+ gem "rubocop-shopify", require: false
11
12
  end
12
13
 
13
14
  group :test do
14
- gem 'mocha'
15
+ gem "mocha"
16
+ gem "timecop"
15
17
  end
data/README.adoc CHANGED
@@ -6,10 +6,10 @@ zoi - Manage snippets
6
6
 
7
7
  == DESCRIPTION
8
8
 
9
- Manage snippets.
9
+ ‘zoi' provides a way to organize snippets. When you create a new file by `create` command, zoi makes the file under ~/zoi. When you execute `open` command, zoi create a new file and open it with your editor. If you want to list all files or all directory in ~/zoi, use `list` command.
10
10
 
11
11
  [verse]
12
- zoi c ruby/foo.rb
12
+ zoi create ruby/foo.rb
13
13
  # ~/zoi/ruby/foo.rb is created.
14
14
 
15
15
  == SYNOPSIS
@@ -18,6 +18,7 @@ zoi c ruby/foo.rb
18
18
  zoi create <filepath>
19
19
  zoi open <filepath>
20
20
  zoi list [-d]
21
+ zoi memo
21
22
  zoi root
22
23
  zoi help
23
24
 
@@ -25,15 +26,23 @@ zoi help
25
26
 
26
27
  create::
27
28
  Create a new file under zoi root directory. If the file already exists, the file isn't created. +
28
- In all cases, the full path of the file is printed to stdout.
29
+ In all cases, the full path of the file is printed to stdout. +
30
+ For example: `zoi create memo/20210101.md`
29
31
 
30
32
  open::
31
- Execute `create` command and open the file with the editor specified by `$EDITOR`. For example: `EDITOR=code zoi open foobar.rb`
33
+ Execute `create` command and open the file with the editor specified by `$EDITOR`. To open a file, set `$EDITOR`. +
34
+ For example: `EDITOR=code zoi open memo/20210101.md`
32
35
 
33
36
  list::
34
37
  List all files under zoi root directory. +
35
38
  With '-d' option, list all directories under zoi root directory.
36
39
 
40
+ memo::
41
+ Create today's memo file and open the file with the editor specified by `$EDITOR`. +
42
+ The file name is `YYYY-MM-DD.md` +
43
+ For example: `EDITOR=code zoi open memo/20210101.md` +
44
+ If it's September 9th in 2021, a new file ~/zoi/2021-09-09.md is created and is opend with the VSCode editor.
45
+
37
46
  root::
38
47
  Print zoi root directory.
39
48
 
@@ -44,14 +53,29 @@ help::
44
53
 
45
54
  gem install zoi
46
55
 
47
- == EXAMPLES
56
+ == CONFIGURATION
48
57
 
49
- Open today's memo file in VSCode.
58
+ You can optionally save the settings used by zoi to a configuration file, __~/.zoirc.json__.
50
59
 
51
- [verse]
52
- code $(date "+%Y%m%d.adoc" | zoi c)
60
+ The type of editor used by zoi can be specified in the __~/.zoirc.json__ file.
61
+
62
+ The following is the example of the __~/.zoirc.json__ file.
63
+
64
+ [source,json]
65
+ ----
66
+ {
67
+ "editor": "code"
68
+ }
69
+ ----
53
70
 
54
- A new file ~/zoi/20210727.adoc is created and is opend in VSCode.
71
+ In that case, there is no need to pass the `EDITOR` environment variable at runtime.
72
+
73
+ == EXAMPLES
74
+
75
+ * Change directories
76
+ +
77
+ [verse]
78
+ cd $(zoi list -d | fzf)
55
79
 
56
80
  == AUTHOR
57
81
 
data/Rakefile CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'bundler/gem_tasks'
4
- require 'rspec/core/rake_task'
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
5
 
6
6
  RSpec::Core::RakeTask.new(:spec)
7
7
 
data/exe/zoi CHANGED
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- require 'zoi'
4
+ require "zoi"
5
5
 
6
- args = File.pipe?(STDIN) ? ARGV + STDIN.gets.chomp.split : ARGV
6
+ args = File.pipe?($stdin) ? ARGV + $stdin.gets.chomp.split : ARGV
7
7
 
8
8
  Zoi::CLI.start(args)
data/lib/zoi/cli.rb CHANGED
@@ -1,22 +1,29 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'fileutils'
4
- require 'find'
5
- require 'open3'
6
- require 'thor'
3
+ require "date"
4
+ require "fileutils"
5
+ require "find"
6
+ require "json"
7
+ require "open3"
8
+ require "pathname"
9
+ require "thor"
7
10
 
8
11
  module Zoi
9
- ROOT_DIR_NAME = 'zoi'
12
+ ROOT_DIR_NAME = "zoi"
13
+ CONFIG_FILE_NAME = ".zoirc.json"
10
14
 
11
15
  class CLI < Thor
12
- desc 'create <filepath>', 'Create a new file under zoi root directory.'
16
+ desc "create <filepath>", "Create a new file under zoi root directory."
13
17
  def create(file_path)
14
18
  return if file_path.nil?
15
19
 
16
20
  puts create_file(file_path)
17
21
  end
18
22
 
19
- desc 'open <filepath>', 'Execute `create` command and open the file with the editor specified by $EDITOR. For example: `EDITOR=code zoi open foobar.rb`'
23
+ desc "open <filepath>", <<~DESCRIPTION
24
+ Execute `create` command and open the file with the editor specified by $EDITOR.
25
+ For example: `EDITOR=code zoi open foobar.rb`
26
+ DESCRIPTION
20
27
  def open(file_path)
21
28
  return if editor.nil? || file_path.nil?
22
29
 
@@ -27,17 +34,41 @@ module Zoi
27
34
  open_file(created_file_path)
28
35
  end
29
36
 
30
- desc 'list [-d]', 'List all files under zoi root directory.'
31
- option 'd', type: :boolean
37
+ desc "list [-d]", "List all files under zoi root directory."
38
+ option "d", type: :boolean
32
39
  def list
33
- only_directory = options['d']
40
+ only_directory = options["d"]
34
41
 
35
42
  puts(Find.find(root_path).select { |path| only_directory ? File.directory?(path) : File.file?(path) })
36
43
  end
37
44
 
45
+ desc "memo", "Create today's memo file and open the file with the editor specified by `$EDITOR`."
46
+ def memo
47
+ return if editor.nil?
48
+
49
+ created_file_path = create_file("#{Date.today}.md")
50
+
51
+ puts created_file_path
52
+
53
+ open_file(created_file_path)
54
+ end
55
+
56
+ desc "root", "Print zoi root directory."
57
+ def root_command
58
+ puts root_path
59
+ end
60
+
61
+ # NOTE: Resolve the following error.
62
+ # `"root" is a Thor reserved word and cannot be defined as command`
63
+ map "root" => "root_command"
64
+
38
65
  no_tasks do
39
66
  def editor
40
- @editor ||= ENV['EDITOR']
67
+ if File.exist?(config_file_path)
68
+ load_envs_from_config_file
69
+ end
70
+
71
+ ENV["EDITOR"]
41
72
  end
42
73
 
43
74
  def create_file(file_path)
@@ -59,6 +90,18 @@ module Zoi
59
90
  def root_path
60
91
  @root_path ||= Pathname(Dir.home).join(ROOT_DIR_NAME).to_s
61
92
  end
93
+
94
+ def config_file_path
95
+ @config_file_path ||= Pathname(Dir.home).join(CONFIG_FILE_NAME).to_s
96
+ end
97
+
98
+ def config_json
99
+ @config_json ||= JSON.parse(File.open(config_file_path, "r", &:read))
100
+ end
101
+
102
+ def load_envs_from_config_file
103
+ ENV["EDITOR"] = config_json["editor"] unless ENV["EDITOR"]
104
+ end
62
105
  end
63
106
  end
64
107
  end
data/lib/zoi/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Zoi
4
- VERSION = '0.1.0'
4
+ VERSION = "0.1.4"
5
5
  end
data/lib/zoi.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'zoi/version'
4
- require_relative 'zoi/cli.rb'
3
+ require_relative "zoi/version"
4
+ require_relative "zoi/cli"
5
5
 
6
6
  module Zoi; end
data/zoi.gemspec CHANGED
@@ -1,28 +1,28 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'lib/zoi/version'
3
+ require_relative "lib/zoi/version"
4
4
 
5
5
  Gem::Specification.new do |spec|
6
- spec.name = 'zoi'
6
+ spec.name = "zoi"
7
7
  spec.version = Zoi::VERSION
8
- spec.authors = ['9sako6']
9
- spec.email = ['31821663+9sako6@users.noreply.github.com']
8
+ spec.authors = ["9sako6"]
9
+ spec.email = ["31821663+9sako6@users.noreply.github.com"]
10
10
 
11
- spec.summary = 'management snippets'
12
- spec.description = 'management snippets'
13
- spec.homepage = 'https://github.com/9sako6/zoi'
14
- spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
11
+ spec.summary = "management snippets"
12
+ spec.description = "management snippets"
13
+ spec.homepage = "https://github.com/9sako6/zoi"
14
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
15
15
 
16
- spec.metadata['homepage_uri'] = spec.homepage
17
- spec.metadata['source_code_uri'] = 'https://github.com/9sako6/zoi'
18
- spec.metadata['changelog_uri'] = 'https://github.com/9sako6/zoi'
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = "https://github.com/9sako6/zoi"
18
+ spec.metadata["changelog_uri"] = "https://github.com/9sako6/zoi"
19
19
 
20
20
  # Specify which files should be added to the gem when it is released.
21
21
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
22
  spec.files = Dir.chdir(File.expand_path(__dir__)) do
23
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23
+ %x(git ls-files -z).split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
24
  end
25
- spec.bindir = 'exe'
25
+ spec.bindir = "exe"
26
26
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
- spec.require_paths = ['lib']
27
+ spec.require_paths = ["lib"]
28
28
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zoi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - 9sako6
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-07-29 00:00:00.000000000 Z
11
+ date: 2022-01-06 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: management snippets
14
14
  email:
@@ -20,6 +20,7 @@ extra_rdoc_files: []
20
20
  files:
21
21
  - ".github/workflows/test.yml"
22
22
  - ".gitignore"
23
+ - ".rubocop.yml"
23
24
  - CHANGELOG.adoc
24
25
  - Gemfile
25
26
  - LICENSE