dotify 0.0.3 → 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/.rspec +2 -0
- data/.travis.yml +1 -0
- data/README.md +22 -2
- data/Rakefile +0 -7
- data/dotify.gemspec +2 -2
- data/lib/dotify.rb +1 -3
- data/lib/dotify/cli.rb +46 -97
- data/lib/dotify/config.rb +90 -0
- data/lib/dotify/errors.rb +3 -0
- data/lib/dotify/files.rb +64 -0
- data/lib/dotify/version.rb +1 -1
- data/spec/dotify/cli_spec.rb +3 -49
- data/spec/dotify/config_spec.rb +57 -0
- data/spec/dotify/files_spec.rb +104 -0
- data/spec/fixtures/.dotrc-default +2 -0
- data/spec/fixtures/.dotrc-mattbridges +3 -0
- data/spec/spec_helper.rb +3 -0
- data/spec/support/fake.rb +39 -0
- metadata +17 -4
data/.gitignore
CHANGED
data/.rspec
CHANGED
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# Dotify
|
2
2
|
|
3
|
-
|
3
|
+
[![Build Status](https://secure.travis-ci.org/mattdbridges/dotify.png)](http://travis-ci.org/mattdbridges/dotify) [![Dependency Status](https://gemnasium.com/mattdbridges/dotify.png)](https://gemnasium.com/mattdbridges/dotify)
|
4
|
+
|
5
|
+
Dotify is a simple CLI tool to make managing dotfiles on your system easy. When developing on a Linux/Unix basic system, keeping track of all of those dotfiles in the home directory can be pain. Some developers do not even bother managing them and many have come up with their own static or even dynamic way of managing them. This is a need in the community to make managing these crazy files a breeze.
|
4
6
|
|
5
7
|
## Installation
|
6
8
|
|
@@ -18,10 +20,28 @@ Or install it yourself as:
|
|
18
20
|
|
19
21
|
## Usage
|
20
22
|
|
21
|
-
|
23
|
+
As dotify is a CLI tool, everything is done in the command line. Here are the current available methods for managing dotfiles.
|
24
|
+
|
25
|
+
### `dotify setup`
|
26
|
+
|
27
|
+
`dotify setup` will first create a `~/.dotify` directory in your home directory (yes, one more, but this is a good thing). It will then ask which files you want to copy from your home directory into your `.dotify` directory.
|
28
|
+
|
29
|
+
**Note:** This will *not* link up the dotfiles. This command simply copies the files over for you without having to go searching for them manually.
|
30
|
+
|
31
|
+
### `dotify link`
|
32
|
+
|
33
|
+
This is the heart of the Dotify tool. This command will link all of the files within the `.dotify` directory into your home directory.
|
34
|
+
|
35
|
+
### `dotify unlink`
|
36
|
+
|
37
|
+
Don't want and of the dotfiles anymore? Sure. You can wipe them out.
|
38
|
+
|
39
|
+
Since this is a non-destructive task, you can simply run `dotify link` again if you want to restore your previous settings.
|
22
40
|
|
23
41
|
## Contributing
|
24
42
|
|
43
|
+
This tool is developed with much influence from *37singals*' fantastic idea of **Do Less**. This is meant to be a *simple* tool. I am more than happy to add small features, but I do not want this turning into an RVM.
|
44
|
+
|
25
45
|
1. Fork it
|
26
46
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
47
|
3. Commit your changes (`git commit -am 'Added some feature'`)
|
data/Rakefile
CHANGED
data/dotify.gemspec
CHANGED
@@ -4,8 +4,8 @@ require File.expand_path('../lib/dotify/version', __FILE__)
|
|
4
4
|
Gem::Specification.new do |gem|
|
5
5
|
gem.authors = ["Matt Bridges"]
|
6
6
|
gem.email = ["mbridges.91@gmail.com"]
|
7
|
-
gem.description = %q{A CLI Tool for managing your dotfiles
|
8
|
-
gem.summary = %q{A CLI Tool for managing your dotfiles
|
7
|
+
gem.description = %q{A CLI Tool for managing your dotfiles}
|
8
|
+
gem.summary = %q{A CLI Tool for managing your dotfiles}
|
9
9
|
gem.homepage = "https://github.com/mattdbridges/dotify"
|
10
10
|
|
11
11
|
gem.files = `git ls-files`.split($\)
|
data/lib/dotify.rb
CHANGED
data/lib/dotify/cli.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
require 'thor'
|
2
|
-
require 'thor/util'
|
3
2
|
require 'dotify'
|
4
|
-
require 'dotify/
|
5
|
-
require '
|
3
|
+
require 'dotify/config'
|
4
|
+
require 'dotify/files'
|
6
5
|
require 'fileutils'
|
7
6
|
|
7
|
+
Dotify::Config.load_config!
|
8
|
+
|
8
9
|
module Dotify
|
9
10
|
class CLI < Thor
|
10
11
|
include Thor::Actions
|
@@ -15,121 +16,69 @@ module Dotify
|
|
15
16
|
map "-b" => "backup"
|
16
17
|
map "-r" => "restore"
|
17
18
|
|
18
|
-
DOTIFY_DIR_NAME = ENV['DOTIFY_DIR_NAME'] || '.dotify'
|
19
|
-
DOTIFY_PATH = ENV['DOTIFY_PATH'] || "#{Thor::Util.user_home}/#{DOTIFY_DIR_NAME}"
|
20
|
-
DOTIFY_BACKUP_PATH = ENV['DOTIFY_BACKUP_PATH'] || "#{DOTIFY_PATH}/.backup"
|
21
|
-
|
22
19
|
def self.source_root
|
23
|
-
|
20
|
+
Config.home
|
24
21
|
end
|
25
22
|
|
26
|
-
desc :setup, "
|
23
|
+
desc :setup, "Setup your system for Dotify to manage your dotfiles"
|
27
24
|
def setup
|
28
|
-
|
25
|
+
empty_directory(Config.path) unless File.directory?(Config.path)
|
26
|
+
Dir[File.join(Config.home, ".*")].each do |file|
|
27
|
+
filename = Files.file_name(file)
|
28
|
+
dotify_file = File.join(Config.path, filename)
|
29
|
+
unless ['.', '..', Config.dirname].include? filename
|
30
|
+
if yes?("Do you want to add #{filename} to Dotify? [Yn]", :yellow)
|
31
|
+
if File.directory?(Files.dotfile(file))
|
32
|
+
FileUtils.rm_rf dotify_file
|
33
|
+
FileUtils.cp_r Files.dotfile(file), dotify_file
|
34
|
+
say_status :create, dotify_file
|
35
|
+
else
|
36
|
+
copy_file Files.dotfile(file), dotify_file
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
say "Dotify has been successfully setup.", :blue
|
29
42
|
end
|
30
43
|
|
31
|
-
desc :link, "Link up your dotfiles"
|
32
|
-
method_option :
|
44
|
+
desc :link, "Link up all of your dotfiles"
|
45
|
+
method_option :all, :default => false, :type => :boolean, :aliases => '-a', :desc => "Link dotfiles without confirmation"
|
33
46
|
def link
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
replace_link dotfile_location(file), file
|
47
|
+
count = 0
|
48
|
+
Files.dots do |file, dot|
|
49
|
+
if options[:all]
|
50
|
+
if File.exists? Files.dotfile(file)
|
51
|
+
replace_link Files.dotfile(file), file
|
40
52
|
else
|
41
|
-
create_link
|
53
|
+
create_link Files.dotfile(file), file
|
54
|
+
end
|
55
|
+
count += 1
|
56
|
+
else
|
57
|
+
if yes?("Do you want to link ~/#{dot}? [Yn]", :green)
|
58
|
+
create_link Files.dotfile(file), file
|
59
|
+
count += 1
|
42
60
|
end
|
43
61
|
end
|
44
62
|
end
|
63
|
+
say "No files were linked.", :yellow if count == 0
|
45
64
|
end
|
46
65
|
|
47
|
-
desc :unlink, "Unlink
|
48
|
-
method_option :
|
66
|
+
desc :unlink, "Unlink all of your dotfiles"
|
67
|
+
method_option :all, :default => false, :type => :boolean, :aliases => '-a', :desc => 'Remove all installed dotfiles without confirmation'
|
49
68
|
def unlink
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
remove_file dotfile_location(file), :verbose => true
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
desc :backup, "Backup your dotfiles for quick recovery if something goes wrong"
|
59
|
-
def backup
|
60
|
-
dotfile_list do |file|
|
61
|
-
file = filename(file)
|
62
|
-
backup = "#{DOTIFY_BACKUP_PATH}/#{file}"
|
63
|
-
if File.exists?(dotfile_location(file))
|
64
|
-
remove_file backup, :verbose => false if File.exists?(backup)
|
65
|
-
copy_file dotfile_location(file), backup, :verbose => false
|
66
|
-
say "Backing up ~/#{file}", :blue
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
desc :restore, "Restore your backed-up dotfiles"
|
72
|
-
method_option :force, :default => false, :type => :boolean, :aliases => '-f', :desc => "Backup existing dotfiles"
|
73
|
-
def restore
|
74
|
-
backup_list do |file|
|
75
|
-
filename = filename(file)
|
76
|
-
if options.force? || yes?("Are you sure you want to restore ~/#{filename}? [Yn]", :red)
|
77
|
-
if File.exists?(dotfile_location(filename))
|
78
|
-
remove_file dotfile_location(filename), :verbose => false
|
79
|
-
end
|
80
|
-
copy_file file, dotfile_location(filename), :verbose => false
|
81
|
-
say "Restoring up ~/#{filename}", :blue
|
69
|
+
Files.installed do |file, dot|
|
70
|
+
if options[:all] || yes?("Are you sure you want to remove ~/#{dot}? [Yn]", :blue)
|
71
|
+
remove_file Files.dotfile(file)
|
82
72
|
end
|
83
73
|
end
|
84
74
|
end
|
85
75
|
|
86
76
|
no_tasks do
|
87
77
|
|
88
|
-
def dotfile_location(file)
|
89
|
-
"#{home}/#{filename(file)}"
|
90
|
-
end
|
91
|
-
|
92
|
-
def no_extension(file)
|
93
|
-
file = file.split('.')
|
94
|
-
file.pop
|
95
|
-
file.join('.')
|
96
|
-
end
|
97
|
-
|
98
|
-
def home
|
99
|
-
Thor::Util.user_home
|
100
|
-
end
|
101
|
-
|
102
78
|
def replace_link(dotfile, file)
|
103
|
-
remove_file dotfile
|
104
|
-
create_link dotfile, file
|
105
|
-
|
106
|
-
|
107
|
-
def dotfile_list
|
108
|
-
files = Dir["#{DOTIFY_PATH}/.*"]
|
109
|
-
files.delete_if { |f| File.directory? f }
|
110
|
-
if block_given?
|
111
|
-
files.each { |f| yield f }
|
112
|
-
else
|
113
|
-
files
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
def backup_list
|
118
|
-
files = Dir["#{DOTIFY_BACKUP_PATH}/.*"]
|
119
|
-
files.delete_if { |f| File.directory? f }
|
120
|
-
if block_given?
|
121
|
-
files.each { |f| yield f }
|
122
|
-
else
|
123
|
-
files
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
def filename(file)
|
128
|
-
file.split("/").last
|
129
|
-
end
|
130
|
-
|
131
|
-
def template?(file)
|
132
|
-
filename(file).match(/(tt|erb)$/)
|
79
|
+
remove_file dotfile, :verbose => false
|
80
|
+
create_link dotfile, file, :verbose => false
|
81
|
+
say_status :replace, dotfile
|
133
82
|
end
|
134
83
|
|
135
84
|
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'dotify'
|
2
|
+
require 'thor/util'
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
module Dotify
|
6
|
+
class Config
|
7
|
+
|
8
|
+
DOTIFY_DIRNAME = '.dotify'
|
9
|
+
DOTIFY_BACKUP = '.backup'
|
10
|
+
#SHELLS = {
|
11
|
+
# 'zsh' => '/bin/zsh',
|
12
|
+
# 'bash' => '/bin/bash',
|
13
|
+
# 'sh' => '/bin/sh'
|
14
|
+
#}
|
15
|
+
|
16
|
+
class << self
|
17
|
+
|
18
|
+
#def shell=(shell)
|
19
|
+
# if !SHELLS.keys.include?(shell)
|
20
|
+
# raise NonValidShell, "You must specify a valid shell: #{SHELLS.keys.map(&:inspect).join(", ")}"
|
21
|
+
# end
|
22
|
+
# @shell = shell
|
23
|
+
#end
|
24
|
+
|
25
|
+
#def shell
|
26
|
+
# @shell
|
27
|
+
#end
|
28
|
+
|
29
|
+
#def profile=(name)
|
30
|
+
# @profile = name
|
31
|
+
#end
|
32
|
+
|
33
|
+
#def profile
|
34
|
+
# @profile
|
35
|
+
#end
|
36
|
+
|
37
|
+
def dirname
|
38
|
+
@dirname ||= DOTIFY_DIRNAME
|
39
|
+
end
|
40
|
+
|
41
|
+
def path
|
42
|
+
File.join(home, dirname)
|
43
|
+
end
|
44
|
+
|
45
|
+
def backup
|
46
|
+
File.join(path, backup_dirname)
|
47
|
+
end
|
48
|
+
|
49
|
+
def backup_dirname
|
50
|
+
@backup ||= DOTIFY_BACKUP
|
51
|
+
end
|
52
|
+
|
53
|
+
def load_config!
|
54
|
+
#@config = File.exists?(config_file) ? (YAML.load_file(config_file) || {}) : {}
|
55
|
+
#symbolize_keys!(@config)
|
56
|
+
#@config.each do |key, value|
|
57
|
+
# if !value.nil? && methods(false).map(&:to_s).include?("#{key}=")
|
58
|
+
# self.__send__("#{key}=", value)
|
59
|
+
# else
|
60
|
+
# @config.delete(key)
|
61
|
+
# end
|
62
|
+
#end
|
63
|
+
#@config
|
64
|
+
end
|
65
|
+
|
66
|
+
def config
|
67
|
+
@config || load_config!
|
68
|
+
end
|
69
|
+
|
70
|
+
def home
|
71
|
+
Thor::Util.user_home
|
72
|
+
end
|
73
|
+
|
74
|
+
private
|
75
|
+
|
76
|
+
def config_file
|
77
|
+
#File.join(home, '.dotrc')
|
78
|
+
end
|
79
|
+
|
80
|
+
def symbolize_keys!(opts)
|
81
|
+
sym_opts = {}
|
82
|
+
opts.each do |key, value|
|
83
|
+
sym_opts[key.to_sym] = value.is_a?(Hash) ? symbolize_keys!(value) : value
|
84
|
+
end
|
85
|
+
sym_opts
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
data/lib/dotify/files.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'dotify'
|
2
|
+
require 'thor/actions'
|
3
|
+
require 'thor/shell'
|
4
|
+
|
5
|
+
Dotify::Config.load_config!
|
6
|
+
|
7
|
+
module Dotify
|
8
|
+
class Files
|
9
|
+
class << self
|
10
|
+
include Thor::Shell
|
11
|
+
include Thor::Actions
|
12
|
+
|
13
|
+
def dots
|
14
|
+
@dots ||= file_list(File.join(dotify_path, "/.*"))
|
15
|
+
return @dots unless block_given?
|
16
|
+
@dots.each {|d| yield(d, file_name(d)) }
|
17
|
+
end
|
18
|
+
|
19
|
+
def installed
|
20
|
+
dots = self.dots.map { |f| file_name(f) }
|
21
|
+
installed = file_list(File.join(Config.home, ".*")).select do |i|
|
22
|
+
dots.include?(file_name(i))
|
23
|
+
end
|
24
|
+
return installed unless block_given?
|
25
|
+
installed.each {|i| yield(i, file_name(i)) }
|
26
|
+
end
|
27
|
+
|
28
|
+
def file_name(file)
|
29
|
+
file.split("/").last
|
30
|
+
end
|
31
|
+
|
32
|
+
def template?(file)
|
33
|
+
file_name(file).match(/(tt|erb)$/) ? true : false
|
34
|
+
end
|
35
|
+
|
36
|
+
def dotfile(file)
|
37
|
+
File.join(Config.home, file_name(file))
|
38
|
+
end
|
39
|
+
|
40
|
+
def link_dotfile(file)
|
41
|
+
FileUtils.ln_s(file_name(file), Config.home) == 0 ? true : false
|
42
|
+
end
|
43
|
+
|
44
|
+
def unlink_dotfile(file)
|
45
|
+
FileUtils.rm_rf File.join(Config.home, file_name(file))
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def file_list(dir_glob)
|
51
|
+
filter_dot_directories!(Dir[dir_glob])
|
52
|
+
end
|
53
|
+
|
54
|
+
def filter_dot_directories!(files)
|
55
|
+
files.select { |f| !['.', '..'].include?(file_name(f)) }
|
56
|
+
end
|
57
|
+
|
58
|
+
def dotify_path
|
59
|
+
Config.path
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/lib/dotify/version.rb
CHANGED
data/spec/dotify/cli_spec.rb
CHANGED
@@ -1,54 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require 'dotify/config'
|
2
3
|
require 'dotify/cli'
|
4
|
+
require 'thor'
|
3
5
|
|
4
6
|
describe Dotify::CLI do
|
5
|
-
|
6
|
-
let(:cli) { Dotify::CLI }
|
7
|
-
let(:dotify_path) { cli::DOTIFY_PATH }
|
8
|
-
|
9
|
-
before do
|
10
|
-
FileUtils.mkdir_p dotify_path
|
11
|
-
end
|
12
|
-
|
13
|
-
after do
|
14
|
-
FileUtils.rm_rf dotify_path
|
15
|
-
end
|
16
|
-
|
17
|
-
describe Dotify::CLI, "#setup" do
|
18
|
-
it "it should create the right directory" do
|
19
|
-
FileUtils.should_receive(:mkdir_p).with(dotify_path)
|
20
|
-
cli.new.setup
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
describe Dotify::CLI, "#dotfile_list" do
|
25
|
-
let(:c) { cli.new }
|
26
|
-
it "should pull the correct set of files" do
|
27
|
-
list = c.dotfile_list
|
28
|
-
list.count.should == 0
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
describe Dotify::CLI, "#filename" do
|
33
|
-
it "should return only the filename given a path" do
|
34
|
-
c = cli.new
|
35
|
-
c.filename("/Users/johndoe/filename").should == "filename"
|
36
|
-
c.filename("/Users/johndoe/..").should == ".."
|
37
|
-
c.filename("/Users/johndoe/.vimrc").should == ".vimrc"
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
describe Dotify::CLI, "#template?" do
|
42
|
-
it "should return true if the file ends in tt or erb" do
|
43
|
-
c = cli.new
|
44
|
-
c.template?("title.tt").should be_true
|
45
|
-
c.template?("title.erb").should be_true
|
46
|
-
c.template?("title.rb").should_not be_true
|
47
|
-
c.template?("title.rb").should_not be_true
|
48
|
-
c.template?("#{dotify_path}/title.rb").should_not be_true
|
49
|
-
c.template?("#{dotify_path}/tt.rb").should_not be_true
|
50
|
-
c.template?("#{dotify_path}/.vimrc.erb").should be_true
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
7
|
+
# add unit tests at a future date
|
54
8
|
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'dotify/errors'
|
3
|
+
require 'dotify/config'
|
4
|
+
|
5
|
+
describe Dotify::Config do
|
6
|
+
let(:fixtures) { File.join(%x{pwd}.chomp, 'spec/fixtures') }
|
7
|
+
before do
|
8
|
+
Fake.tearup
|
9
|
+
Dotify::Config.stub(:user_home) { Fake.root_path }
|
10
|
+
#Dotify::Config.stub(:config_file) { File.join(fixtures, '.dotrc-default') }
|
11
|
+
#Dotify::Config.load_config!
|
12
|
+
end
|
13
|
+
after do
|
14
|
+
Fake.teardown
|
15
|
+
end
|
16
|
+
describe "setters" do
|
17
|
+
#it "should be able to set the current shell (not actually yet used)" do
|
18
|
+
# Dotify::Config.shell = 'zsh'
|
19
|
+
# Dotify::Config.shell.should == 'zsh'
|
20
|
+
# Dotify::Config.shell = 'bash'
|
21
|
+
# Dotify::Config.shell.should == 'bash'
|
22
|
+
#end
|
23
|
+
#it "should raise an error if the shell specified does not exist" do
|
24
|
+
# expect { Dotify::Config.shell = 'fake' }.to raise_error Dotify::NonValidShell
|
25
|
+
#end
|
26
|
+
#it "should be able to set the current profile name (not actually yet used)" do
|
27
|
+
# Dotify::Config.profile = 'james'
|
28
|
+
# Dotify::Config.profile.should == 'james'
|
29
|
+
#end
|
30
|
+
#it "should be able to show the dotify path" do
|
31
|
+
# Dotify::Config.path.should == File.join(Dotify::Config.home, '.dotify')
|
32
|
+
#end
|
33
|
+
it "should be able to show the dotify path" do
|
34
|
+
Dotify::Config.path.should == File.join(Dotify::Config.home, '.dotify')
|
35
|
+
end
|
36
|
+
it "should be able to show the dotify backup path" do
|
37
|
+
Dotify::Config.backup.should == File.join(Dotify::Config.path, '.backup')
|
38
|
+
end
|
39
|
+
end
|
40
|
+
describe "config files" do
|
41
|
+
#before do
|
42
|
+
# Dotify::Config.stub(:home) { Fake.root_path }
|
43
|
+
# Dotify::Config.stub(:config_file) { File.join(fixtures, '.dotrc-mattbridges') }
|
44
|
+
#end
|
45
|
+
#it "should not try to assign improper config values" do
|
46
|
+
# Dotify::Config.should_receive(:profile=)
|
47
|
+
# Dotify::Config.should_receive(:shell=)
|
48
|
+
# Dotify::Config.should_not_receive(:something_fake=)
|
49
|
+
# Dotify::Config.load_config!
|
50
|
+
#end
|
51
|
+
#it "should load the config and set the variables" do
|
52
|
+
# Dotify::Config.load_config!
|
53
|
+
# Dotify::Config.profile.should == 'mattdbridges'
|
54
|
+
# Dotify::Config.shell.should == 'zsh'
|
55
|
+
#end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'dotify/files'
|
3
|
+
require 'fileutils'
|
4
|
+
|
5
|
+
describe Dotify::Files do
|
6
|
+
let(:fixtures) { File.join(%x{pwd}.chomp, 'spec/fixtures') }
|
7
|
+
before do
|
8
|
+
Fake.tearup
|
9
|
+
#Dotify::Config.stub(:config_file) { File.join(fixtures, '.dotrc-default') }
|
10
|
+
Dotify::Config.stub(:home) { Fake.root_path }
|
11
|
+
Dotify::Config.load_config!
|
12
|
+
end
|
13
|
+
after do
|
14
|
+
Fake.teardown
|
15
|
+
end
|
16
|
+
it "should respond to the right methods" do
|
17
|
+
Dotify::Files.should respond_to :dots
|
18
|
+
Dotify::Files.should respond_to :installed
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should split a file_name correct" do
|
22
|
+
Dotify::Files.file_name("some/random/path/to/file.txt").should == 'file.txt'
|
23
|
+
Dotify::Files.file_name("another/path/no_extension").should == 'no_extension'
|
24
|
+
end
|
25
|
+
|
26
|
+
describe Dotify::Files, "#dotfile" do
|
27
|
+
it "should return the path to the file when it is linked in the root" do
|
28
|
+
Dotify::Files.dotfile(".vimrc").should == File.join(Dotify::Config.home, ".vimrc")
|
29
|
+
Dotify::Files.dotfile("/spec/home/.bashrc").should == File.join(Dotify::Config.home, ".bashrc")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe Dotify::Files, "#dots" do
|
34
|
+
before do
|
35
|
+
Dotify::Files.stub(:file_list) do
|
36
|
+
['/spec/test/.vimrc', '/spec/test/.bashrc', '/spec/test/.zshrc']
|
37
|
+
end
|
38
|
+
end
|
39
|
+
it "should return the list of dotfiles in the dotify path" do
|
40
|
+
files = Dotify::Files.dots.map { |f| Dotify::Files.file_name(f) }
|
41
|
+
files.should include '.vimrc'
|
42
|
+
files.should include '.bashrc'
|
43
|
+
files.should include '.zshrc'
|
44
|
+
files.should_not include '.' # current and upper directories
|
45
|
+
files.should_not include '..'
|
46
|
+
end
|
47
|
+
it "shoud yield the files if a block is given" do
|
48
|
+
files = Dotify::Files.dots.map { |d| [d, Dotify::Files.file_name(d)] }
|
49
|
+
expect { |b| Dotify::Files.dots(&b) }.to yield_successive_args(*files)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe Dotify::Files, "#installed" do
|
54
|
+
before do
|
55
|
+
fake_root, dotify = Fake.paths
|
56
|
+
FileUtils.touch File.join(fake_root, '.vimrc')
|
57
|
+
FileUtils.touch File.join(fake_root, '.bashrc')
|
58
|
+
end
|
59
|
+
it "should return the list of installed dotfiles in the root path" do
|
60
|
+
installed = Dotify::Files.installed.map { |i| Dotify::Files.file_name(i) }
|
61
|
+
installed.should include '.vimrc'
|
62
|
+
installed.should include '.bashrc'
|
63
|
+
installed.should_not include '.zshrc'
|
64
|
+
installed.should_not include '.dotify'
|
65
|
+
end
|
66
|
+
it "shoud yield the installed files if a block is given" do
|
67
|
+
installed = Dotify::Files.installed.map { |i| [i, Dotify::Files.file_name(i)] }
|
68
|
+
expect { |b| Dotify::Files.installed(&b) }.to yield_successive_args(*installed)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe Dotify::Files, "#template?" do
|
73
|
+
it "should return true if the string given is a .tt or .erb template" do
|
74
|
+
Dotify::Files.template?("testing.erb").should == true
|
75
|
+
Dotify::Files.template?("testing.tt").should == true
|
76
|
+
Dotify::Files.template?("/Users/fake/path/to/testing.tt").should == true
|
77
|
+
Dotify::Files.template?("/Users/another/fake/path/to/testing.erb").should == true
|
78
|
+
end
|
79
|
+
it "should return false if the string given is not a .tt or .erb template" do
|
80
|
+
Dotify::Files.template?(".tt.testing").should == false
|
81
|
+
Dotify::Files.template?("erbit.txt").should == false
|
82
|
+
Dotify::Files.template?(".erb.erbit.txt").should == false
|
83
|
+
Dotify::Files.template?("/Users/fake/path/to/testing.txt").should == false
|
84
|
+
Dotify::Files.template?("/Users/another/fake/path/to/testing.rb").should == false
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe Dotify::Files, "#link_dotfile" do
|
89
|
+
it "should receive a file and link it into the root path" do
|
90
|
+
first = File.join(Dotify::Files.send(:dotify_path), ".vimrc")
|
91
|
+
FileUtils.should_receive(:ln_s).with(Dotify::Files.file_name(first), Dotify::Config.home).once
|
92
|
+
Dotify::Files.link_dotfile first
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
describe Dotify::Files, "#unlink_dotfile" do
|
97
|
+
it "should receive a file and remove it from the root" do
|
98
|
+
first = "/spec/test/.file"
|
99
|
+
FileUtils.stub(:rm_rf).with(File.join(Dotify::Config.home, Dotify::Files.file_name(first))).once
|
100
|
+
Dotify::Files.unlink_dotfile first
|
101
|
+
FileUtils.unstub(:rm_rf)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -5,6 +5,9 @@
|
|
5
5
|
#
|
6
6
|
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
7
|
$:.unshift File.expand_path("../../lib", __FILE__)
|
8
|
+
require 'fileutils'
|
9
|
+
Dir["./spec/support/**/*.rb"].each { |f| require f }
|
10
|
+
|
8
11
|
RSpec.configure do |config|
|
9
12
|
config.treat_symbols_as_metadata_keys_with_true_values = true
|
10
13
|
config.run_all_when_everything_filtered = true
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
class Fake
|
4
|
+
|
5
|
+
def self.paths
|
6
|
+
path = File.dirname(File.dirname(__FILE__))
|
7
|
+
fake_root = File.join(path, 'fake-root')
|
8
|
+
dotify = File.join(fake_root, '.dotify')
|
9
|
+
[fake_root, dotify]
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.tearup
|
13
|
+
fake_root, dotify = paths
|
14
|
+
FileUtils.mkdir_p fake_root
|
15
|
+
reset
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.teardown
|
19
|
+
fake_root, dotify = paths
|
20
|
+
FileUtils.rm_rf fake_root
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.reset
|
24
|
+
fake_root, dotify = paths
|
25
|
+
FileUtils.mkdir_p dotify
|
26
|
+
FileUtils.touch File.join(dotify, '.vimrc')
|
27
|
+
FileUtils.touch File.join(dotify, '.bashrc')
|
28
|
+
FileUtils.touch File.join(dotify, '.zshrc')
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.root_path
|
32
|
+
fake_root, dotify = paths
|
33
|
+
fake_root
|
34
|
+
end
|
35
|
+
def self.dotify_path
|
36
|
+
fake_root, dotify = paths
|
37
|
+
dotify
|
38
|
+
end
|
39
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dotify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: '0.1'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-06-
|
12
|
+
date: 2012-06-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: thor
|
@@ -59,7 +59,7 @@ dependencies:
|
|
59
59
|
- - ! '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
|
-
description: A CLI Tool for managing your dotfiles
|
62
|
+
description: A CLI Tool for managing your dotfiles
|
63
63
|
email:
|
64
64
|
- mbridges.91@gmail.com
|
65
65
|
executables:
|
@@ -78,9 +78,17 @@ files:
|
|
78
78
|
- dotify.gemspec
|
79
79
|
- lib/dotify.rb
|
80
80
|
- lib/dotify/cli.rb
|
81
|
+
- lib/dotify/config.rb
|
82
|
+
- lib/dotify/errors.rb
|
83
|
+
- lib/dotify/files.rb
|
81
84
|
- lib/dotify/version.rb
|
82
85
|
- spec/dotify/cli_spec.rb
|
86
|
+
- spec/dotify/config_spec.rb
|
87
|
+
- spec/dotify/files_spec.rb
|
88
|
+
- spec/fixtures/.dotrc-default
|
89
|
+
- spec/fixtures/.dotrc-mattbridges
|
83
90
|
- spec/spec_helper.rb
|
91
|
+
- spec/support/fake.rb
|
84
92
|
homepage: https://github.com/mattdbridges/dotify
|
85
93
|
licenses: []
|
86
94
|
post_install_message:
|
@@ -104,7 +112,12 @@ rubyforge_project:
|
|
104
112
|
rubygems_version: 1.8.23
|
105
113
|
signing_key:
|
106
114
|
specification_version: 3
|
107
|
-
summary: A CLI Tool for managing your dotfiles
|
115
|
+
summary: A CLI Tool for managing your dotfiles
|
108
116
|
test_files:
|
109
117
|
- spec/dotify/cli_spec.rb
|
118
|
+
- spec/dotify/config_spec.rb
|
119
|
+
- spec/dotify/files_spec.rb
|
120
|
+
- spec/fixtures/.dotrc-default
|
121
|
+
- spec/fixtures/.dotrc-mattbridges
|
110
122
|
- spec/spec_helper.rb
|
123
|
+
- spec/support/fake.rb
|