flexdot 3.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fbeccda096b5cffa6592e2fd044091357384a1be8eed6d692f2ddfd8e7b6cb3e
4
- data.tar.gz: cb0bb15f3a618e50ebe0c4e5db1fc325e426ba357f4ccfbddfd5110ec263a172
3
+ metadata.gz: c373b333d8109e552863dc5e8dc1ce031d04b7344d80269c591408688cd70ade
4
+ data.tar.gz: ee06b19abd37b90a35c0b9ced7a0c28a18c4d757f03318773763628efc1320f0
5
5
  SHA512:
6
- metadata.gz: 93df4b1412f1fbaccc3a242f68a569955435e2271d9cab0de29ec62cd04d760997162bb81fb1573454d837d29ba34606e6ef9a8d83b0c07cab5238c28cbfa62b
7
- data.tar.gz: 89284ebc88a5c475e53e80a6049bfa2bd37d498bf4a600ecd9ba1637a5c170951a9aa6be749e72adef587b691865c686a2ae834ea973f78674f1e32effd56a54
6
+ metadata.gz: fe5589432db9a290342835c1799a8ff19f3e59df553e21b40de0bf059d6d8ea65ba0f1eb3a0929d5678d22ce47182e9d531c15d9486a19b71f68e80955ef6d0d
7
+ data.tar.gz: 158067f3e822573f3d2a28b72b85f6dc4fb88afe532c9a2504c4cffff42720be1734a3b3e3253ec529cfc32e2f1f795e06119cf8448dec564a49652a104676af
@@ -7,15 +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.6
17
17
  - 2.7
18
- - 3.0
18
+ - '3.0'
19
+ - 3.1
19
20
  steps:
20
21
  - uses: actions/checkout@v2
21
22
 
data/.gitignore CHANGED
@@ -2,7 +2,6 @@
2
2
  /.yardoc
3
3
  /_yardoc/
4
4
  /coverage/
5
- /doc/
6
5
  /pkg/
7
6
  /spec/reports/
8
7
  /tmp/
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.6+
12
+ Ruby 2.7+
13
13
 
14
14
  ### Installing
15
15
 
@@ -53,6 +53,12 @@ Flexdot.setup(
53
53
  # Whether or not to colorize the output
54
54
  # Default: true
55
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
56
62
  )
