flexdot 1.0.2 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -2
- data/CHANGELOG.md +29 -0
- data/Gemfile +1 -0
- data/README.md +50 -10
- data/lib/flexdot.rb +2 -2
- data/lib/flexdot/{logger.rb → console.rb} +8 -8
- data/lib/flexdot/index.rb +1 -1
- data/lib/flexdot/installer.rb +21 -21
- data/lib/flexdot/tasks.rb +39 -13
- data/lib/flexdot/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: abd911eda16fc28b419271e8e75d96f33314f2cc73cc850180966c16cb7fca4f
|
4
|
+
data.tar.gz: d3f84e097a314f4fc83772e5cc63874f2c3e0adf9658967b56269b52f3a284d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 844806f825d04329fc3fd63a893925e928075afc08c9d6bfcf262bb1b4dac0429edd0525cd68b7744e82dd08deccd10bc41f33e628bb72bb59a94448604b9505
|
7
|
+
data.tar.gz: 0dbbd2c56ab172c289206fc8e480be8deef399e2f153213046a83e61497010e8652ce67844f88fade41b29c41a8e8be842e4b8ff3f693d4722e26d6937bd55cd
|
data/.gitignore
CHANGED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
## 2.0.0
|
2
|
+
|
3
|
+
### Breaking Changes
|
4
|
+
|
5
|
+
v1.0.x
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
# Rakefile
|
9
|
+
Flexdot.install_tasks(
|
10
|
+
target_dir: '/home/username',
|
11
|
+
base_dir: '.'
|
12
|
+
)
|
13
|
+
```
|
14
|
+
|
15
|
+
v2.0.0
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
Flexdot.setup(
|
19
|
+
home_dir: '/home/username',
|
20
|
+
dotfiles_dir: '.'
|
21
|
+
)
|
22
|
+
```
|
23
|
+
|
24
|
+
### Enchancements
|
25
|
+
|
26
|
+
- Add default_index option fixes #2
|
27
|
+
- Option renaming and simplification by default value
|
28
|
+
|
29
|
+
Please refer to README.md for details.
|
data/Gemfile
CHANGED
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.
|
@@ -12,25 +13,48 @@ Ruby 2.5+
|
|
12
13
|
|
13
14
|
### Installing
|
14
15
|
|
15
|
-
|
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
|
-
|
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
|
-
|
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.
|
32
|
-
|
33
|
-
|
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
|
+
# The `rake install` command will be available to install the dotfile for the specified index file.
|
54
|
+
# Default nil.
|
55
|
+
#
|
56
|
+
# Note that the `rake install` command is always available if you have a single index file.
|
57
|
+
default_index: 'name_of_an_index_file'
|
34
58
|
)
|
35
59
|
```
|
36
60
|
|
@@ -94,12 +118,24 @@ $HOME/dotfiles
|
|
94
118
|
└── Rakefile
|
95
119
|
```
|
96
120
|
|
121
|
+
### Rakefile
|
122
|
+
|
123
|
+
```ruby
|
124
|
+
require 'flexdot'
|
125
|
+
|
126
|
+
Flexdot.setup(
|
127
|
+
home_dir: '..',
|
128
|
+
default_index: 'macOS'
|
129
|
+
)
|
130
|
+
```
|
131
|
+
|
97
132
|
### Available Commands
|
98
133
|
|
99
134
|
When you run the `rake -T` command in that directory structure, you should have two installation commands available:
|
100
135
|
|
101
136
|
$ rake -T
|
102
137
|
rake clear_backups # Clear all backups
|
138
|
+
rake install # Install dotfiles for macOS
|
103
139
|
rake install:macOS # Install dotfiles for macOS
|
104
140
|
rake install:ubuntu # Install dotfiles for ubuntu
|
105
141
|
|
@@ -177,6 +213,10 @@ ubuntu:
|
|
177
213
|
|
178
214
|
### Installing dotfiles
|
179
215
|
|
216
|
+
$ rake install
|
217
|
+
|
218
|
+
Or
|
219
|
+
|
180
220
|
$ rake install:macOS
|
181
221
|
|
182
222
|
The following is the output result:
|
data/lib/flexdot.rb
CHANGED
@@ -4,7 +4,7 @@ require_relative 'flexdot/version'
|
|
4
4
|
require_relative 'flexdot/tasks'
|
5
5
|
|
6
6
|
module Flexdot
|
7
|
-
def self.
|
8
|
-
Tasks.new(
|
7
|
+
def self.setup(home_dir:, dotfiles_dir: '.', default_index: nil)
|
8
|
+
Tasks.new(dotfiles_dir, home_dir, default_index).install
|
9
9
|
end
|
10
10
|
end
|
@@ -1,27 +1,27 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Flexdot
|
4
|
-
class
|
5
|
-
Status = Struct.new(:
|
4
|
+
class Console
|
5
|
+
Status = Struct.new(:home_file, :result, :backuped)
|
6
6
|
|
7
|
-
def initialize(
|
8
|
-
@
|
7
|
+
def initialize(dotfiles_dir)
|
8
|
+
@dotfiles_dir = dotfiles_dir
|
9
9
|
end
|
10
10
|
|
11
|
-
def log(
|
12
|
-
status = Status.new(
|
11
|
+
def log(home_file)
|
12
|
+
status = Status.new(home_file)
|
13
13
|
yield(status)
|
14
14
|
puts message_for(status)
|
15
15
|
end
|
16
16
|
|
17
17
|
private
|
18
18
|
|
19
|
-
attr_reader :
|
19
|
+
attr_reader :dotfiles_dir
|
20
20
|
|
21
21
|
def message_for(status)
|
22
22
|
[].tap { |msg|
|
23
23
|
msg << "[#{status.result}]"
|
24
|
-
msg << status.
|
24
|
+
msg << status.home_file.relative_path_from(dotfiles_dir)
|
25
25
|
msg << '(backup)' if status.backuped
|
26
26
|
}.join(' ')
|
27
27
|
end
|
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),
|
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
|
data/lib/flexdot/installer.rb
CHANGED
@@ -2,53 +2,53 @@
|
|
2
2
|
|
3
3
|
require 'yaml'
|
4
4
|
|
5
|
-
require_relative '
|
5
|
+
require_relative 'console'
|
6
6
|
require_relative 'backup'
|
7
7
|
require_relative 'index'
|
8
8
|
|
9
9
|
module Flexdot
|
10
10
|
class Installer
|
11
|
-
def initialize(name,
|
11
|
+
def initialize(name, dotfiles_dir:, home_dir:)
|
12
12
|
@name = name
|
13
|
-
@
|
14
|
-
@
|
13
|
+
@dotfiles_dir = dotfiles_dir
|
14
|
+
@home_dir = home_dir
|
15
15
|
@backup = Backup.new
|
16
|
-
@
|
16
|
+
@console = Console.new(@home_dir)
|
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:,
|
22
|
-
install_link(dotfile_path,
|
21
|
+
index.each do |dotfile_path:, home_file_path:|
|
22
|
+
install_link(dotfile_path, home_file_path)
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
26
|
private
|
27
27
|
|
28
|
-
attr_reader :name, :
|
28
|
+
attr_reader :name, :dotfiles_dir, :home_dir, :backup, :console
|
29
29
|
|
30
|
-
def install_link(dotfile_path,
|
31
|
-
dotfile = @
|
32
|
-
|
30
|
+
def install_link(dotfile_path, home_file_path)
|
31
|
+
dotfile = @dotfiles_dir.join(dotfile_path).expand_path
|
32
|
+
home_file = @home_dir.join(home_file_path, dotfile.basename).expand_path
|
33
33
|
|
34
|
-
|
35
|
-
if
|
36
|
-
if
|
34
|
+
console.log(home_file) do |status|
|
35
|
+
if home_file.symlink?
|
36
|
+
if home_file.readlink == dotfile
|
37
37
|
status.result = :already_linked
|
38
38
|
else
|
39
|
-
|
40
|
-
|
39
|
+
home_file.unlink
|
40
|
+
home_file.make_symlink(dotfile.to_path)
|
41
41
|
status.result = :link_updated
|
42
42
|
end
|
43
43
|
else
|
44
|
-
if
|
45
|
-
backup.call(
|
44
|
+
if home_file.exist?
|
45
|
+
backup.call(home_file)
|
46
46
|
status.backuped = true
|
47
|
-
elsif !
|
48
|
-
|
47
|
+
elsif !home_file.dirname.exist?
|
48
|
+
home_file.dirname.mkpath
|
49
49
|
end
|
50
50
|
|
51
|
-
|
51
|
+
home_file.make_symlink(dotfile.to_path)
|
52
52
|
status.result = :link_created
|
53
53
|
end
|
54
54
|
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
|
-
|
12
|
-
|
13
|
-
|
11
|
+
Index = Struct.new(:filename, :name, keyword_init: true)
|
12
|
+
|
13
|
+
def initialize(dotfiles_dir, home_dir, default_index_name = nil)
|
14
|
+
@default_index_name = default_index_name
|
15
|
+
@dotfiles_dir = Pathname.new(dotfiles_dir).expand_path
|
16
|
+
@home_dir = Pathname.new(home_dir).expand_path
|
14
17
|
end
|
15
18
|
|
16
19
|
def install
|
@@ -20,25 +23,48 @@ module Flexdot
|
|
20
23
|
end
|
21
24
|
|
22
25
|
namespace :install do
|
23
|
-
|
24
|
-
|
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
|
-
|
31
|
-
|
30
|
+
index.name,
|
31
|
+
dotfiles_dir: dotfiles_dir,
|
32
|
+
home_dir: home_dir
|
32
33
|
)
|
33
|
-
installer.install(
|
34
|
+
installer.install(index.filename)
|
34
35
|
end
|
35
36
|
end
|
36
37
|
end
|
38
|
+
|
39
|
+
if default_index
|
40
|
+
desc "Install dotfiles for #{default_index.name}"
|
41
|
+
task :install do
|
42
|
+
Rake::Task["install:#{default_index.name}"].invoke
|
43
|
+
end
|
44
|
+
end
|
37
45
|
end
|
38
46
|
|
39
47
|
private
|
40
48
|
|
41
|
-
attr_reader :
|
49
|
+
attr_reader :dotfiles_dir, :home_dir
|
50
|
+
|
51
|
+
def default_index
|
52
|
+
@default_index ||=
|
53
|
+
if @default_index_name
|
54
|
+
ifnone = -> { raise "#{@default_index_name} index is not found" }
|
55
|
+
indexes.find(ifnone) { |index| index.name == @default_index_name }
|
56
|
+
elsif indexes.size == 1
|
57
|
+
indexes.first
|
58
|
+
else
|
59
|
+
nil
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def indexes
|
64
|
+
@indexes ||= Pathname.new(dotfiles_dir).glob('*.yml').map do |index_file|
|
65
|
+
Index.new(name: index_file.basename('.*').to_s, filename: index_file)
|
66
|
+
end
|
67
|
+
end
|
42
68
|
end
|
43
69
|
end
|
44
70
|
|
data/lib/flexdot/version.rb
CHANGED
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:
|
4
|
+
version: 2.0.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: 2020-
|
11
|
+
date: 2020-10-28 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Flexdot is a Flexible and Rake based dotfile manager
|
14
14
|
email:
|
@@ -20,6 +20,7 @@ files:
|
|
20
20
|
- ".github/FUNDING.yml"
|
21
21
|
- ".github/workflows/test.yml"
|
22
22
|
- ".gitignore"
|
23
|
+
- CHANGELOG.md
|
23
24
|
- CODE_OF_CONDUCT.md
|
24
25
|
- Gemfile
|
25
26
|
- LICENSE.txt
|
@@ -28,9 +29,9 @@ files:
|
|
28
29
|
- flexdot.gemspec
|
29
30
|
- lib/flexdot.rb
|
30
31
|
- lib/flexdot/backup.rb
|
32
|
+
- lib/flexdot/console.rb
|
31
33
|
- lib/flexdot/index.rb
|
32
34
|
- lib/flexdot/installer.rb
|
33
|
-
- lib/flexdot/logger.rb
|
34
35
|
- lib/flexdot/tasks.rb
|
35
36
|
- lib/flexdot/version.rb
|
36
37
|
homepage: https://github.com/hidakatsuya/flexdot
|