flexdot 3.0.0 → 3.3.0
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 +4 -4
- data/.github/dependabot.yml +0 -5
- data/.github/workflows/test.yml +3 -3
- data/.gitignore +0 -1
- data/Gemfile +0 -1
- data/README.md +14 -182
- data/doc/example.md +182 -0
- data/flexdot.gemspec +4 -1
- data/lib/flexdot/backup.rb +21 -1
- data/lib/flexdot/installer.rb +9 -6
- data/lib/flexdot/output.rb +48 -0
- data/lib/flexdot/tasks.rb +7 -5
- data/lib/flexdot/version.rb +1 -1
- data/lib/flexdot.rb +28 -2
- metadata +38 -11
- data/.github/FUNDING.yml +0 -3
- data/CHANGELOG.md +0 -68
- data/lib/flexdot/console.rb +0 -29
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c373b333d8109e552863dc5e8dc1ce031d04b7344d80269c591408688cd70ade
|
4
|
+
data.tar.gz: ee06b19abd37b90a35c0b9ced7a0c28a18c4d757f03318773763628efc1320f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe5589432db9a290342835c1799a8ff19f3e59df553e21b40de0bf059d6d8ea65ba0f1eb3a0929d5678d22ce47182e9d531c15d9486a19b71f68e80955ef6d0d
|
7
|
+
data.tar.gz: 158067f3e822573f3d2a28b72b85f6dc4fb88afe532c9a2504c4cffff42720be1734a3b3e3253ec529cfc32e2f1f795e06119cf8448dec564a49652a104676af
|
data/.github/dependabot.yml
CHANGED
data/.github/workflows/test.yml
CHANGED
@@ -7,16 +7,16 @@ jobs:
|
|
7
7
|
test:
|
8
8
|
name: Test on ruby ${{ matrix.ruby_version }}
|
9
9
|
runs-on: ubuntu-latest
|
10
|
+
|
10
11
|
# Run this build only on either pull request or push.
|
11
12
|
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
|
12
13
|
|
13
14
|
strategy:
|
14
15
|
matrix:
|
15
16
|
ruby_version:
|
16
|
-
- 2.5
|
17
|
-
- 2.6
|
18
17
|
- 2.7
|
19
|
-
- 3.0
|
18
|
+
- '3.0'
|
19
|
+
- 3.1
|
20
20
|
steps:
|
21
21
|
- uses: actions/checkout@v2
|
22
22
|
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -9,7 +9,7 @@ A Flexible and Rake based dotfile manager.
|
|
9
9
|
|
10
10
|
### Prerequisite
|
11
11
|
|
12
|
-
Ruby 2.
|
12
|
+
Ruby 2.7+
|
13
13
|
|
14
14
|
### Installing
|
15
15
|
|
@@ -48,6 +48,17 @@ 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
|
56
|
+
|
57
|
+
# (optional)
|
58
|
+
# Whether to automatically delete old backups.
|
59
|
+
# If nil, do not delete, otherwise keep to the specified number of backups.
|
60
|
+
# Default: nil
|
61
|
+
keep_max_backup_count: 10
|
51
62
|
)
|
52
63
|
```
|
53
64
|
|
@@ -63,188 +74,9 @@ Finally, run `rake -T` in the `$HOME/dotfiles` and make sure that the output is
|
|
63
74
|
$ rake -T
|
64
75
|
rake clear_backups
|
65
76
|
|
66
|
-
##
|
67
|
-
|
68
|
-
This example is my actual dotfile environment.
|
69
|
-
|
70
|
-
I have two working environments, macOS and ubuntu. The dotfiles in these environments are slightly different, so each dotfile is separated.
|
71
|
-
|
72
|
-
### Directory Structure
|
73
|
-
|
74
|
-
```
|
75
|
-
$HOME/dotfiles
|
76
|
-
├── common
|
77
|
-
│ ├── bin
|
78
|
-
│ │ ├── git-delete-other-branches
|
79
|
-
│ │ └── git-reset-and-clean
|
80
|
-
│ ├── git
|
81
|
-
│ │ └── ignore
|
82
|
-
│ ├── rubygems
|
83
|
-
│ │ └── .gemrc
|
84
|
-
│ └── vim
|
85
|
-
│ └── .vimrc
|
86
|
-
├── macOS
|
87
|
-
│ ├── bash
|
88
|
-
│ │ ├── .bash_profile
|
89
|
-
│ │ └── .bashrc
|
90
|
-
│ ├── git
|
91
|
-
│ │ └── .gitconfig
|
92
|
-
│ ├── karabiner
|
93
|
-
│ │ └── tab-emulation.json
|
94
|
-
│ └── vscode
|
95
|
-
│ ├── keybindings.json
|
96
|
-
│ └── settings.json
|
97
|
-
├── ubuntu
|
98
|
-
│ ├── bash
|
99
|
-
│ │ └── .bashrc
|
100
|
-
│ ├── bin
|
101
|
-
│ │ ├── upgrade-ghcli
|
102
|
-
│ │ ├── utils
|
103
|
-
│ │ ├── x-copy
|
104
|
-
│ │ └── x-open
|
105
|
-
│ ├── git
|
106
|
-
│ │ └── .gitconfig
|
107
|
-
│ ├── vscode
|
108
|
-
│ │ ├── keybindings.json
|
109
|
-
│ │ └── settings.json
|
110
|
-
│ └── xkeysnail
|
111
|
-
│ ├── config.py
|
112
|
-
│ ├── debug.sh
|
113
|
-
│ ├── restart.sh
|
114
|
-
│ ├── start.sh
|
115
|
-
│ └── stop.sh
|
116
|
-
├── macOS.yml
|
117
|
-
├── ubuntu.yml
|
118
|
-
└── Rakefile
|
119
|
-
```
|
120
|
-
|
121
|
-
### Rakefile
|
122
|
-
|
123
|
-
```ruby
|
124
|
-
require 'flexdot'
|
125
|
-
|
126
|
-
Flexdot.setup(
|
127
|
-
home_dir: '..'
|
128
|
-
)
|
129
|
-
|
130
|
-
# You can execute `install:macOS` when you run `rake` command
|
131
|
-
# with no arguments by defining it as follows:
|
132
|
-
task default: 'install:macOS'
|
133
|
-
```
|
134
|
-
|
135
|
-
### Available Commands
|
136
|
-
|
137
|
-
When you run the `rake -T` command in that directory structure, you should have two installation commands available:
|
138
|
-
|
139
|
-
$ rake -T
|
140
|
-
rake clear_backups # Clear all backups
|
141
|
-
rake install:macOS # Install dotfiles for macOS
|
142
|
-
rake install:ubuntu # Install dotfiles for ubuntu
|
143
|
-
|
144
|
-
### Dotfile Index File
|
145
|
-
|
146
|
-
`macOS.yml` and `ubuntu.yml` are for setting the link destination of dotfile. dotfile will be installed according to its setting.
|
147
|
-
|
148
|
-
#### macOS.yml
|
149
|
-
|
150
|
-
For example, `common -> bin -> git-delete-other-branchs` is `$HOME/dotfiles/common/bin/git-delete-other-branches`.
|
151
|
-
And the value `bin` means `$HOME/bin` directory.
|
152
|
-
|
153
|
-
So this defines linking `$HOME/dotfiles/common/bin/git-delete-other-branches` to `$HOME/bin/git-delete-other-branches`.
|
154
|
-
|
155
|
-
|
156
|
-
```yml
|
157
|
-
common:
|
158
|
-
bin:
|
159
|
-
git-delete-other-branches: bin
|
160
|
-
git-reset-and-clean: bin
|
161
|
-
git:
|
162
|
-
ignore: .config/git
|
163
|
-
rubygems:
|
164
|
-
.gemrc: .
|
165
|
-
vim:
|
166
|
-
.vimrc: .
|
167
|
-
|
168
|
-
macOS:
|
169
|
-
bash:
|
170
|
-
.bash_profile: .
|
171
|
-
.bashrc: .
|
172
|
-
git:
|
173
|
-
.gitconfig: .
|
174
|
-
karabiner:
|
175
|
-
tab-emulation.json: .config/karabiner/assets/complex_modifications
|
176
|
-
vscode:
|
177
|
-
keybindings.json: Library/Application Support/Code/User
|
178
|
-
settings.json: Library/Application Support/Code/User
|
179
|
-
```
|
180
|
-
|
181
|
-
#### ubuntu.yml
|
182
|
-
|
183
|
-
```yml
|
184
|
-
common:
|
185
|
-
bin:
|
186
|
-
git-delete-other-branchs: bin
|
187
|
-
git-reset-and-clean: bin
|
188
|
-
git:
|
189
|
-
ignore: .config/git
|
190
|
-
rubygems:
|
191
|
-
.gemrc: .
|
192
|
-
vim:
|
193
|
-
.vimrc: .
|
194
|
-
|
195
|
-
ubuntu:
|
196
|
-
bash:
|
197
|
-
.bashrc: .
|
198
|
-
bin:
|
199
|
-
upgrade-ghcli: bin
|
200
|
-
utils: bin
|
201
|
-
x-copy: bin
|
202
|
-
x-open: bin
|
203
|
-
git:
|
204
|
-
.gitconfig: .
|
205
|
-
vscode:
|
206
|
-
keybindings.json: .config/Code/User
|
207
|
-
settings.json: .config/Code/User
|
208
|
-
xkeysnail:
|
209
|
-
config.py: .xkeysnail
|
210
|
-
debug.sh: .xkeysnail
|
211
|
-
restart.sh: .xkeysnail
|
212
|
-
start.sh: .xkeysnail
|
213
|
-
stop.sh: .xkeysnail
|
214
|
-
```
|
215
|
-
|
216
|
-
### Installing dotfiles for macOS
|
217
|
-
|
218
|
-
$ rake
|
219
|
-
|
220
|
-
Or,
|
221
|
-
|
222
|
-
$ rake install:macOS
|
223
|
-
|
224
|
-
The following is the output result:
|
225
|
-
|
226
|
-
```
|
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)
|
238
|
-
```
|
239
|
-
|
240
|
-
`already_linked` means skipped because `bin/git-delete-other-branches` is already linked. `link_created` means the link was created.
|
241
|
-
Also, `(backup)` means that a file exists in the link path and that file was backed up to `$HOME/dotfiles/backup/YYYYMMDDHHIISS/filename`.
|
242
|
-
|
243
|
-
### Misc
|
244
|
-
|
245
|
-
You can clear all backups in `$HOME/dotfiles/backup/YYYYMMDDHHIISS` to run `rake clear_backups`.
|
77
|
+
## Usage
|
246
78
|
|
247
|
-
|
79
|
+
See [doc/example.md](doc/example.md)
|
248
80
|
|
249
81
|
## License
|
250
82
|
|
data/doc/example.md
ADDED
@@ -0,0 +1,182 @@
|
|
1
|
+
# Example
|
2
|
+
|
3
|
+
This example is my actual dotfile environment.
|
4
|
+
|
5
|
+
I have two working environments, macOS and ubuntu. The dotfiles in these environments are slightly different, so each dotfile is separated.
|
6
|
+
|
7
|
+
## Directory Structure
|
8
|
+
|
9
|
+
```
|
10
|
+
$HOME/dotfiles
|
11
|
+
├── common
|
12
|
+
│ ├── bin
|
13
|
+
│ │ ├── git-delete-other-branches
|
14
|
+
│ │ └── git-reset-and-clean
|
15
|
+
│ ├── git
|
16
|
+
│ │ └── ignore
|
17
|
+
│ ├── rubygems
|
18
|
+
│ │ └── .gemrc
|
19
|
+
│ └── vim
|
20
|
+
│ └── .vimrc
|
21
|
+
├── macOS
|
22
|
+
│ ├── bash
|
23
|
+
│ │ ├── .bash_profile
|
24
|
+
│ │ └── .bashrc
|
25
|
+
│ ├── git
|
26
|
+
│ │ └── .gitconfig
|
27
|
+
│ ├── karabiner
|
28
|
+
│ │ └── tab-emulation.json
|
29
|
+
│ └── vscode
|
30
|
+
│ ├── keybindings.json
|
31
|
+
│ └── settings.json
|
32
|
+
├── ubuntu
|
33
|
+
│ ├── bash
|
34
|
+
│ │ └── .bashrc
|
35
|
+
│ ├── bin
|
36
|
+
│ │ ├── upgrade-ghcli
|
37
|
+
│ │ ├── utils
|
38
|
+
│ │ ├── x-copy
|
39
|
+
│ │ └── x-open
|
40
|
+
│ ├── git
|
41
|
+
│ │ └── .gitconfig
|
42
|
+
│ ├── vscode
|
43
|
+
│ │ ├── keybindings.json
|
44
|
+
│ │ └── settings.json
|
45
|
+
│ └── xkeysnail
|
46
|
+
│ ├── config.py
|
47
|
+
│ ├── debug.sh
|
48
|
+
│ ├── restart.sh
|
49
|
+
│ ├── start.sh
|
50
|
+
│ └── stop.sh
|
51
|
+
├── macOS.yml
|
52
|
+
├── ubuntu.yml
|
53
|
+
└── Rakefile
|
54
|
+
```
|
55
|
+
|
56
|
+
## Rakefile
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
require 'flexdot'
|
60
|
+
|
61
|
+
Flexdot.setup(
|
62
|
+
home_dir: '..'
|
63
|
+
)
|
64
|
+
|
65
|
+
# You can execute `install:macOS` when you run `rake` command
|
66
|
+
# with no arguments by defining it as follows:
|
67
|
+
task default: 'install:macOS'
|
68
|
+
```
|
69
|
+
|
70
|
+
## Available Commands
|
71
|
+
|
72
|
+
When you run the `rake -T` command in that directory structure, you should have two installation commands available:
|
73
|
+
|
74
|
+
$ rake -T
|
75
|
+
rake clear_backups # Clear all backups
|
76
|
+
rake install:macOS # Install dotfiles for macOS
|
77
|
+
rake install:ubuntu # Install dotfiles for ubuntu
|
78
|
+
|
79
|
+
## Dotfile Index File
|
80
|
+
|
81
|
+
`macOS.yml` and `ubuntu.yml` are for setting the link destination of dotfile. dotfile will be installed according to its setting.
|
82
|
+
|
83
|
+
### macOS.yml
|
84
|
+
|
85
|
+
For example, `common -> bin -> git-delete-other-branchs` is `$HOME/dotfiles/common/bin/git-delete-other-branches`.
|
86
|
+
And the value `bin` means `$HOME/bin` directory.
|
87
|
+
|
88
|
+
So this defines linking `$HOME/dotfiles/common/bin/git-delete-other-branches` to `$HOME/bin/git-delete-other-branches`.
|
89
|
+
|
90
|
+
|
91
|
+
```yml
|
92
|
+
common:
|
93
|
+
bin:
|
94
|
+
git-delete-other-branches: bin
|
95
|
+
git-reset-and-clean: bin
|
96
|
+
git:
|
97
|
+
ignore: .config/git
|
98
|
+
rubygems:
|
99
|
+
.gemrc: .
|
100
|
+
vim:
|
101
|
+
.vimrc: .
|
102
|
+
|
103
|
+
macOS:
|
104
|
+
bash:
|
105
|
+
.bash_profile: .
|
106
|
+
.bashrc: .
|
107
|
+
git:
|
108
|
+
.gitconfig: .
|
109
|
+
karabiner:
|
110
|
+
tab-emulation.json: .config/karabiner/assets/complex_modifications
|
111
|
+
vscode:
|
112
|
+
keybindings.json: Library/Application Support/Code/User
|
113
|
+
settings.json: Library/Application Support/Code/User
|
114
|
+
```
|
115
|
+
|
116
|
+
### ubuntu.yml
|
117
|
+
|
118
|
+
```yml
|
119
|
+
common:
|
120
|
+
bin:
|
121
|
+
git-delete-other-branchs: bin
|
122
|
+
git-reset-and-clean: bin
|
123
|
+
git:
|
124
|
+
ignore: .config/git
|
125
|
+
rubygems:
|
126
|
+
.gemrc: .
|
127
|
+
vim:
|
128
|
+
.vimrc: .
|
129
|
+
|
130
|
+
ubuntu:
|
131
|
+
bash:
|
132
|
+
.bashrc: .
|
133
|
+
bin:
|
134
|
+
upgrade-ghcli: bin
|
135
|
+
utils: bin
|
136
|
+
x-copy: bin
|
137
|
+
x-open: bin
|
138
|
+
git:
|
139
|
+
.gitconfig: .
|
140
|
+
vscode:
|
141
|
+
keybindings.json: .config/Code/User
|
142
|
+
settings.json: .config/Code/User
|
143
|
+
xkeysnail:
|
144
|
+
config.py: .xkeysnail
|
145
|
+
debug.sh: .xkeysnail
|
146
|
+
restart.sh: .xkeysnail
|
147
|
+
start.sh: .xkeysnail
|
148
|
+
stop.sh: .xkeysnail
|
149
|
+
```
|
150
|
+
|
151
|
+
## Installing dotfiles for macOS
|
152
|
+
|
153
|
+
$ rake
|
154
|
+
|
155
|
+
Or,
|
156
|
+
|
157
|
+
$ rake install:macOS
|
158
|
+
|
159
|
+
The following is the output result:
|
160
|
+
|
161
|
+
```
|
162
|
+
already linked: bin/git-delete-other-branches
|
163
|
+
already linked: bin/git-reset-and-clean
|
164
|
+
already linked: .config/git/ignore
|
165
|
+
already linked: .gemrc
|
166
|
+
already linked: .vimrc
|
167
|
+
link created: .bash_profile (backup)
|
168
|
+
link created: .bashrc (backup)
|
169
|
+
link created: .gitconfig (backup)
|
170
|
+
link created: .config/karabiner/assets/complex_modifications/tab-emulation.json (backup)
|
171
|
+
link created: Library/Application Support/Code/User/keybindings.json (backup)
|
172
|
+
link created: Library/Application Support/Code/User/settings.json (backup)
|
173
|
+
```
|
174
|
+
|
175
|
+
`already_linked` means skipped because `bin/git-delete-other-branches` is already linked. `link_created` means the link was created.
|
176
|
+
Also, `(backup)` means that a file exists in the link path and that file was backed up to `$HOME/dotfiles/backup/YYYYMMDDHHIISS/filename`.
|
177
|
+
|
178
|
+
## Misc
|
179
|
+
|
180
|
+
You can clear all backups in `$HOME/dotfiles/backup/YYYYMMDDHHIISS` to run `rake clear_backups`.
|
181
|
+
|
182
|
+
$ rake clear_backups
|
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.
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.7.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
|
data/lib/flexdot/backup.rb
CHANGED
@@ -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)
|
@@ -17,14 +19,32 @@ module Flexdot
|
|
17
19
|
end
|
18
20
|
end
|
19
21
|
|
20
|
-
def initialize
|
22
|
+
def initialize(keep_max_count)
|
21
23
|
backup_dir.mkpath unless backup_dir.exist?
|
24
|
+
@keep_max_count = keep_max_count
|
25
|
+
@finished = false
|
22
26
|
end
|
23
27
|
|
24
28
|
def call(file)
|
29
|
+
raise AlreadyFinishedError if @finished
|
25
30
|
FileUtils.mv(file, backup_dir)
|
26
31
|
end
|
27
32
|
|
33
|
+
def finish!
|
34
|
+
backup_dir.delete if backup_dir.empty?
|
35
|
+
@finished = true
|
36
|
+
end
|
37
|
+
|
38
|
+
def remove_outdated!
|
39
|
+
return if @keep_max_count.nil?
|
40
|
+
|
41
|
+
backups = self.class.base_dir.glob('*/').select { |dir| dir.basename.to_s.match?(/\d{14}/) }
|
42
|
+
backups.sort_by! { |dir| dir.basename.to_s }.reverse!
|
43
|
+
backups.slice!(0, @keep_max_count)
|
44
|
+
|
45
|
+
backups.each(&:rmtree)
|
46
|
+
end
|
47
|
+
|
28
48
|
private
|
29
49
|
|
30
50
|
def backup_dir
|
data/lib/flexdot/installer.rb
CHANGED
@@ -2,18 +2,18 @@
|
|
2
2
|
|
3
3
|
require 'yaml'
|
4
4
|
|
5
|
-
require_relative '
|
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
|
11
|
+
def initialize(name, home_dir, dotfiles_dir, options)
|
12
12
|
@name = name
|
13
13
|
@dotfiles_dir = dotfiles_dir
|
14
14
|
@home_dir = home_dir
|
15
|
-
@backup = Backup.new
|
16
|
-
@
|
15
|
+
@backup = Backup.new(options.keep_max_backup_count)
|
16
|
+
@output = Output.new(@home_dir, colorize: options.output_colorize)
|
17
17
|
end
|
18
18
|
|
19
19
|
def install(index_file)
|
@@ -21,17 +21,20 @@ module Flexdot
|
|
21
21
|
index.each do |dotfile_path:, home_file_path:|
|
22
22
|
install_link(dotfile_path, home_file_path)
|
23
23
|
end
|
24
|
+
|
25
|
+
backup.finish!
|
26
|
+
backup.remove_outdated!
|
24
27
|
end
|
25
28
|
|
26
29
|
private
|
27
30
|
|
28
|
-
attr_reader :name, :
|
31
|
+
attr_reader :name, :home_dir, :dotfiles_dir, :backup, :output
|
29
32
|
|
30
33
|
def install_link(dotfile_path, home_file_path)
|
31
34
|
dotfile = @dotfiles_dir.join(dotfile_path).expand_path
|
32
35
|
home_file = @home_dir.join(home_file_path, dotfile.basename).expand_path
|
33
36
|
|
34
|
-
|
37
|
+
output.log(home_file) do |status|
|
35
38
|
if home_file.symlink?
|
36
39
|
if home_file.readlink == dotfile
|
37
40
|
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(
|
14
|
-
@dotfiles_dir = Pathname.new(dotfiles_dir).expand_path
|
13
|
+
def initialize(home_dir, options)
|
15
14
|
@home_dir = Pathname.new(home_dir).expand_path
|
15
|
+
@dotfiles_dir = Pathname.new(options.dotfiles_dir).expand_path
|
16
|
+
@options = options
|
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
|
-
|
31
|
-
|
31
|
+
home_dir,
|
32
|
+
dotfiles_dir,
|
33
|
+
options
|
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, :
|
43
|
+
attr_reader :home_dir, :dotfiles_dir, :options
|
42
44
|
|
43
45
|
def indexes
|
44
46
|
@indexes ||= Pathname.new(dotfiles_dir).glob('*.yml').map do |index_file|
|
data/lib/flexdot/version.rb
CHANGED
data/lib/flexdot.rb
CHANGED
@@ -1,10 +1,36 @@
|
|
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
|
-
|
8
|
-
|
9
|
+
Options = Struct.new(
|
10
|
+
# The dotfile directory path.
|
11
|
+
# Default: '.'.
|
12
|
+
:dotfiles_dir,
|
13
|
+
|
14
|
+
# Whether or not to colorize the output
|
15
|
+
# Default: true
|
16
|
+
:output_colorize,
|
17
|
+
|
18
|
+
# Whether to automatically delete old backups.
|
19
|
+
# If nil, do not delete, otherwise keep to the specified number of backups.
|
20
|
+
# Default: nil
|
21
|
+
:keep_max_backup_count,
|
22
|
+
|
23
|
+
keyword_init: true
|
24
|
+
)
|
25
|
+
|
26
|
+
DEFAULT_OPTIONS = {
|
27
|
+
dotfiles_dir: '.',
|
28
|
+
output_colorize: true,
|
29
|
+
keep_max_backup_count: nil
|
30
|
+
}
|
31
|
+
|
32
|
+
def self.setup(home_dir:, **options)
|
33
|
+
opts = Options.new(DEFAULT_OPTIONS.merge(options))
|
34
|
+
Tasks.new(home_dir, opts).install
|
9
35
|
end
|
10
36
|
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: 3.
|
4
|
+
version: 3.3.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:
|
12
|
-
dependencies:
|
11
|
+
date: 2022-05-22 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,29 +45,28 @@ executables: []
|
|
17
45
|
extensions: []
|
18
46
|
extra_rdoc_files: []
|
19
47
|
files:
|
20
|
-
- ".github/FUNDING.yml"
|
21
48
|
- ".github/dependabot.yml"
|
22
49
|
- ".github/workflows/test.yml"
|
23
50
|
- ".gitignore"
|
24
|
-
- CHANGELOG.md
|
25
51
|
- CODE_OF_CONDUCT.md
|
26
52
|
- Gemfile
|
27
53
|
- LICENSE.txt
|
28
54
|
- README.md
|
29
55
|
- Rakefile
|
56
|
+
- doc/example.md
|
30
57
|
- flexdot.gemspec
|
31
58
|
- lib/flexdot.rb
|
32
59
|
- lib/flexdot/backup.rb
|
33
|
-
- lib/flexdot/console.rb
|
34
60
|
- lib/flexdot/index.rb
|
35
61
|
- lib/flexdot/installer.rb
|
62
|
+
- lib/flexdot/output.rb
|
36
63
|
- lib/flexdot/tasks.rb
|
37
64
|
- lib/flexdot/version.rb
|
38
65
|
homepage: https://github.com/hidakatsuya/flexdot
|
39
66
|
licenses:
|
40
67
|
- MIT
|
41
68
|
metadata: {}
|
42
|
-
post_install_message:
|
69
|
+
post_install_message:
|
43
70
|
rdoc_options: []
|
44
71
|
require_paths:
|
45
72
|
- lib
|
@@ -47,15 +74,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
47
74
|
requirements:
|
48
75
|
- - ">="
|
49
76
|
- !ruby/object:Gem::Version
|
50
|
-
version: 2.
|
77
|
+
version: 2.7.0
|
51
78
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
79
|
requirements:
|
53
80
|
- - ">="
|
54
81
|
- !ruby/object:Gem::Version
|
55
82
|
version: '0'
|
56
83
|
requirements: []
|
57
|
-
rubygems_version: 3.
|
58
|
-
signing_key:
|
84
|
+
rubygems_version: 3.3.3
|
85
|
+
signing_key:
|
59
86
|
specification_version: 4
|
60
87
|
summary: A Flexible and Rake based dotfile manager
|
61
88
|
test_files: []
|
data/.github/FUNDING.yml
DELETED
data/CHANGELOG.md
DELETED
@@ -1,68 +0,0 @@
|
|
1
|
-
## 3.0.0
|
2
|
-
|
3
|
-
### Breaking Changes
|
4
|
-
|
5
|
-
Revert 'Add default_index option #2'. Please follow the instructions below to migrate:
|
6
|
-
|
7
|
-
First, modify your Rakefile as follows:
|
8
|
-
|
9
|
-
```diff
|
10
|
-
require 'flexdot'
|
11
|
-
|
12
|
-
Flexdot.setup(
|
13
|
-
+ home_dir: '..'
|
14
|
-
- home_dir: '..',
|
15
|
-
- default_index: 'macOS'
|
16
|
-
)
|
17
|
-
|
18
|
-
+ task default: 'install:macOS'
|
19
|
-
```
|
20
|
-
|
21
|
-
Then, update flexdot:
|
22
|
-
|
23
|
-
```
|
24
|
-
$ bundle update flexdot
|
25
|
-
```
|
26
|
-
|
27
|
-
Now you can run the following command to install the default index dotfiles:
|
28
|
-
|
29
|
-
```
|
30
|
-
$ rake
|
31
|
-
```
|
32
|
-
|
33
|
-
## 2.0.0
|
34
|
-
|
35
|
-
### Breaking Changes
|
36
|
-
|
37
|
-
- Change the syntax of configuration in the `Rakefile`
|
38
|
-
|
39
|
-
### Enchancements
|
40
|
-
|
41
|
-
- Add `default_index` option fixes #2
|
42
|
-
- Option renaming and simplification by default value
|
43
|
-
|
44
|
-
### Migrating from v1.0.x
|
45
|
-
|
46
|
-
First, you need to rewrite the `Rakefile` configuration to the v2.0.0 syntax.
|
47
|
-
|
48
|
-
```ruby
|
49
|
-
# v1.0.x
|
50
|
-
Flexdot.install_tasks(
|
51
|
-
target_dir: '/home/username',
|
52
|
-
base_dir: '.'
|
53
|
-
)
|
54
|
-
```
|
55
|
-
|
56
|
-
```ruby
|
57
|
-
# v2.0.0
|
58
|
-
Flexdot.setup(
|
59
|
-
home_dir: '/home/username',
|
60
|
-
dotfiles_dir: '.'
|
61
|
-
)
|
62
|
-
```
|
63
|
-
|
64
|
-
Note that If the `dotfiles_dir` option is `'.'` (current directory) , you can omit it.
|
65
|
-
|
66
|
-
Then, update flexdot to v2.0.0 and you're done.
|
67
|
-
|
68
|
-
$ bundle update flexdot
|
data/lib/flexdot/console.rb
DELETED
@@ -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
|