flexdot 3.1.0 → 3.2.0

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: 5d1b112b651204f8ce82ddad718e2b6673e7c0d898704b7e43aea5328040c869
4
- data.tar.gz: 917fb9ffe2100da70b42dc5f96666104bea4f603aa71026e2aaaa497f5e220e5
3
+ metadata.gz: fbeccda096b5cffa6592e2fd044091357384a1be8eed6d692f2ddfd8e7b6cb3e
4
+ data.tar.gz: cb0bb15f3a618e50ebe0c4e5db1fc325e426ba357f4ccfbddfd5110ec263a172
5
5
  SHA512:
6
- metadata.gz: 9718bc11bcc0181d8803b91fc62f54d515cdb52b49aa8629239ffe841eac8f7edc867bcbaae547648c1ffbe3a0f2334628eabc3cd40c8c4e71b03c4e56c8a1a3
7
- data.tar.gz: '08e880cd0f2e81ad725b2057dcfb50fac18a6c1fa93b72e41d6f453a1d33883b3fcb25d68252f187f6fbaa966640c2dfac2b044f52a677dc8f045f609bfa7d2b'
6
+ metadata.gz: 93df4b1412f1fbaccc3a242f68a569955435e2271d9cab0de29ec62cd04d760997162bb81fb1573454d837d29ba34606e6ef9a8d83b0c07cab5238c28cbfa62b
7
+ data.tar.gz: 89284ebc88a5c475e53e80a6049bfa2bd37d498bf4a600ecd9ba1637a5c170951a9aa6be749e72adef587b691865c686a2ae834ea973f78674f1e32effd56a54
data/README.md CHANGED
@@ -48,6 +48,11 @@ Flexdot.setup(
48
48
  # The dotfile directory path.
49
49
  # Default '.'.
50
50
  dotfiles_dir: '.'
51
+
52
+ # (optional)
53
+ # Whether or not to colorize the output
54
+ # Default: true
55
+ output_colorize: true
51
56
  )
52
57
  ```
53
58
 
@@ -224,17 +229,17 @@ Or,
224
229
  The following is the output result:
225
230
 
226
231
  ```
