dotmodule 0.0.1 → 0.0.2

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
  SHA1:
3
- metadata.gz: afb5ce73d11f4c18dab49f48ef961de191d90aac
4
- data.tar.gz: 35b34b660806d538df722e3380f53d1a35ddaba4
3
+ metadata.gz: 97a5f89a98b981463d33e24efb62b8027fe11064
4
+ data.tar.gz: 29f5b4893fe4355a1ab607566761abd20d9d5471
5
5
  SHA512:
6
- metadata.gz: 2f942872744724b7ee18100dae0db5e586aa37e9f900cc2bf94efe2f6eb2b81c837b825db3eb9cb75b5139d010aeb6964c385044be92cdb7334e382952503ec8
7
- data.tar.gz: 1c6876fe409f3ce28cee0ee89009ef235dce4f618aadb8b9d4eac67657b9179695b83852e31ebac0e3e43de91e2224609818864cda03a3815ae79e3357ecda21
6
+ metadata.gz: 54885352278cd8a5f1dc30adf05446d2028e3ffb43e368038ac4bd34ab5ab7d4697a891a483673577e0263fba78fc80dbf81bfcf24b594d1097bdcc896b83445
7
+ data.tar.gz: 2b0a4f1f1800763430233ea4dd4c1c5c50f777f9e0b5e091174415f5c8e4c6de44210e59c0fa09778248a3492e9409131e2f4a3e092b8a4294404e3938d96996
data/README.md CHANGED
@@ -1,38 +1,128 @@
1
1
  # Dotmodule
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/dotmodule`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ ## Overview
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ This is a simple management helper for modular dotfile repositories.
6
+
7
+ It decorates [GNU Stow](https://www.gnu.org/software/stow/) with a couple of minor but useful (to me) features:
8
+ - Pre- and post- installation scripts (e.g. to check out other projects from git -- i.e. spacemacs)
9
+ - Shared directory configuration via an optional config file (to safeguard against collisions between GNU Stow and other applications -- more detail below)
10
+ - Defining a subset of 'core' modules to be installed on all systems
11
+
12
+ This can be used with an existing stow link farm as-is, adding use of new features as needed on a per-module basis.
13
+
14
+ The (optional) configuration file is `dotmodule.collection`, a file in YAML format located at the collection root.
15
+ It is only required if defining shared folders and/or a core module set.
6
16
 
7
17
  ## Installation
8
18
 
9
- Add this line to your application's Gemfile:
19
+ $ gem install dotmodule
20
+
21
+ ## Usage
22
+
23
+ ### Basic usage
24
+
25
+ Organise your dotfiles in modules, one per directory (i.e. a standard link farm for GNU Stow). Given a dotmodule collection at ~/dotfiles...
10
26
 
11
- ```ruby
12
- gem 'dotmodule'
13
27
  ```
28
+ $ cd ~/dotfiles
29
+
30
+ $ dotmodule install
14
31
 
15
- And then execute:
32
+ Collection root: /home/cormacc/dotfiles
33
+ Default target: /home/cormacc
16
34
 
17
- $ bundle
35
+ Shared target subdirectories:
36
+ bin, .config, .profile.d
18
37
 
19
- Or install it yourself as:
38
+ Modules:
39
+ i3, vscode, fish, ruby, zsh, emacs, xorg, base, ssh, macbook
20
40
 
21
- $ gem install dotmodule
41
+ Core modules:
42
+ base, zsh, emacs, ssh, ruby
22
43
 
23
- ## Usage
24
44
 
25
- TODO: Write usage instructions here
45
+ No module argument passed. Install (c)ore/(a)ll/(n)one? [n]: c
46
+ Installing 5 modules ...
47
+ .. Module base ..
48
+ .. Module zsh ..
49
+ .. Module emacs ..
50
+ ... running hook 'pre': '/home/cormacc/dotfiles/emacs-pre'
51
+ .... WARNING: ~/.emacs.d found -- skipping spacemacs checkout
52
+ .. Module ssh ..
53
+ .. Module ruby ..
54
+
55
+ ```
56
+
57
+ N.B. Shared target subdirectories and core modules will be blank, unless configured in the optional collection config file
58
+
59
+ To install a specific module or modules
60
+
61
+ $dotmodule install MODULE_NAME
62
+
63
+ or
64
+
65
+ $dotmodule install MODULE_NAME, ANOTHER_MODULE_NAME
66
+
67
+ To display module collection parameters
68
+
69
+ $dotmodule info
70
+
71
+
72
+ ### Pre- and post-installation hooks (Optional)
73
+
74
+ Any file in the farm root matching the pattern '<modulename>-pre' or '<modulename>-post' will be treated as a pre- or post-
75
+ installation hook and executed before/after GNU stow. I use an 'emacs-pre' hook to clone the spacemacs repository. Similarly, could use a pre or post hook to copy your ssh keys from somewhere else (as you probably don't want them in a public dotfile repo).
76
+
77
+
78
+ ### Shared folders (Optional)
79
+
80
+ GNU Stow is clever at managing collisions between modules in a link farm, however we can run into issues when constructing symlinks into directory trees that are used by multiple applications -- e.g. `~/.config` -- resulting in unwanted data in your dotfile repo. To guard against this, you can declare these shared directories as a YAML list in a file called `dotmodule.collection` located at the root of your dotfile repository.
81
+
82
+ ```yaml
83
+ :shared_directories:
84
+ - bin
85
+ - .config
86
+ - .profile.d
87
+ - this/also/works/with/nested/paths
88
+ ```
89
+
90
+ The `dotmodule` gem will ensure these directories are created before installing any modules to prevent GNU Stow from creating them as links into your dotfile repository instead.
91
+
92
+ ### Core modules (Optional)
93
+
94
+ This is purely a convenience -- allowing you to quickly install essential modules without having to remove modules that are platform-specific you're not using any more but may again at a later date from your repo. These core modules are also defined in `dotmodule.collection`
95
+
96
+ ```yaml
97
+ :core_modules:
98
+ - base
99
+ - zsh
100
+ - emacs
101
+ - ssh
102
+ - ruby
103
+ ```
104
+
105
+ ### Examples
106
+
107
+ See [my dotfiles](https://github.com/cormacc/dotfiles) for an example.
108
+
109
+
110
+ ## Development / improvements
111
+
112
+ This is a pretty basic gem.
113
+
114
+ The majority of the functionality is defined in [DotModule::Collection](lib/dotmodule.rb)
26
115
 
27
- ## Development
116
+ This is wrapped in a basic [CLI](lib/dotmodule/CLI.rb) using [Thor](https://github.com/erikhuda/thor).
28
117
 
29
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
118
+ Unlike GNU Stow, the installation target directory is always the user home directory (internally, `Dir.home`) rather than the parent directory of the module collection. `DotModule::Collection` is setup to allow explicit target specification, but the CLI wrapper doesn't yet,
119
+ as I don't currently need it to. That said, it would probably only take slightly more time to change that than it has to write this paragraph :)
30
120
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
121
+ If you add to a module, you can just `dotmodule install` it again. However if you remove content you need to clean out stale links manually. Might be worth adding some logic to detect/delete stale links, and/or uninstall a module.
32
122
 
33
123
  ## Contributing
34
124
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/dotmodule.
125
+ Bug reports and pull requests are welcome on GitHub at https://github.com/cormacc/dotmodule.
36
126
 
37
127
 
38
128
  ## License
data/lib/dotmodule.rb CHANGED
@@ -49,7 +49,7 @@ module DotModule
49
49
  # Currently, this supports a single array entry listing any folders shared with other applications / the system
50
50
  def load_config
51
51
  file = root+CONFIG_FILE_NAME
52
- @config = file.file? ? YAML.load_file(file) : { :shared_directories => nil, :core_modules => nil }
52
+ @config = file.file? ? YAML.load_file(file) : { :shared_directories => [], :core_modules => [] }
53
53
  end
54
54
 
55
55
  def modules
@@ -65,7 +65,7 @@ module DotModule
65
65
  end
66
66
 
67
67
  def default_target
68
- @root.parent
68
+ Pathname.new(Dir.home)
69
69
  end
70
70
 
71
71
  def create_shared_directories(target_root)
@@ -80,10 +80,11 @@ module DotModule
80
80
 
81
81
  def install_module(name, target=default_target)
82
82
  create_shared_directories(target)
83
- puts "... installing #{name} ..."
83
+ puts ".. Module #{name} .."
84
84
  raise ArgumentError, "Module '#{name}' not found" unless (@root+name).directory?
85
-
85
+ preinstall(name)
86
86
  system "stow -d #{@root} -t #{target} #{name}"
87
+ postinstall(name)
87
88
  end
88
89
 
89
90
  def install_modules(module_names, target=default_target)
@@ -103,22 +104,42 @@ module DotModule
103
104
  end
104
105
 
105
106
  def to_s
106
- <<~HEREDOC
107
+ # <<~HEREDOC would be nicer, but not worth sacrificing compatibility with rubies <2.3 for
108
+ <<-HEREDOC
107
109
 
108
- Collection root: #{@root}
109
- Default target: #{default_target}
110
+ Collection root: #{@root}
111
+ Default target: #{default_target}
110
112
 
111
- Shared target subdirectories:
112
- #{shared_directories.join(', ')}
113
+ Shared target subdirectories:
114
+ #{shared_directories.join(', ')}
113
115
 
114
- Modules:
115
- #{modules.join(', ')}
116
+ Modules:
117
+ #{modules.join(', ')}
116
118
 
117
- Core modules:
118
- #{core_modules.join(', ')}
119
+ Core modules:
120
+ #{core_modules.join(', ')}
119
121
 
120
122
  HEREDOC
121
123
  end
124
+
125
+ private
126
+
127
+ def preinstall(module_name)
128
+ runhook(module_name, 'pre')
129
+ end
130
+
131
+ def postinstall(module_name)
132
+ runhook(module_name, 'post')
133
+ end
134
+
135
+ def runhook(module_name, hook)
136
+ hook_file = @root + "#{module_name}-#{hook}"
137
+ return unless hook_file.file?
138
+ puts "... running hook '#{hook}': '#{hook_file}'"
139
+ IO.popen("sh #{hook_file}").each do |line|
140
+ puts ".... #{line}"
141
+ end
142
+ end
122
143
  end
123
144
 
124
145
  end
@@ -1,3 +1,3 @@
1
1
  module DotModule
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dotmodule
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cormac Cannon
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-11-03 00:00:00.000000000 Z
11
+ date: 2016-11-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor