filedots 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in filedots.gemspec
4
+ gemspec
@@ -0,0 +1,17 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ filedots (0.0.1)
5
+ thor (>= 0.14.6)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ thor (0.14.6)
11
+
12
+ PLATFORMS
13
+ ruby
14
+
15
+ DEPENDENCIES
16
+ filedots!
17
+ thor (>= 0.14.6)
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "filedots"
4
+
5
+ Filedots::Runner.start
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "filedots/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "filedots"
7
+ s.version = Filedots::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["miaout17"]
10
+ s.email = ["miaout17@gmail.com"]
11
+ s.homepage = ""
12
+ s.summary = %q{A simple dotfiles installation tool}
13
+ s.description = %q{A simple dotfiles installation tool}
14
+
15
+ s.rubyforge_project = "filedots"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_dependency "thor", ">= 0.14.6"
23
+ end
@@ -0,0 +1,3 @@
1
+ require 'filedots/runner'
2
+ require 'filedots/config'
3
+
@@ -0,0 +1,23 @@
1
+ module Filedots
2
+ class Config
3
+
4
+ attr_accessor :links
5
+
6
+ def initialize
7
+ @links = []
8
+ end
9
+
10
+ def link(source, target=nil)
11
+ if source.is_a?(Array)
12
+ source.each { |s| link(s) }
13
+ return
14
+ end
15
+
16
+ target ||= File.expand_path("~/.#{source}")
17
+ source = File.expand_path("#{Dir.pwd}/#{source}")
18
+
19
+ @links << [source, target]
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,61 @@
1
+ require 'thor'
2
+
3
+ module Filedots
4
+ class Runner < Thor
5
+ include Thor::Actions
6
+
7
+ desc 'install', 'Install dotfiles'
8
+ def install
9
+ return unless load_config
10
+ @config.links.each do |source, target|
11
+ link(source, target)
12
+ end
13
+ end
14
+
15
+ desc 'uninstall', 'Uninstall dotfiles'
16
+ def uninstall
17
+ return unless load_config
18
+ @config.links.each do |source, target|
19
+ unlink(target)
20
+ end
21
+ end
22
+
23
+ no_tasks do
24
+ def load_config
25
+ @config = Config.new
26
+ @config.instance_eval(File.read('.filedots'))
27
+ true
28
+ end
29
+
30
+ def link(source, target)
31
+ if File.exists?(target)
32
+ # TODO: This is not accuracy.
33
+ # Check the link, make some test cases....when I have more free time :)
34
+ if File.identical?(source, target)
35
+ say_status :identical, target
36
+ else
37
+ link!(source, target) if yes?("Overwrite #{target}?", :red)
38
+ end
39
+ else
40
+ link!(source, target)
41
+ end
42
+ end
43
+
44
+ def link!(source, target)
45
+ File.unlink(target) if File.exists?(target)
46
+ File.symlink(source, target)
47
+ say_status :symlink, "#{source} #{target}"
48
+ end
49
+
50
+ def unlink(target)
51
+ # TODO: Alert if it's not symlink?
52
+ if File.exists?(target)
53
+ File.unlink(target)
54
+ say_status :unlink, target
55
+ else
56
+ say_status :nonexist, target
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,3 @@
1
+ module Filedots
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: filedots
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - miaout17
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-08-14 00:00:00 +08:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: thor
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 43
30
+ segments:
31
+ - 0
32
+ - 14
33
+ - 6
34
+ version: 0.14.6
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ description: A simple dotfiles installation tool
38
+ email:
39
+ - miaout17@gmail.com
40
+ executables:
41
+ - filedots
42
+ extensions: []
43
+
44
+ extra_rdoc_files: []
45
+
46
+ files:
47
+ - .gitignore
48
+ - Gemfile
49
+ - Gemfile.lock
50
+ - Rakefile
51
+ - bin/filedots
52
+ - filedots.gemspec
53
+ - lib/filedots.rb
54
+ - lib/filedots/config.rb
55
+ - lib/filedots/runner.rb
56
+ - lib/filedots/version.rb
57
+ has_rdoc: true
58
+ homepage: ""
59
+ licenses: []
60
+
61
+ post_install_message:
62
+ rdoc_options: []
63
+
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ hash: 3
72
+ segments:
73
+ - 0
74
+ version: "0"
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ hash: 3
81
+ segments:
82
+ - 0
83
+ version: "0"
84
+ requirements: []
85
+
86
+ rubyforge_project: filedots
87
+ rubygems_version: 1.3.7
88
+ signing_key:
89
+ specification_version: 3
90
+ summary: A simple dotfiles installation tool
91
+ test_files: []
92
+