dotmodule 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: afb5ce73d11f4c18dab49f48ef961de191d90aac
4
+ data.tar.gz: 35b34b660806d538df722e3380f53d1a35ddaba4
5
+ SHA512:
6
+ metadata.gz: 2f942872744724b7ee18100dae0db5e586aa37e9f900cc2bf94efe2f6eb2b81c837b825db3eb9cb75b5139d010aeb6964c385044be92cdb7334e382952503ec8
7
+ data.tar.gz: 1c6876fe409f3ce28cee0ee89009ef235dce4f618aadb8b9d4eac67657b9179695b83852e31ebac0e3e43de91e2224609818864cda03a3815ae79e3357ecda21
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /.idea/
11
+ /*.gem
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in dotmodule.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Cormac Cannon
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # Dotmodule
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.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'dotmodule'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install dotmodule
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
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.
30
+
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).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/dotmodule.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "dotmodule"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ #require "pry"
11
+ #Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/dotmodule.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'dotmodule/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'dotmodule'
8
+ spec.version = DotModule::VERSION
9
+ spec.authors = ['Cormac Cannon']
10
+ spec.email = ['cormacc.public@gmail.com']
11
+
12
+ spec.summary = %q{Manage dotfiles in a modular fashion using GNU Stow}
13
+ spec.description = %q{Wraps GNU stow, using a set of conventions for additions to load path, bash/zsh environment etc.}
14
+ spec.homepage = 'https://rubygems.org/gems/dotmodule'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = 'exe'
21
+ spec.executables = spec.files.grep(%r{^#{spec.bindir}/}) { |f| File.basename(f) }
22
+ spec.require_paths = ['lib']
23
+
24
+ spec.add_runtime_dependency 'thor', '~> 0.19.1'
25
+
26
+ spec.add_development_dependency 'bundler', '~> 1.13'
27
+ spec.add_development_dependency 'rake', '~> 10.0'
28
+ end
data/exe/dotmodule ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require 'dotmodule'
3
+
4
+ DotModule::CLI.start(ARGV)
@@ -0,0 +1,28 @@
1
+ require 'thor'
2
+
3
+ module DotModule
4
+ class CLI < Thor
5
+ desc 'install', 'Install one or more modules'
6
+ # option :modules, :type => :array
7
+ def install(*modules)
8
+ collection = DotModule::Collection.new(Dir.pwd)
9
+ if modules.size.zero?
10
+ modules = case ask("#{collection}\nNo module argument passed. Install (c)ore/(a)ll/(n)one? [n]:").downcase
11
+ when 'a'
12
+ collection.modules
13
+ when 'c'
14
+ collection.core_modules
15
+ else #none
16
+ []
17
+ end
18
+ end
19
+ collection.install_modules(modules)
20
+ end
21
+
22
+ desc 'info', 'List module collection details'
23
+ def info
24
+ collection = DotModule::Collection.new(Dir.pwd)
25
+ puts collection
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,3 @@
1
+ module DotModule
2
+ VERSION = "0.0.1"
3
+ end
data/lib/dotmodule.rb ADDED
@@ -0,0 +1,124 @@
1
+ require 'dotmodule/version'
2
+ require 'dotmodule/cli'
3
+
4
+ require 'fileutils'
5
+ require 'pathname'
6
+ require 'yaml'
7
+
8
+ ##
9
+ # Ruby wrapper for GNU stow, designed for modular dotfile maintenance
10
+ #
11
+ # It doesn't really do a huge amount.
12
+ # In addition to creating symlinks using stow, it allows a set of DOT_PATHS
13
+ # to be defined. These may exist in multiple modules and are created prior to
14
+ # installing any module if not already present.
15
+ #
16
+ # GNU Stow is already clever enough to manage this well, for the most part,
17
+ # however this gets around a corner case with paths also used by the system
18
+ # e.g. ~/.config...
19
+ # Given a module a containing a subdirectory .config/A
20
+ # On a clean system (with no existing ~/.config dir), installing just the i3
21
+ # module will create a symlink ~/.config -> ~/dotfiles/A/.config
22
+ # Installing another module B which contains .config/B will happily replace
23
+ # that symlink with a directory ~/.config containg two symlinks,
24
+ # ~/.config/A -> ~/dotfiles/A/.config/A
25
+ # ~/.config/B -> ~/dotfiles/B/.config/B
26
+ # If another application has created a directory in .config in the meantime,
27
+ # however, this directory will now.
28
+ #
29
+ # Short version -- it is only necessary to define paths as DOT_PATHs if they
30
+ # are likely to be written to by applications/scripts outside the dotmodule
31
+ # framework
32
+ module DotModule
33
+
34
+ ##
35
+ # A collection of modules, with an optional YAML configuration file
36
+ class Collection
37
+
38
+ CONFIG_FILE_NAME = 'dotmodule.collection'.freeze
39
+ attr_reader :root
40
+
41
+ def initialize(root_path = Dir.pwd)
42
+ @root = Pathname.new(root_path).expand_path
43
+ raise ArgumentError, "Directory '#{@root}' not found" unless @root.directory?
44
+ load_config
45
+ end
46
+
47
+ ##
48
+ # Load the optional YAML configuration file
49
+ # Currently, this supports a single array entry listing any folders shared with other applications / the system
50
+ def load_config
51
+ file = root+CONFIG_FILE_NAME
52
+ @config = file.file? ? YAML.load_file(file) : { :shared_directories => nil, :core_modules => nil }
53
+ end
54
+
55
+ def modules
56
+ @root.children.select(&:directory?).map(&:basename).map(&:to_s).reject {|d| d.start_with?('.')}
57
+ end
58
+
59
+ def shared_directories
60
+ @config[:shared_directories]
61
+ end
62
+
63
+ def core_modules
64
+ @config[:core_modules]
65
+ end
66
+
67
+ def default_target
68
+ @root.parent
69
+ end
70
+
71
+ def create_shared_directories(target_root)
72
+ shared_directories.each do |dir|
73
+ abs_path = Pathname.new(target_root + dir).expand_path
74
+ unless abs_path.directory?
75
+ puts "Directory '#{abs_path}' not found, creating..."
76
+ FileUtils.mkdir_p(abs_path)
77
+ end
78
+ end
79
+ end
80
+
81
+ def install_module(name, target=default_target)
82
+ create_shared_directories(target)
83
+ puts "... installing #{name} ..."
84
+ raise ArgumentError, "Module '#{name}' not found" unless (@root+name).directory?
85
+
86
+ system "stow -d #{@root} -t #{target} #{name}"
87
+ end
88
+
89
+ def install_modules(module_names, target=default_target)
90
+ puts "Installing #{module_names.size} modules ..." unless modules.size.zero?
91
+ module_names.each do |m|
92
+ begin
93
+ install_module(m)
94
+ rescue ArgumentError
95
+ puts "WARNING: Module '#{m}' not found"
96
+ break unless ask('... (a)bort or (c)ontinue [a]: ') == 'c'
97
+ end
98
+ end
99
+ end
100
+
101
+ def install_all(target=default_target)
102
+ install_modules(modules)
103
+ end
104
+
105
+ def to_s
106
+ <<~HEREDOC
107
+
108
+ Collection root: #{@root}
109
+ Default target: #{default_target}
110
+
111
+ Shared target subdirectories:
112
+ #{shared_directories.join(', ')}
113
+
114
+ Modules:
115
+ #{modules.join(', ')}
116
+
117
+ Core modules:
118
+ #{core_modules.join(', ')}
119
+
120
+ HEREDOC
121
+ end
122
+ end
123
+
124
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dotmodule
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Cormac Cannon
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-11-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.19.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.19.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.13'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.13'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: Wraps GNU stow, using a set of conventions for additions to load path,
56
+ bash/zsh environment etc.
57
+ email:
58
+ - cormacc.public@gmail.com
59
+ executables:
60
+ - dotmodule
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - ".gitignore"
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - bin/console
70
+ - bin/setup
71
+ - dotmodule.gemspec
72
+ - exe/dotmodule
73
+ - lib/dotmodule.rb
74
+ - lib/dotmodule/cli.rb
75
+ - lib/dotmodule/version.rb
76
+ homepage: https://rubygems.org/gems/dotmodule
77
+ licenses:
78
+ - MIT
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.5.1
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: Manage dotfiles in a modular fashion using GNU Stow
100
+ test_files: []