zoi 0.0.1 → 0.1.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2ccfa9bd2af8d9ab31bbdc514297d9365c38bc2421b2173093fe08fd8251d944
4
- data.tar.gz: ba885cd33410899947a601f53750527d40099859bbd505e2f6950c47da6e447f
3
+ metadata.gz: d23241852fcfd819a4d44dd63b6880aeef2ec93ba9ed7f8dcf47bb65e16d30f7
4
+ data.tar.gz: 781a1cb431cba40751192af7ff44516a03882f266272043c74606f5c7c2f5c32
5
5
  SHA512:
6
- metadata.gz: 595012ed030fcaafc09abffb41e3f02632c3249676ba14384abcf37a032709c2a2eabc39d2b4931a8ca2dbed10949d285dc3a93f4d905152c3ac85dae9e5938d
7
- data.tar.gz: f1a8b96908b12885b34697ab56580e08d81c4b51fdd3923c0cd132776b1f3531a512dc8ee5a213319fb5be4fb836f145b8212260df19c96392094582c46b421a
6
+ metadata.gz: 62fae3694797624b563eef4eda673a6de6f667f713c94b45c44316bbe3a2e9283eca30047e7c6623d1c2a394edd4aae66ce5556c515a2459fef90d204f0a1259
7
+ data.tar.gz: 89cdc3fbf4b3930370a66eff38df225adaa9cc9f1ffa6ebebf64474071ea37af7dcd90f68c10680c3eb0fc8860018447f6c7736be7e08dfa9ee6b21b1b842e37
@@ -0,0 +1,21 @@
1
+ name: Ruby
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ test:
7
+ strategy:
8
+ matrix:
9
+ os: [macos-latest, ubuntu-latest]
10
+ ruby: [2.7, 3.0]
11
+ runs-on: ${{ matrix.os }}
12
+ steps:
13
+ - uses: actions/checkout@v2
14
+ - name: Set up Ruby
15
+ uses: ruby/setup-ruby@v1
16
+ with:
17
+ ruby-version: ${{ matrix.ruby }}
18
+ - name: Install dependencies
19
+ run: bundle install
20
+ - name: Run tests
21
+ run: ruby test/*.rb
data/.gitignore CHANGED
@@ -1,2 +1,3 @@
1
1
  Gemfile.lock
2
2
  pkg
3
+ tmp/
data/CHANGELOG.adoc ADDED
@@ -0,0 +1,19 @@
1
+ == 0.1.3 (September 15, 2021)
2
+
3
+ === Enhancements
4
+ * Add `memo` command https://github.com/9sako6/zoi/pull/11[#11]
5
+
6
+ == 0.1.2 (September 11, 2021)
7
+
8
+ === Enhancements
9
+ * Add `root` command https://github.com/9sako6/zoi/pull/8[#8]
10
+
11
+ == 0.1.1 (July 29, 2021)
12
+
13
+ === Bug Fixes
14
+ * Fix load error of 'pathname' library https://github.com/9sako6/zoi/pull/3[#3]
15
+
16
+ == 0.1.0 (July 29, 2021)
17
+
18
+ === Enhancements
19
+ * Add basic commands https://github.com/9sako6/zoi/pull/2[#2]
data/Gemfile CHANGED
@@ -1,7 +1,16 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  gemspec
4
6
 
7
+ gem 'thor'
8
+
5
9
  group :development do
6
10
  gem 'rake', '~> 12.0'
7
11
  end
12
+
13
+ group :test do
14
+ gem 'mocha'
15
+ gem 'timecop'
16
+ end
data/README.adoc ADDED
@@ -0,0 +1,65 @@
1
+ = zoi(1)
2
+
3
+ == NAME
4
+
5
+ zoi - Manage snippets
6
+
7
+ == DESCRIPTION
8
+
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
+
11
+ [verse]
12
+ zoi create ruby/foo.rb
13
+ # ~/zoi/ruby/foo.rb is created.
14
+
15
+ == SYNOPSIS
16
+
17
+ [verse]
18
+ zoi create <filepath>
19
+ zoi open <filepath>
20
+ zoi list [-d]
21
+ zoi memo
22
+ zoi root
23
+ zoi help
24
+
25
+ == COMMANDS
26
+
27
+ create::
28
+ Create a new file under zoi root directory. If the file already exists, the file isn't created. +
29
+ In all cases, the full path of the file is printed to stdout. +
30
+ For example: `zoi create memo/20210101.md`
31
+
32
+ open::
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`
35
+
36
+ list::
37
+ List all files under zoi root directory. +
38
+ With '-d' option, list all directories under zoi root directory.
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 in VSCode.
45
+
46
+ root::
47
+ Print zoi root directory.
48
+
49
+ help::
50
+ Print a brief help message.
51
+
52
+ == INSTALLATION
53
+
54
+ gem install zoi
55
+
56
+ == EXAMPLES
57
+
58
+ * Change directories
59
+ +
60
+ [verse]
61
+ cd $(zoi list -d | fzf)
62
+
63
+ == AUTHOR
64
+
65
+ https://github.com/9sako6[9sako6]
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/gem_tasks'
2
4
  require 'rspec/core/rake_task'
3
5
 
data/exe/zoi CHANGED
@@ -1,13 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'zoi'
4
5
 
5
- case ARGV[0]
6
- when '-l', '--list'
7
- puts Zoi.list
8
- when '-t', '--today'
9
- puts Zoi.today_file
10
- when nil
11
- new_file_path = Zoi.create
12
- new_file_path.nil? ? nil : (puts new_file_path)
13
- end
6
+ args = File.pipe?(STDIN) ? ARGV + STDIN.gets.chomp.split : ARGV
7
+
8
+ Zoi::CLI.start(args)
data/lib/zoi/cli.rb ADDED
@@ -0,0 +1,86 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'date'
4
+ require 'fileutils'
5
+ require 'find'
6
+ require 'open3'
7
+ require 'pathname'
8
+ require 'thor'
9
+
10
+ module Zoi
11
+ ROOT_DIR_NAME = 'zoi'
12
+
13
+ class CLI < Thor
14
+ desc 'create <filepath>', 'Create a new file under zoi root directory.'
15
+ def create(file_path)
16
+ return if file_path.nil?
17
+
18
+ puts create_file(file_path)
19
+ end
20
+
21
+ desc 'open <filepath>', 'Execute `create` command and open the file with the editor specified by $EDITOR. For example: `EDITOR=code zoi open foobar.rb`'
22
+ def open(file_path)
23
+ return if editor.nil? || file_path.nil?
24
+
25
+ created_file_path = create_file(file_path)
26
+
27
+ puts created_file_path
28
+
29
+ open_file(created_file_path)
30
+ end
31
+
32
+ desc 'list [-d]', 'List all files under zoi root directory.'
33
+ option 'd', type: :boolean
34
+ def list
35
+ only_directory = options['d']
36
+
37
+ puts(Find.find(root_path).select { |path| only_directory ? File.directory?(path) : File.file?(path) })
38
+ end
39
+
40
+ desc 'memo', "Create today's memo file and open the file with the editor specified by `$EDITOR`."
41
+ def memo
42
+ return if editor.nil?
43
+
44
+ created_file_path = create_file("#{Date.today}.md")
45
+
46
+ puts created_file_path
47
+
48
+ open_file(created_file_path)
49
+ end
50
+
51
+ desc 'root', 'Print zoi root directory.'
52
+ def root_command
53
+ puts root_path
54
+ end
55
+
56
+ # NOTE: Resolve the following error.
57
+ # `"root" is a Thor reserved word and cannot be defined as command`
58
+ map 'root' => 'root_command'
59
+
60
+ no_tasks do
61
+ def editor
62
+ @editor ||= ENV['EDITOR']
63
+ end
64
+
65
+ def create_file(file_path)
66
+ file_full_path = File.join(root_path, file_path)
67
+
68
+ return file_full_path if File.exist?(file_full_path)
69
+
70
+ dir_path = File.join(root_path, File.dirname(file_path))
71
+
72
+ FileUtils.mkdir_p(dir_path)
73
+ FileUtils.touch(file_full_path)
74
+ file_full_path
75
+ end
76
+
77
+ def open_file(file_path)
78
+ system(editor, file_path)
79
+ end
80
+
81
+ def root_path
82
+ @root_path ||= Pathname(Dir.home).join(ROOT_DIR_NAME).to_s
83
+ end
84
+ end
85
+ end
86
+ end
data/lib/zoi/version.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Zoi
2
- VERSION = '0.0.1'.freeze
4
+ VERSION = '0.1.3'
3
5
  end
data/lib/zoi.rb CHANGED
@@ -1,43 +1,6 @@
1
- require 'date'
2
- require 'fileutils'
3
- require_relative 'zoi/version'
4
-
5
- module Zoi
6
- class Error < StandardError; end
7
-
8
- class << self
9
- def create
10
- FileUtils.mkdir_p(root_path)
11
-
12
- return if File.exist?(today_file)
13
-
14
- File.open(today_file, 'w') do |f|
15
- f.puts "# #{today}"
16
- end
17
-
18
- today_file
19
- end
1
+ # frozen_string_literal: true
20
2
 
21
- def list
22
- Dir.glob("#{root_path}/*")
23
- end
24
-
25
- def today_file
26
- File.join(root_path, file_name)
27
- end
28
-
29
- private
30
-
31
- def file_name
32
- "#{today}.md"
33
- end
34
-
35
- def today
36
- Date.today.strftime('%Y%m%d')
37
- end
3
+ require_relative 'zoi/version'
4
+ require_relative 'zoi/cli.rb'
38
5
 
39
- def root_path
40
- File.join(Dir.home, name.downcase)
41
- end
42
- end
43
- end
6
+ module Zoi; 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.0.1
4
+ version: 0.1.3
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-26 00:00:00.000000000 Z
11
+ date: 2021-09-15 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: management snippets
14
14
  email:
@@ -18,16 +18,16 @@ executables:
18
18
  extensions: []
19
19
  extra_rdoc_files: []
20
20
  files:
21
+ - ".github/workflows/test.yml"
21
22
  - ".gitignore"
22
- - CHANGELOG.md
23
+ - CHANGELOG.adoc
23
24
  - Gemfile
24
25
  - LICENSE
25
- - README.md
26
+ - README.adoc
26
27
  - Rakefile
27
- - bin/console
28
- - bin/setup
29
28
  - exe/zoi
30
29
  - lib/zoi.rb
30
+ - lib/zoi/cli.rb
31
31
  - lib/zoi/version.rb
32
32
  - zoi.gemspec
33
33
  homepage: https://github.com/9sako6/zoi
data/CHANGELOG.md DELETED
File without changes
data/README.md DELETED
@@ -1,35 +0,0 @@
1
- # Zoi
2
-
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/zoi`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
6
-
7
- ## Installation
8
-
9
- Add this line to your application's Gemfile:
10
-
11
- ```ruby
12
- gem 'zoi'
13
- ```
14
-
15
- And then execute:
16
-
17
- $ bundle install
18
-
19
- Or install it yourself as:
20
-
21
- $ gem install zoi
22
-
23
- ## Usage
24
-
25
- TODO: Write usage instructions here
26
-
27
- ## Development
28
-
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
-
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
-
33
- ## Contributing
34
-
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/zoi.
data/bin/console DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'bundler/setup'
4
- require 'zoi'
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require 'irb'
14
- IRB.start(__FILE__)
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here