flexdot 1.0.2 → 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: 1cce20c75873ecb10cd057fa7e02177580915e399768e6e2b24a908924717d99
4
- data.tar.gz: 89328d00bc1991493907c2ec558662d4ada76110e6d33052eeaa521ecac64e22
3
+ metadata.gz: fbeccda096b5cffa6592e2fd044091357384a1be8eed6d692f2ddfd8e7b6cb3e
4
+ data.tar.gz: cb0bb15f3a618e50ebe0c4e5db1fc325e426ba357f4ccfbddfd5110ec263a172
5
5
  SHA512:
6
- metadata.gz: 8ba2f0a613eff80271375c8a1eaee73af9e3f573c2ae08ca86b61eff337a4363d55b5d9b45a8212d3b75ad5536215105541f9430910eed87708ec8ca3f583838
7
- data.tar.gz: 3a06a1a126bf0beec0a9b9c7d72f5d96c8778a926d242dc0ed74db0ea198b0a8e6d30c0b64c8a4f40be7525ce731eefec6fe7251a8ac3ad0ad5ab4fef0789013
6
+ metadata.gz: 93df4b1412f1fbaccc3a242f68a569955435e2271d9cab0de29ec62cd04d760997162bb81fb1573454d837d29ba34606e6ef9a8d83b0c07cab5238c28cbfa62b
7
+ data.tar.gz: 89284ebc88a5c475e53e80a6049bfa2bd37d498bf4a600ecd9ba1637a5c170951a9aa6be749e72adef587b691865c686a2ae834ea973f78674f1e32effd56a54
@@ -0,0 +1,11 @@
1
+ # To get started with Dependabot version updates, you'll need to specify which
2
+ # package ecosystems to update and where the package manifests are located.
3
+ # Please see the documentation for all configuration options:
4
+ # https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5
+
6
+ version: 2
7
+ updates:
8
+ - package-ecosystem: "bundler"
9
+ directory: "/"
10
+ schedule:
11
+ interval: "daily"
@@ -7,20 +7,27 @@ jobs:
7
7
  test:
8
8
  name: Test on ruby ${{ matrix.ruby_version }}
9
9
  runs-on: ubuntu-latest
10
+ # Run this build only on either pull request or push.
11
+ if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
12
+
10
13
  strategy:
11
14
  matrix:
12
15
  ruby_version:
13
- - 2.5.x
14
- - 2.6.x
15
- - 2.7.x
16
+ - 2.6
17
+ - 2.7
18
+ - 3.0
16
19
  steps:
17
- - uses: actions/checkout@v1
20
+ - uses: actions/checkout@v2
21
+
18
22
  - name: Set up Ruby ${{ matrix.ruby_version }}
19
- uses: actions/setup-ruby@v1
23
+ uses: ruby/setup-ruby@v1
20
24
  with:
21
25
  ruby-version: ${{ matrix.ruby_version }}
22
- - name: Build and test with Rake
26
+
27
+ - name: Install dependencies
23
28
  run: |
24
29
  gem install bundler
25
30
  bundle install --jobs 4 --retry 3
26
- bundle exec rake test
31
+
32
+ - name: Run tests
33
+ run: bundle exec rake test
data/.gitignore CHANGED
@@ -8,5 +8,5 @@
8
8
  /tmp/
9
9
  /Gemfile.lock
10
10
 
