dotme 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YWZjNzlmOWU5NDFhZmIxZjMyY2FmNGU4MWMzYTZhNDAxOWY5NjZiMg==
5
+ data.tar.gz: !binary |-
6
+ MzMxNDFkYTY4NTA1M2ZiZTFkYWQ3ZTUzNGU2ZDczOTg0N2YzMjQ1Yg==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ OWY3MDNmMTUwODVhZjY0N2VjZmJjY2EyNmYyOGZkYzQzYTdjYTY0YjA3Yjhj
10
+ YjE2MzAwMTcyNTQ1ZWRhMGEzZWI2MDFjMGJkY2ZkYmRkODc2OWJiNWYyNmU3
11
+ ZGVjNDgyMTAwNmVkMGZmZDNiMjNlZjIwODdkZWFmYzE0Yjc0Y2Y=
12
+ data.tar.gz: !binary |-
13
+ ZmRlNDhhMTI5YTFiM2UxNjhlZWY4ZmJmY2EyNTcyMTk4ZDM2NGZmN2Q3Zjhl
14
+ MWM3ODZmYzgxYTIwYWYxODZmZTI2Yjg5ZGY2NDEwY2ZkZGUwMzZmNTRlOTMw
15
+ ZTg2ZmFlYzZjYmY4NjA2ZjUxOTA3MGU1MzBiZjY0OGRlYjM5N2I=
data/LICENSE ADDED
@@ -0,0 +1,28 @@
1
+ Software License Agreement (BSD License)
2
+
3
+ Copyright (c) 2013, Simone Margaritelli <evilsocket at gmail dot com>
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are met:
8
+
9
+ * Redistributions of source code must retain the above copyright notice,
10
+ this list of conditions and the following disclaimer.
11
+ * Redistributions in binary form must reproduce the above copyright
12
+ notice, this list of conditions and the following disclaimer in the
13
+ documentation and/or other materials provided with the distribution.
14
+ * Neither the name of DotMe nor the names of its contributors may be used
15
+ to endorse or promote products derived from this software without
16
+ specific prior written permission.
17
+
18
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28
+ POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,42 @@
1
+ DotMe [![Gem Version](https://badge.fury.io/rb/dotme.png)](http://badge.fury.io/rb/dotme)
2
+ ========================
3
+
4
+ DotMe is a dot files management system for human beings.
5
+
6
+ <http://rubygems.org/gems/dotme>
7
+
8
+ Installation and Usage
9
+ ------------------------
10
+
11
+ You can verify your installation using this piece of code:
12
+
13
+ gem install dotme
14
+
15
+ And
16
+
17
+ # dotme --help
18
+
19
+ You will be presented with the following output:
20
+
21
+ Usage: dotme ACTION [options]
22
+
23
+ Actions:
24
+ create Create your dot files archive.
25
+ install Use the Dotfile in current directory to install your dot files, this is the default action.
26
+
27
+ Options:
28
+ -T, --targets TARGETS Files and folders to backup. DEFAULT: .oh-my-zsh, .vimrc, .vim, .zshrc, .bashrc
29
+ -O, --output FOLDER Directory to store your dot files in. DEFAULT: dotfiles
30
+ -B, --backup FOLDER Backup directory to store existing dot files. DEFAULT: ~/dotfiles.backup
31
+ -P, --prepend COMMAND Prepend a custom command to the Dotfile, can be use multiple times.
32
+ -A, --append COMMAND Append a custom command to the Dotfile, can be use multiple times.
33
+
34
+ License
35
+ ---
36
+
37
+ Released under the BSD license.
38
+ Copyright &copy; 2013, Simone Margaritelli
39
+ <evilsocket@gmail.com>
40
+
41
+ <http://www.evilsocket.net/>
42
+ All rights reserved.
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require 'dotme/commander'
3
+
4
+ DotMe::Commander.dispatch!(ARGV)
@@ -0,0 +1,22 @@
1
+ require './lib/dotme/version'
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{dotme}
5
+ s.version = DotMe::VERSION
6
+ s.license = "BSD"
7
+
8
+ s.authors = ["Simone Margaritelli"]
9
+ s.description = %q{A gem to handle dot files easily.}
10
+ s.email = %q{evilsocket@gmail.com}
11
+ s.files = Dir.glob("lib/**/*") + Dir.glob("bin/*") + [
12
+ "LICENSE",
13
+ "README.md",
14
+ "dotme.gemspec"
15
+ ]
16
+ s.executables = %w(dotme)
17
+ s.homepage = %q{http://evilsocket.net/}
18
+ s.rdoc_options = ["--charset=UTF-8"]
19
+ s.require_paths = ["lib"]
20
+ s.summary = %q{A gem to handle dot files easily.}
21
+ end
22
+
@@ -0,0 +1,54 @@
1
+ require 'fileutils'
2
+ require 'dotme/incubator'
3
+ require 'dotme/loader'
4
+
5
+ if ::File.exist? $options[:output]
6
+ print "Folder '#{$options[:output]}' already exists, overwrite ? [y/N] "
7
+ overwrite = $stdin.gets.chop
8
+ exit unless overwrite == 'y' or overwrite == 'Y'
9
+ FileUtils.rm_rf $options[:output]
10
+ end
11
+
12
+ DotMe::Loader.load!
13
+
14
+ $options[:targets].each do |item|
15
+ begin
16
+ DotMe::Incubator.incubate item, $options[:output]
17
+ rescue DotMe::NoIncubator
18
+ puts "No suitable incubator for #{item}, skipping ..."
19
+ end
20
+ end
21
+
22
+ File.open( "#{$options[:output]}/Dotfile", 'w+t' ) do |dotfile|
23
+ dotfile << "backup #{$options[:targets]}, \"#{$options[:backup]}\"\n"
24
+ $options[:prepend].each do |command|
25
+ dotfile << "sh \"#{command}\"\n"
26
+ end
27
+ DotMe::Incubator.cells.each do |cell|
28
+ op, to, what, where = cell.keys + cell.values
29
+ dotfile << "#{op} \"#{what}\", \"#{where}\"\n"
30
+ end
31
+ $options[:append].each do |command|
32
+ dotfile << "sh \"#{command}\"\n"
33
+ end
34
+ end
35
+
36
+ File.open( "#{$options[:output]}/README.md", 'w+t' ) do |readme|
37
+ readme << <<README
38
+ DotMe - My personal dot files.
39
+ ===
40
+
41
+ This is my personal dot files archive easily generated with [DotMe](http://rubygems.org/gems/dotme) using the following command line:
42
+
43
+ dotme #{$options[:cmdline]}
44
+
45
+ ## Requirements
46
+
47
+ In order to install this archive to your system, you will need ruby installed and the dotme gem.
48
+
49
+ ## Installation
50
+
51
+ cd path-to/#{$options[:output]} && dotme
52
+
53
+ README
54
+ end
@@ -0,0 +1,7 @@
1
+ require 'dotme/dsl'
2
+
3
+ if File.exists? 'Dotfile'
4
+ DotMe::Dsl.run 'Dotfile'
5
+ else
6
+ puts 'No Dotfile found.'
7
+ end
@@ -0,0 +1,57 @@
1
+ require 'optparse'
2
+
3
+ module DotMe
4
+ class Commander
5
+ def self.dispatch!(argv)
6
+ # make this global to let load-ed actions use it
7
+ $options = {
8
+ :cmdline => ARGV.join(' '),
9
+ :action => argv[0] || 'install',
10
+ :verbose => true,
11
+ :targets => [ '.oh-my-zsh', '.fonts', '.vimrc', '.vim', '.zshrc', '.bashrc' ],
12
+ :output => 'dotfiles',
13
+ :backup => '~/dotfiles.backup',
14
+ :prepend => [],
15
+ :append => []
16
+ }
17
+
18
+ OptionParser.new do |opts|
19
+ opts.banner = <<HELP
20
+ Usage: dotme ACTION [options]
21
+
22
+ Actions:
23
+ create Create your dot files archive.
24
+ install Use the Dotfile in current directory to install your dot files, this is the default action.
25
+
26
+ Options:
27
+ HELP
28
+ opts.on( '-T', '--targets TARGETS', "Files and folders to backup. DEFAULT: #{$options[:targets].join(', ')}" ) do |targets|
29
+ $options[:targets] = targets.split ' '
30
+ end
31
+
32
+ opts.on( '-O', '--output FOLDER', "Directory to store your dot files in. DEFAULT: #{$options[:output]}" ) do |folder|
33
+ $options[:output] = folder
34
+ end
35
+
36
+ opts.on( '-B', '--backup FOLDER', "Backup directory to store existing dot files. DEFAULT: #{$options[:backup]}" ) do |folder|
37
+ $options[:backup] = folder
38
+ end
39
+
40
+ opts.on( '-P', '--prepend COMMAND', "Prepend a custom command to the Dotfile, can be use multiple times." ) do |command|
41
+ $options[:prepend] << command
42
+ end
43
+
44
+ opts.on( '-A', '--append COMMAND', "Append a custom command to the Dotfile, can be use multiple times." ) do |command|
45
+ $options[:append] << command
46
+ end
47
+
48
+ end.parse!
49
+
50
+ begin
51
+ load ::File.join ::File.dirname(__FILE__), "actions/#{$options[:action]}.rb"
52
+ rescue LoadError
53
+ puts "#{$options[:action]} - No such action."
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,50 @@
1
+ require 'fileutils'
2
+ require 'etc'
3
+
4
+ module DotMe
5
+ class Dsl
6
+ def self.run( filename )
7
+ self.new.instance_eval( ::File.read(filename), filename )
8
+ end
9
+
10
+ def _backup( what, where )
11
+ FileUtils.rm_rf where unless !::File.directory? where
12
+ Dir.mkdir where, 0700
13
+
14
+ what.each do |file|
15
+ from = ::File.join Etc.getpwuid.dir, file
16
+ unless file[0] != '.'
17
+ file = file[1..-1]
18
+ end
19
+ if File.exists? from
20
+ puts "Backupping #{from} to #{where} ..."
21
+ FileUtils.mv from, ::File.join( where, file )
22
+ end
23
+ end
24
+ end
25
+
26
+ def _link( what, where )
27
+ puts "Symlinking #{what} to #{where} ..."
28
+ what = File.absolute_path what
29
+ File.symlink what, where
30
+ end
31
+
32
+ def method_missing( name, *args )
33
+ name = "_#{name}"
34
+ if respond_to? name
35
+ args.each_with_index do |arg,i|
36
+ args[i] = arg.is_a?(String) ? arg.gsub( '~', Etc.getpwuid.dir ) : arg.map { |v| v.gsub( '~', Etc.getpwuid.dir ) }
37
+ end
38
+ send name.to_sym, *args
39
+ end
40
+ end
41
+
42
+ def git_clone( repo, where )
43
+ puts "GIT CLONE #{repo} #{where}"
44
+ end
45
+
46
+ def sh( cmd )
47
+ system cmd
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,3 @@
1
+ module DotMe
2
+ class NoIncubator < RuntimeError; end
3
+ end
@@ -0,0 +1,43 @@
1
+ require 'etc'
2
+ require 'dotme/errors'
3
+
4
+ module DotMe
5
+ class Incubator
6
+ @@incubators = []
7
+ @@cells = []
8
+
9
+ def initialize(path)
10
+ @path = path
11
+ @relative = @path.gsub( Etc.getpwuid.dir, '~' )
12
+ @basename = ::File.basename @path
13
+ unless @basename[0] != '.'
14
+ @basename = @basename[1..-1]
15
+ end
16
+ end
17
+
18
+ def self.register!(c)
19
+ raise TypeError, 'Not an Incubator derived class.' unless c.respond_to? :incubates?
20
+ @@incubators << c
21
+ end
22
+
23
+ def self.incubate(path,to)
24
+ path = ::File.join( Etc.getpwuid.dir, path ) unless ::File.exists? path
25
+
26
+ Dir.mkdir to, 0700 unless ::File.directory? to
27
+
28
+ puts "Incubating #{::File.basename path} to #{to}"
29
+ incubator = nil
30
+ # get the last valid incubator
31
+ @@incubators.each { |c| if c.incubates? path then incubator = c end }
32
+ unless incubator
33
+ raise NoIncubator
34
+ end
35
+
36
+ @@cells << incubator.new(path).incubate(to)
37
+ end
38
+
39
+ def self.cells
40
+ @@cells
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,16 @@
1
+ require 'fileutils'
2
+
3
+ module DotMe
4
+ class File < Incubator
5
+ def incubate(to)
6
+ FileUtils.cp_r @path, ::File.join( to, @basename )
7
+
8
+ { :link => @basename, :to => @relative }
9
+ end
10
+
11
+ def self.incubates?(path)
12
+ ::File.file? path
13
+ end
14
+ end
15
+ end
16
+
@@ -0,0 +1,21 @@
1
+ module DotMe
2
+ class Folder < Incubator
3
+ def incubate(*to)
4
+ begin
5
+ require 'git'
6
+
7
+ { :git_clone => Git.open( @path ).config['remote.origin.url'], :to => @relative }
8
+ rescue
9
+ FileUtils.cp_r @path, ::File.join( to, @basename )
10
+
11
+ { :link => @basename, :to => @relative }
12
+ end
13
+ end
14
+
15
+ def self.incubates?(path)
16
+ ::File.directory? path
17
+ end
18
+ end
19
+ end
20
+
21
+
@@ -0,0 +1,13 @@
1
+ module DotMe
2
+ class Loader
3
+ def self.load!
4
+ Dir[ ::File.join ::File.dirname(__FILE__), 'incubators/*.rb' ].each do |file|
5
+ begin
6
+ require file
7
+ clazz = DotMe.const_get file.gsub( /^.*incubators\/(.+)\.rb$/, '\1' ).capitalize
8
+ DotMe::Incubator.register! clazz
9
+ rescue; end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module DotMe
2
+ VERSION = '0.1.0'
3
+ end
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dotme
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Simone Margaritelli
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-08-20 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A gem to handle dot files easily.
14
+ email: evilsocket@gmail.com
15
+ executables:
16
+ - dotme
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/dotme/actions/create.rb
21
+ - lib/dotme/actions/install.rb
22
+ - lib/dotme/commander.rb
23
+ - lib/dotme/dsl.rb
24
+ - lib/dotme/errors.rb
25
+ - lib/dotme/incubator.rb
26
+ - lib/dotme/incubators/file.rb
27
+ - lib/dotme/incubators/folder.rb
28
+ - lib/dotme/loader.rb
29
+ - lib/dotme/version.rb
30
+ - bin/dotme
31
+ - LICENSE
32
+ - README.md
33
+ - dotme.gemspec
34
+ homepage: http://evilsocket.net/
35
+ licenses:
36
+ - BSD
37
+ metadata: {}
38
+ post_install_message:
39
+ rdoc_options:
40
+ - --charset=UTF-8
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ! '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ requirements: []
54
+ rubyforge_project:
55
+ rubygems_version: 2.0.6
56
+ signing_key:
57
+ specification_version: 4
58
+ summary: A gem to handle dot files easily.
59
+ test_files: []