227
- [already_linked] bin/git-delete-other-branches
228
- [already_linked] bin/git-reset-and-clean
229
- [already_linked] .config/git/ignore
230
- [already_linked] .gemrc
231
- [already_linked] .vimrc
232
- [link_created] .bash_profile (backup)
233
- [link_created] .bashrc (backup)
234
- [link_created] .gitconfig (backup)
235
- [link_created] .config/karabiner/assets/complex_modifications/tab-emulation.json (backup)
236
- [link_created] Library/Application Support/Code/User/keybindings.json (backup)
237
- [link_created] Library/Application Support/Code/User/settings.json (backup)
232
+ already linked: bin/git-delete-other-branches
233
+ already linked: bin/git-reset-and-clean
234
+ already linked: .config/git/ignore
235
+ already linked: .gemrc
236
+ already linked: .vimrc
237
+ link created: .bash_profile (backup)
238
+ link created: .bashrc (backup)
239
+ link created: .gitconfig (backup)
240
+ link created: .config/karabiner/assets/complex_modifications/tab-emulation.json (backup)
241
+ link created: Library/Application Support/Code/User/keybindings.json (backup)
242
+ link created: Library/Application Support/Code/User/settings.json (backup)
238
243
  ```
239
244
 
240
245
  `already_linked` means skipped because `bin/git-delete-other-branches` is already linked. `link_created` means the link was created.
data/flexdot.gemspec CHANGED
@@ -18,4 +18,5 @@ Gem::Specification.new do |spec|
18
18
  spec.require_paths = ['lib']
19
19
 
20
20
  spec.add_dependency 'rake', '>= 12.0'
21
+ spec.add_dependency 'paint', '>= 2.2.1'
21
22
  end
@@ -2,18 +2,18 @@
2
2
 
3
3
  require 'yaml'
4
4
 
5
- require_relative 'console'
5
+ require_relative 'output'
6
6
  require_relative 'backup'
7
7
  require_relative 'index'
8
8
 
9
9
  module Flexdot
10
10
  class Installer
11
- def initialize(name, dotfiles_dir:, home_dir:)
11
+ def initialize(name, dotfiles_dir, home_dir, output_colorize)
12
12
  @name = name
13
13
  @dotfiles_dir = dotfiles_dir
14
14
  @home_dir = home_dir
15
15
  @backup = Backup.new
16
- @console = Console.new(@home_dir)
16
+ @output = Output.new(@home_dir, colorize: output_colorize)
17
17
  end
18
18
 
19
19
  def install(index_file)
@@ -27,13 +27,13 @@ module Flexdot
27
27
 
28
28
  private
29
29
 
30
- attr_reader :name, :dotfiles_dir, :home_dir, :backup, :console
30
+ attr_reader :name, :dotfiles_dir, :home_dir, :backup, :output
31
31
 
32
32
  def install_link(dotfile_path, home_file_path)
33
33
  dotfile = @dotfiles_dir.join(dotfile_path).expand_path
34
34
  home_file = @home_dir.join(home_file_path, dotfile.basename).expand_path
35
35
 
36
- console.log(home_file) do |status|
36
+ output.log(home_file) do |status|
37
37
  if home_file.symlink?
38
38
  if home_file.readlink == dotfile
39
39
  status.result = :already_linked
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'paint'
4
+
5
+ module Flexdot
6
+ class Output
7
+ Status = Struct.new(:home_file, :result, :backuped)
8
+
9
+ def initialize(dotfiles_dir, colorize: true)
10
+ @dotfiles_dir = dotfiles_dir
11
+ @colorize = colorize
12
+ end
13
+
14
+ def log(home_file)
15
+ status = Status.new(home_file)
16
+ yield(status)
17
+ puts message_for(status)
18
+ end
19
+
20
+ private
21
+
22
+ attr_reader :dotfiles_dir
23
+
24
+ def message_for(status)
25
+ result_color =
26
+ case status.result
27
+ when :already_linked then :gray
28
+ when :link_updated then :yellow
29
+ when :link_created then :green
30
+ else :default
31
+ end
32
+
33
+ msg = []
34
+ msg << paint("#{status.result.to_s.gsub('_', ' ')}:", result_color)
35
+ msg << status.home_file.relative_path_from(dotfiles_dir)
36
+ msg << '(backup)' if status.backuped
37
+ msg.join(' ')
38
+ end
39
+
40
+ def paint(string, *colors)
41
+ colorize? ? Paint[string, *colors] : string
42
+ end
43
+
44
+ def colorize?
45
+ @colorize
46
+ end
47
+ end
48
+ end
data/lib/flexdot/tasks.rb CHANGED
@@ -10,9 +10,10 @@ module Flexdot
10
10
 
11
11
  Index = Struct.new(:filename, :name, keyword_init: true)
12
12
 
13
- def initialize(dotfiles_dir, home_dir)
13
+ def initialize(dotfiles_dir, home_dir, output_colorize)
14
14
  @dotfiles_dir = Pathname.new(dotfiles_dir).expand_path
15
15
  @home_dir = Pathname.new(home_dir).expand_path
16
+ @output_colorize = output_colorize
16
17
  end
17
18
 
18
19
  def install
@@ -27,8 +28,9 @@ module Flexdot
27
28
  task index.name do
28
29
  installer = Installer.new(
29
30
  index.name,
30
- dotfiles_dir: dotfiles_dir,
31
- home_dir: home_dir
31
+ dotfiles_dir,
32
+ home_dir,
33
+ output_colorize
32
34
  )
33
35
  installer.install(index.filename)
34
36
  end
@@ -38,7 +40,7 @@ module Flexdot
38
40
 
39
41
  private
40
42
 
41
- attr_reader :dotfiles_dir, :home_dir
43
+ attr_reader :dotfiles_dir, :home_dir, :output_colorize
42
44
 
43
45
  def indexes
44
46
  @indexes ||= Pathname.new(dotfiles_dir).glob('*.yml').map do |index_file|
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Flexdot
4
- VERSION = '3.1.0'
4
+ VERSION = '3.2.0'
5
5
  end
data/lib/flexdot.rb CHANGED
@@ -6,7 +6,7 @@ require_relative 'flexdot/version'
6
6
  require_relative 'flexdot/tasks'
7
7
 
8
8
  module Flexdot
9
- def self.setup(home_dir:, dotfiles_dir: '.')
10
- Tasks.new(dotfiles_dir, home_dir).install
9
+ def self.setup(home_dir:, dotfiles_dir: '.', output_colorize: true)
10
+ Tasks.new(dotfiles_dir, home_dir, output_colorize).install
11
11
  end
12
12
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flexdot
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
4
+ version: 3.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Katsuya Hidaka
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-18 00:00:00.000000000 Z
11
+ date: 2021-08-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '12.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: paint
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 2.2.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 2.2.1
27
41
  description: Flexdot is a Flexible and Rake based dotfile manager
28
42
  email:
29
43
  - hidakatsuya@gmail.com
@@ -43,9 +57,9 @@ files:
43
57
  - flexdot.gemspec
44
58
  - lib/flexdot.rb
45
59
  - lib/flexdot/backup.rb
46
- - lib/flexdot/console.rb
47
60
  - lib/flexdot/index.rb
48
61
  - lib/flexdot/installer.rb
62
+ - lib/flexdot/output.rb
49
63
  - lib/flexdot/tasks.rb
50
64
  - lib/flexdot/version.rb
51
65
  homepage: https://github.com/hidakatsuya/flexdot
@@ -1,29 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Flexdot
4
- class Console
5
- Status = Struct.new(:home_file, :result, :backuped)
6
-
7
- def initialize(dotfiles_dir)
8
- @dotfiles_dir = dotfiles_dir
9
- end
10
-
11
- def log(home_file)
12
- status = Status.new(home_file)
13
- yield(status)
14
- puts message_for(status)
15
- end
16
-
17
- private
18
-
19
- attr_reader :dotfiles_dir
20
-
21
- def message_for(status)
22
- [].tap { |msg|
23
- msg << "[#{status.result}]"
24
- msg << status.home_file.relative_path_from(dotfiles_dir)
25
- msg << '(backup)' if status.backuped
26
- }.join(' ')
27
- end
28
- end
29
- end