11
- /test/home/*
12
- !/test/home/dotfiles/*
11
+ /test/tasks/home/*
12
+ !/test/tasks/home/dotfiles/*
data/CHANGELOG.md ADDED
@@ -0,0 +1 @@
1
+ Please see [the release page](https://github.com/hidakatsuya/flexdot/releases).
data/Gemfile CHANGED
@@ -2,5 +2,4 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
- gem 'rake', '>= 12.0'
6
5
  gem 'minitest', '~> 5.0'
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  # Flexdot
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/flexdot.svg)](https://badge.fury.io/rb/flexdot)
3
4
  [![Test](https://github.com/hidakatsuya/flexdot/workflows/Test/badge.svg?branch=master)](https://github.com/hidakatsuya/flexdot/actions?query=workflow%3ATest)
4
5
 
5
6
  A Flexible and Rake based dotfile manager.
@@ -8,32 +9,60 @@ A Flexible and Rake based dotfile manager.
8
9
 
9
10
  ### Prerequisite
10
11
 
11
- Ruby 2.5+
12
+ Ruby 2.6+
12
13
 
13
14
  ### Installing
14
15
 
15
- Install it as:
16
-
17
- $ gem install flexdot
18
-
19
- Then, create the following directory structure:
16
+ Create the following directory structure:
20
17
 
21
18
  ```
22
19
  $HOME/
23
- dotfiles/
20
+ ├── dotfiles/
21
+ :
22
+ ```
23
+
24
+ Create a `Gemfile` to install Flexdot:
25
+
26
+ $ cd $HOME/dotfiles
27
+ $ bundle init
28
+
29
+ Add this line to the `Gemfile`:
30
+
31
+ ```ruby
32
+ gem 'flexdot'
24
33
  ```
25
34
 
26
- Create a `$HOME/dotfiles/Rakefile` with the following codes:
35
+ Or install it yourself as:
36
+
37
+ $ gem install flexdot
38
+
39
+ Then, create a `$HOME/dotfiles/Rakefile` with the following codes:
27
40
 
28
41
  ```ruby
29
42
  require 'flexdot'
30
43
 
31
- Flexdot.install_tasks(
32
- base_dir: '.', # $HOME/dotfiles/
33
- target_dir: '/home/username' # $HOME/
44
+ Flexdot.setup(
45
+ home_dir: '/home/username',
46
+
47
+ # (optional)
48
+ # The dotfile directory path.
49
+ # Default '.'.
50
+ dotfiles_dir: '.'
51
+
52
+ # (optional)
53
+ # Whether or not to colorize the output
54
+ # Default: true
55
+ output_colorize: true
34
56
  )
35
57
  ```
36
58
 
59
+ It is recommended that you add the Rakefile to `gitignore`:
60
+
61
+ ```
62
+ # .gitignore
63
+ Rakefile
64
+ ```
65
+
37
66
  Finally, run `rake -T` in the `$HOME/dotfiles` and make sure that the output is as follows:
38
67
 
39
68
  $ rake -T
@@ -94,6 +123,20 @@ $HOME/dotfiles
94
123
  └── Rakefile
95
124
  ```
96
125
 
126
+ ### Rakefile
127
+
128
+ ```ruby
129
+ require 'flexdot'
130
+
131
+ Flexdot.setup(
132
+ home_dir: '..'
133
+ )
134
+
135
+ # You can execute `install:macOS` when you run `rake` command
136
+ # with no arguments by defining it as follows:
137
+ task default: 'install:macOS'
138
+ ```
139
+
97
140
  ### Available Commands
98
141
 
99
142
  When you run the `rake -T` command in that directory structure, you should have two installation commands available:
@@ -175,24 +218,28 @@ ubuntu:
175
218
  stop.sh: .xkeysnail
176
219
  ```
177
220
 
178
- ### Installing dotfiles
221
+ ### Installing dotfiles for macOS
222
+
223
+ $ rake
224
+
225
+ Or,
179
226
 
180
227
  $ rake install:macOS
181
228
 
182
229
  The following is the output result:
183
230
 
184
231
  ```
185
- [already_linked] bin/git-delete-other-branches
186
- [already_linked] bin/git-reset-and-clean
187
- [already_linked] .config/git/ignore
188
- [already_linked] .gemrc
189
- [already_linked] .vimrc
190
- [link_created] .bash_profile (backup)
191
- [link_created] .bashrc (backup)
192
- [link_created] .gitconfig (backup)
193
- [link_created] .config/karabiner/assets/complex_modifications/tab-emulation.json (backup)
194
- [link_created] Library/Application Support/Code/User/keybindings.json (backup)
195
- [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)
196
243
  ```
197
244
 
198
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
@@ -10,10 +10,13 @@ Gem::Specification.new do |spec|
10
10
  spec.description = 'Flexdot is a Flexible and Rake based dotfile manager'
11
11
  spec.homepage = 'https://github.com/hidakatsuya/flexdot'
12
12
  spec.license = 'MIT'
13
- spec.required_ruby_version = Gem::Requirement.new('>= 2.5.0')
13
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.6.0')
14
14
 
15
15
  spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
16
16
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test)/}) }
17
17
  end
18
18
  spec.require_paths = ['lib']
19
+
20
+ spec.add_dependency 'rake', '>= 12.0'
21
+ spec.add_dependency 'paint', '>= 2.2.1'
19
22
  end
@@ -7,6 +7,8 @@ module Flexdot
7
7
  class Backup
8
8
  BASE_DIR = 'backup'
9
9
 
10
+ class AlreadyFinishedError < StandardError; end
11
+
10
12
  class << self
11
13
  def clear_all
12
14
  base_dir.glob('*').each(&:rmtree)
@@ -19,12 +21,19 @@ module Flexdot
19
21
 
20
22
  def initialize
21
23
  backup_dir.mkpath unless backup_dir.exist?
24
+ @finished = false
22
25
  end
23
26
 
24
27
  def call(file)
28
+ raise AlreadyFinishedError if @finished
25
29
  FileUtils.mv(file, backup_dir)
26
30
  end
27
31
 
32
+ def finish!
33
+ backup_dir.delete if backup_dir.empty?
34
+ @finished = true
35
+ end
36
+
28
37
  private
29
38
 
30
39
  def backup_dir
data/lib/flexdot/index.rb CHANGED
@@ -21,7 +21,7 @@ module Flexdot
21
21
  dotfile_path = paths + [k]
22
22
  case v
23
23
  when String
24
- block.call(dotfile_path: File.join(*dotfile_path), target_path: v)
24
+ block.call(dotfile_path: File.join(*dotfile_path), home_file_path: v)
25
25
  when Hash
26
26
  fetch_descendants(v, paths: dotfile_path, &block)
27
27
  else
@@ -2,53 +2,55 @@
2
2
 
3
3
  require 'yaml'
4
4
 
5
- require_relative 'logger'
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, base_dir:, target_dir:)
11
+ def initialize(name, dotfiles_dir, home_dir, output_colorize)
12
12
  @name = name
13
- @base_dir = base_dir
14
- @target_dir = target_dir
13
+ @dotfiles_dir = dotfiles_dir
14
+ @home_dir = home_dir
15
15
  @backup = Backup.new
16
- @logger = Logger.new(@target_dir)
16
+ @output = Output.new(@home_dir, colorize: output_colorize)
17
17
  end
18
18
 
19
19
  def install(index_file)
20
20
  index = Index.new(YAML.load_file(index_file.to_path))
21
- index.each do |dotfile_path:, target_path:|
22
- install_link(dotfile_path, target_path)
21
+ index.each do |dotfile_path:, home_file_path:|
22
+ install_link(dotfile_path, home_file_path)
23
23
  end
24
+
25
+ backup.finish!
24
26
  end
25
27
 
26
28
  private
27
29
 
28
- attr_reader :name, :base_dir, :target_dir, :backup, :logger
30
+ attr_reader :name, :dotfiles_dir, :home_dir, :backup, :output
29
31
 
30
- def install_link(dotfile_path, target_path)
31
- dotfile = @base_dir.join(dotfile_path).expand_path
32
- target_file = @target_dir.join(target_path, dotfile.basename).expand_path
32
+ def install_link(dotfile_path, home_file_path)
33
+ dotfile = @dotfiles_dir.join(dotfile_path).expand_path
34
+ home_file = @home_dir.join(home_file_path, dotfile.basename).expand_path
33
35
 
34
- logger.log(target_file) do |status|
35
- if target_file.symlink?
36
- if target_file.readlink == dotfile
36
+ output.log(home_file) do |status|
37
+ if home_file.symlink?
38
+ if home_file.readlink == dotfile
37
39
  status.result = :already_linked
38
40
  else
39
- target_file.unlink
40
- target_file.make_symlink(dotfile.to_path)
41
+ home_file.unlink
42
+ home_file.make_symlink(dotfile.to_path)
41
43
  status.result = :link_updated
42
44
  end
43
45
  else
44
- if target_file.exist?
45
- backup.call(target_file)
46
+ if home_file.exist?
47
+ backup.call(home_file)
46
48
  status.backuped = true
47
- elsif !target_file.dirname.exist?
48
- target_file.dirname.mkpath
49
+ elsif !home_file.dirname.exist?
50
+ home_file.dirname.mkpath
49
51
  end
50
52
 
51
- target_file.make_symlink(dotfile.to_path)
53
+ home_file.make_symlink(dotfile.to_path)
52
54
  status.result = :link_created
53
55
  end
54
56
  end
@@ -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
@@ -8,9 +8,12 @@ module Flexdot
8
8
  class Tasks
9
9
  include Rake::DSL
10
10
 
11
- def initialize(base_dir, target_dir)
12
- @base_dir = Pathname.new(base_dir)
13
- @target_dir = Pathname.new(target_dir)
11
+ Index = Struct.new(:filename, :name, keyword_init: true)
12
+
13
+ def initialize(dotfiles_dir, home_dir, output_colorize)
14
+ @dotfiles_dir = Pathname.new(dotfiles_dir).expand_path
15
+ @home_dir = Pathname.new(home_dir).expand_path
16
+ @output_colorize = output_colorize
14
17
  end
15
18
 
16
19
  def install
@@ -20,17 +23,16 @@ module Flexdot
20
23
  end
21
24
 
22
25
  namespace :install do
23
- Pathname.new(base_dir).glob('*.yml') do |index_file|
24
- name = index_file.basename('.*')
25
-
26
- desc "Install dotfiles for #{name}"
27
- task name do
26
+ indexes.each do |index|
27
+ desc "Install dotfiles for #{index.name}"
28
+ task index.name do
28
29
  installer = Installer.new(
29
- name,
30
- base_dir: base_dir,
31
- target_dir: target_dir
30
+ index.name,
31
+ dotfiles_dir,
32
+ home_dir,
33
+ output_colorize
32
34
  )
33
- installer.install(index_file)
35
+ installer.install(index.filename)
34
36
  end
35
37
  end
36
38
  end
@@ -38,7 +40,13 @@ module Flexdot
38
40
 
39
41
  private
40
42
 
41
- attr_reader :base_dir, :target_dir
43
+ attr_reader :dotfiles_dir, :home_dir, :output_colorize
44
+
45
+ def indexes
46
+ @indexes ||= Pathname.new(dotfiles_dir).glob('*.yml').map do |index_file|
47
+ Index.new(name: index_file.basename('.*').to_s, filename: index_file)
48
+ end
49
+ end
42
50
  end
43
51
  end
44
52
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Flexdot
4
- VERSION = '1.0.2'
4
+ VERSION = '3.2.0'
5
5
  end
data/lib/flexdot.rb CHANGED
@@ -1,10 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'rake'
4
+
3
5
  require_relative 'flexdot/version'
4
6
  require_relative 'flexdot/tasks'
5
7
 
6
8
  module Flexdot
7
- def self.install_tasks(base_dir:, target_dir:)
8
- Tasks.new(base_dir, target_dir).install
9
+ def self.setup(home_dir:, dotfiles_dir: '.', output_colorize: true)
10
+ Tasks.new(dotfiles_dir, home_dir, output_colorize).install
9
11
  end
10
12
  end
metadata CHANGED
@@ -1,15 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flexdot
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 3.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Katsuya Hidaka
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-21 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2021-08-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '12.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
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
13
41
  description: Flexdot is a Flexible and Rake based dotfile manager
14
42
  email:
15
43
  - hidakatsuya@gmail.com
@@ -17,9 +45,10 @@ executables: []
17
45
  extensions: []
18
46
  extra_rdoc_files: []
19
47
  files:
20
- - ".github/FUNDING.yml"
48
+ - ".github/dependabot.yml"
21
49
  - ".github/workflows/test.yml"
22
50
  - ".gitignore"
51
+ - CHANGELOG.md
23
52
  - CODE_OF_CONDUCT.md
24
53
  - Gemfile
25
54
  - LICENSE.txt
@@ -30,14 +59,14 @@ files:
30
59
  - lib/flexdot/backup.rb
31
60
  - lib/flexdot/index.rb
32
61
  - lib/flexdot/installer.rb
33
- - lib/flexdot/logger.rb
62
+ - lib/flexdot/output.rb
34
63
  - lib/flexdot/tasks.rb
35
64
  - lib/flexdot/version.rb
36
65
  homepage: https://github.com/hidakatsuya/flexdot
37
66
  licenses:
38
67
  - MIT
39
68
  metadata: {}
40
- post_install_message:
69
+ post_install_message:
41
70
  rdoc_options: []
42
71
  require_paths:
43
72
  - lib
@@ -45,15 +74,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
45
74
  requirements:
46
75
  - - ">="
47
76
  - !ruby/object:Gem::Version
48
- version: 2.5.0
77
+ version: 2.6.0
49
78
  required_rubygems_version: !ruby/object:Gem::Requirement
50
79
  requirements:
51
80
  - - ">="
52
81
  - !ruby/object:Gem::Version
53
82
  version: '0'
54
83
  requirements: []
55
- rubygems_version: 3.1.2
56
- signing_key:
84
+ rubygems_version: 3.2.22
85
+ signing_key:
57
86
  specification_version: 4
58
87
  summary: A Flexible and Rake based dotfile manager
59
88
  test_files: []
data/.github/FUNDING.yml DELETED
@@ -1,3 +0,0 @@
1
- # These are supported funding model platforms
2
-
3
- github: [hidakatsuya]
@@ -1,29 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Flexdot
4
- class Logger
5
- Status = Struct.new(:target_file, :result, :backuped)
6
-
7
- def initialize(target_dir)
8
- @target_dir = target_dir
9
- end
10
-
11
- def log(target_file)
12
- status = Status.new(target_file)
13
- yield(status)
14
- puts message_for(status)
15
- end
16
-
17
- private
18
-
19
- attr_reader :target_dir
20
-
21
- def message_for(status)
22
- [].tap { |msg|
23
- msg << "[#{status.result}]"
24
- msg << status.target_file.relative_path_from(target_dir)
25
- msg << '(backup)' if status.backuped
26
- }.join(' ')
27
- end
28
- end
29
- end