57
63
  ```
58
64
 
@@ -68,188 +74,9 @@ Finally, run `rake -T` in the `$HOME/dotfiles` and make sure that the output is
68
74
  $ rake -T
69
75
  rake clear_backups
70
76
 
71
- ## Example
72
-
73
- This example is my actual dotfile environment.
74
-
75
- I have two working environments, macOS and ubuntu. The dotfiles in these environments are slightly different, so each dotfile is separated.
76
-
77
- ### Directory Structure
78
-
79
- ```
80
- $HOME/dotfiles
81
- ├── common
82
- │   ├── bin
83
- │   │   ├── git-delete-other-branches
84
- │   │   └── git-reset-and-clean
85
- │   ├── git
86
- │   │   └── ignore
87
- │   ├── rubygems
88
- │   │   └── .gemrc
89
- │   └── vim
90
- │   └── .vimrc
91
- ├── macOS
92
- │   ├── bash
93
- │   │   ├── .bash_profile
94
- │   │   └── .bashrc
95
- │   ├── git
96
- │   │   └── .gitconfig
97
- │   ├── karabiner
98
- │   │   └── tab-emulation.json
99
- │   └── vscode
100
- │   ├── keybindings.json
101
- │   └── settings.json
102
- ├── ubuntu
103
- │   ├── bash
104
- │   │   └── .bashrc
105
- │   ├── bin
106
- │   │   ├── upgrade-ghcli
107
- │   │   ├── utils
108
- │   │   ├── x-copy
109
- │   │   └── x-open
110
- │   ├── git
111
- │   │   └── .gitconfig
112
- │   ├── vscode
113
- │   │   ├── keybindings.json
114
- │   │   └── settings.json
115
- │   └── xkeysnail
116
- │   ├── config.py
117
- │   ├── debug.sh
118
- │   ├── restart.sh
119
- │   ├── start.sh
120
- │   └── stop.sh
121
- ├── macOS.yml
122
- ├── ubuntu.yml
123
- └── Rakefile
124
- ```
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
-
140
- ### Available Commands
141
-
142
- When you run the `rake -T` command in that directory structure, you should have two installation commands available:
143
-
144
- $ rake -T
145
- rake clear_backups # Clear all backups
146
- rake install:macOS # Install dotfiles for macOS
147
- rake install:ubuntu # Install dotfiles for ubuntu
148
-
149
- ### Dotfile Index File
150
-
151
- `macOS.yml` and `ubuntu.yml` are for setting the link destination of dotfile. dotfile will be installed according to its setting.
152
-
153
- #### macOS.yml
154
-
155
- For example, `common -> bin -> git-delete-other-branchs` is `$HOME/dotfiles/common/bin/git-delete-other-branches`.
156
- And the value `bin` means `$HOME/bin` directory.
157
-
158
- So this defines linking `$HOME/dotfiles/common/bin/git-delete-other-branches` to `$HOME/bin/git-delete-other-branches`.
159
-
160
-
161
- ```yml
162
- common:
163
- bin:
164
- git-delete-other-branches: bin
165
- git-reset-and-clean: bin
166
- git:
167
- ignore: .config/git
168
- rubygems:
169
- .gemrc: .
170
- vim:
171
- .vimrc: .
172
-
173
- macOS:
174
- bash:
175
- .bash_profile: .
176
- .bashrc: .
177
- git:
178
- .gitconfig: .
179
- karabiner:
180
- tab-emulation.json: .config/karabiner/assets/complex_modifications
181
- vscode:
182
- keybindings.json: Library/Application Support/Code/User
183
- settings.json: Library/Application Support/Code/User
184
- ```
185
-
186
- #### ubuntu.yml
187
-
188
- ```yml
189
- common:
190
- bin:
191
- git-delete-other-branchs: bin
192
- git-reset-and-clean: bin
193
- git:
194
- ignore: .config/git
195
- rubygems:
196
- .gemrc: .
197
- vim:
198
- .vimrc: .
199
-
200
- ubuntu:
201
- bash:
202
- .bashrc: .
203
- bin:
204
- upgrade-ghcli: bin
205
- utils: bin
206
- x-copy: bin
207
- x-open: bin
208
- git:
209
- .gitconfig: .
210
- vscode:
211
- keybindings.json: .config/Code/User
212
- settings.json: .config/Code/User
213
- xkeysnail:
214
- config.py: .xkeysnail
215
- debug.sh: .xkeysnail
216
- restart.sh: .xkeysnail
217
- start.sh: .xkeysnail
218
- stop.sh: .xkeysnail
219
- ```
220
-
221
- ### Installing dotfiles for macOS
222
-
223
- $ rake
224
-
225
- Or,
226
-
227
- $ rake install:macOS
228
-
229
- The following is the output result:
230
-
231
- ```
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)
243
- ```
244
-
245
- `already_linked` means skipped because `bin/git-delete-other-branches` is already linked. `link_created` means the link was created.
246
- Also, `(backup)` means that a file exists in the link path and that file was backed up to `$HOME/dotfiles/backup/YYYYMMDDHHIISS/filename`.
247
-
248
- ### Misc
249
-
250
- You can clear all backups in `$HOME/dotfiles/backup/YYYYMMDDHHIISS` to run `rake clear_backups`.
77
+ ## Usage
251
78
 
252
- $ rake clear_backups
79
+ See [doc/example.md](doc/example.md)
253
80
 
254
81
  ## License
255
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,7 +10,7 @@ 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.6.0')
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)/}) }
@@ -19,8 +19,9 @@ module Flexdot
19
19
  end
20
20
  end
21
21
 
22
- def initialize
22
+ def initialize(keep_max_count)
23
23
  backup_dir.mkpath unless backup_dir.exist?
24
+ @keep_max_count = keep_max_count
24
25
  @finished = false
25
26
  end
26
27
 
@@ -34,6 +35,16 @@ module Flexdot
34
35
  @finished = true
35
36
  end
36
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
+
37
48
  private
38
49
 
39
50
  def backup_dir
@@ -8,12 +8,12 @@ require_relative 'index'
8
8
 
9
9
  module Flexdot
10
10
  class Installer
11
- def initialize(name, dotfiles_dir, home_dir, output_colorize)
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
- @output = Output.new(@home_dir, colorize: output_colorize)
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)
@@ -23,11 +23,12 @@ module Flexdot
23
23
  end
24
24
 
25
25
  backup.finish!
26
+ backup.remove_outdated!
26
27
  end
27
28
 
28
29
  private
29
30
 
30
- attr_reader :name, :dotfiles_dir, :home_dir, :backup, :output
31
+ attr_reader :name, :home_dir, :dotfiles_dir, :backup, :output
31
32
 
32
33
  def install_link(dotfile_path, home_file_path)
33
34
  dotfile = @dotfiles_dir.join(dotfile_path).expand_path
data/lib/flexdot/tasks.rb CHANGED
@@ -10,10 +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, output_colorize)
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
16
- @output_colorize = output_colorize
15
+ @dotfiles_dir = Pathname.new(options.dotfiles_dir).expand_path
16
+ @options = options
17
17
  end
18
18
 
19
19
  def install
@@ -28,9 +28,9 @@ module Flexdot
28
28
  task index.name do
29
29
  installer = Installer.new(
30
30
  index.name,
31
- dotfiles_dir,
32
31
  home_dir,
33
- output_colorize
32
+ dotfiles_dir,
33
+ options
34
34
  )
35
35
  installer.install(index.filename)
36
36
  end
@@ -40,7 +40,7 @@ module Flexdot
40
40
 
41
41
  private
42
42
 
43
- attr_reader :dotfiles_dir, :home_dir, :output_colorize
43
+ attr_reader :home_dir, :dotfiles_dir, :options
44
44
 
45
45
  def indexes
46
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.2.0'
4
+ VERSION = '3.3.0'
5
5
  end
data/lib/flexdot.rb CHANGED
@@ -6,7 +6,31 @@ require_relative 'flexdot/version'
6
6
  require_relative 'flexdot/tasks'
7
7
 
8
8
  module Flexdot
9
- def self.setup(home_dir:, dotfiles_dir: '.', output_colorize: true)
10
- Tasks.new(dotfiles_dir, home_dir, output_colorize).install
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
11
35
  end
12
36
  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.2.0
4
+ version: 3.3.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-08-28 00:00:00.000000000 Z
11
+ date: 2022-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -48,12 +48,12 @@ files:
48
48
  - ".github/dependabot.yml"
49
49
  - ".github/workflows/test.yml"
50
50
  - ".gitignore"
51
- - CHANGELOG.md
52
51
  - CODE_OF_CONDUCT.md
53
52
  - Gemfile
54
53
  - LICENSE.txt
55
54
  - README.md
56
55
  - Rakefile
56
+ - doc/example.md
57
57
  - flexdot.gemspec
58
58
  - lib/flexdot.rb
59
59
  - lib/flexdot/backup.rb
@@ -74,14 +74,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
74
74
  requirements:
75
75
  - - ">="
76
76
  - !ruby/object:Gem::Version
77
- version: 2.6.0
77
+ version: 2.7.0
78
78
  required_rubygems_version: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  requirements: []
84
- rubygems_version: 3.2.22
84
+ rubygems_version: 3.3.3
85
85
  signing_key:
86
86
  specification_version: 4
87
87
  summary: A Flexible and Rake based dotfile manager
data/CHANGELOG.md DELETED
@@ -1 +0,0 @@
1
- Please see [the release page](https://github.com/hidakatsuya/flexdot/releases).