dotify 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -32,10 +32,28 @@ To setup Dotify, you must first run `dotify setup` in your terminal.
32
32
  Do you want to add .gitconfig to Dotify? [Yn] y
33
33
  ...
34
34
 
35
- This will first create a `.dotify` directory in your home directory (yes, only one more dot directory, but this time it is a good thing). It will then ask which files you want to copy from your home directory into your `.dotify` directory.
35
+ This will first create a `.dotify` directory in your home directory (yes, only one more dot directory, but this time it is a good thing). It will then ask which files you want to copy from your home directory into your `.dotify` directory.
36
36
 
37
37
  **This will *not* link up the dotfiles. This command simply copies the files over for you without having to go searching for them manually.**
38
38
 
39
+ ### Add single files
40
+
41
+ After you have setup Dotify, you can add files one by one if you did not add them during setup
42
+
43
+ $ dotify add .vimrc
44
+ create /Users/mattbridges/.vimrc
45
+
46
+ ### Remove single files
47
+
48
+ If you don't want a particular dotfile anymore? You can just remove it.
49
+
50
+ ***This actually removes the file from the home directory. Do this at your own risk***.
51
+
52
+ $ dotify remove .vimrc
53
+ remove /Users/mattbridges/.vimrc
54
+
55
+ If you do this and decide to change your mind, the file is still located in the `~/.dotify` directory. You can re-link it by running `dotify link` again.
56
+
39
57
  ### Link up your files
40
58
 
41
59
  This is the heart of the Dotify tool. This command will link the files within the `~/.dotify` directory into your home directory.
@@ -64,22 +82,35 @@ Don't want any of the dotfiles anymore? Well, I'm not one to question. Go ahead
64
82
 
65
83
  Should you run this horrid task accidentally, you can simply run `dotify link` again if you want to restore your previous settings.
66
84
 
85
+ ## Confused?
86
+
87
+ Dotify can manages dotfiles from two different directions:
88
+
89
+ 1. `add` and `remove` both look in the user's home directory for dotfiles to manage
90
+ 2. `link` and `unlink` both look in the Dotify directory for dotfiles to manage.
91
+
92
+ In other words, when the user has dotfiles in the home directory that he/she wants Dotify to manage, they would use `dotify add [FILENAME]` (or even `setup`) to instruct Dotify to manage those files.
93
+
94
+ On the other hand, if he/she has files that they have instructed Dotify to manage but have removed them from the home directory, they would use `link` and `unlink` to re-link them into the home directory.
95
+
67
96
  ## Not sure what to do?
68
97
 
69
98
  This tool is powered by the amazing library, [Thor](http://whatisthor.com/). You can use the `help` task like so:
70
99
 
71
100
  $ dotify help
72
101
  Tasks:
73
- dotify help [TASK] # Describe available tasks or one specific task
74
- dotify link # Link up all of your dotfiles
75
- dotify setup # Setup your system for Dotify to manage your dotfiles
76
- dotify unlink # Unlink all of your dotfiles
102
+ dotify add [FILENAME] # Add a single dotfile to the Dotify directory
103
+ dotify help [TASK] # Describe available tasks or one specific task
104
+ dotify link # Link up all of your dotfiles
105
+ dotify remove [FILENAME] # Remove a single dotfile from Dotify
106
+ dotify setup # Setup your system for Dotify to manage your dotfiles
107
+ dotify unlink # Unlink all of your dotfiles
77
108
 
78
109
  And if you want a little clarity on one of the command you can run `dotify help [TASK]` to find out what other options you have in the other tasks.
79
110
 
80
111
  ## Contributing
81
112
 
82
- This tool is developed with much influence from *37singals*' fantastic idea of **Do Less**. This is meant to be a *simple* tool.
113
+ This tool is developed with much influence from *37singals*' fantastic idea of **Do Less**. This is meant to be a *simple* tool.
83
114
 
84
115
  Contributions are welcome and encouraged. The contrubution process is the typical Github one.
85
116
 
data/lib/dotify/cli.rb CHANGED
@@ -11,34 +11,74 @@ module Dotify
11
11
  include Thor::Actions
12
12
  default_task :help
13
13
 
14
- map "-l" => "link"
15
- map "-u" => "unlink"
16
- map "-b" => "backup"
17
- map "-r" => "restore"
14
+ map "-l" => :link
15
+ map "-u" => :unlink
16
+ map "-s" => :setup
17
+ map "-a" => :add
18
+ map "-r" => :remove
18
19
 
19
20
  def self.source_root
20
21
  Config.home
21
22
  end
22
23
 
23
24
  desc :setup, "Setup your system for Dotify to manage your dotfiles"
25
+ method_option :link, :default => false, :type => :boolean, :aliases => '-l', :desc => "Link dotfiles when setup is complete"
24
26
  def setup
25
27
  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
28
+ Files.unlinked do |path, file|
29
+ add(file) unless Config.dirname == file
30
+ end
31
+ say "Dotify has been successfully setup.", :blue
32
+ if options[:link]
33
+ say "Linking up the new dotfiles...", :blue
34
+ invoke :link, nil, { :all => true } if options[:link]
35
+ end
36
+ end
37
+
38
+ desc "add [FILENAME]", "Add a single dotfile to the Dotify directory"
39
+ method_option :force, :default => false, :type => :boolean, :aliases => '-f', :desc => "Add file without confirmation"
40
+ def add(file)
41
+ file = Files.file_name(file)
42
+ dotfile = Files.dotfile(file)
43
+ dotify_file = Files.dotify(file)
44
+ case
45
+ when !File.exist?(dotfile)
46
+ say "'~/#{file}' does not exist", :blue
47
+ when File.identical?(dotfile, dotify_file)
48
+ say "'~/#{file}' is already identical to '~/.dotify/#{file}'", :blue
49
+ else
50
+ if options[:force] == true || yes?("Do you want to add #{file} to Dotify? [Yn]", :yellow)
51
+ if File.directory?(dotfile)
52
+ FileUtils.rm_rf dotify_file
53
+ FileUtils.cp_r dotfile, dotify_file
54
+ say_status :create, dotify_file
55
+ else
56
+ copy_file dotfile, dotify_file
38
57
  end
39
58
  end
40
59
  end
41
- say "Dotify has been successfully setup.", :blue
60
+ end
61
+
62
+ desc "remove [FILENAME]", "Remove a single dotfile from Dotify"
63
+ long_desc <<-STRING
64
+ `dotify remove [FILENAME]` removes the dotfiles from the Dotify directory
65
+ and moves it back into the home directory. If you decide you want Dotify
66
+ to manage that file again, you can simply run `dotify add [FILENAME]` to
67
+ add it back again.
68
+ STRING
69
+ method_option :force, :default => false, :type => :boolean, :aliases => '-f', :desc => "Remove file without confirmation"
70
+ method_option :quiet, :default => false, :type => :boolean, :aliases => '-q', :desc => "Don't output anything"
71
+ def remove(file)
72
+ if !File.exists?(Files.dotify(file))
73
+ say "Dotify is not currently managing ~/#{file}.", :blue unless options.quiet?
74
+ return
75
+ end
76
+ if options[:force] == true || yes?("Are you sure you want to remove #{file} from Dotify? [Yn]", :yellow)
77
+ remove_file Files.dotfile(file), :verbose => false
78
+ copy_file Files.dotify(file), Files.dotfile(file), :verbose => false
79
+ remove_file Files.dotify(file), :verbose => false
80
+ say_status :removed, Files.dotify(file) unless options.quiet?
81
+ end
42
82
  end
43
83
 
44
84
  desc :link, "Link up all of your dotfiles"
@@ -54,21 +94,26 @@ module Dotify
54
94
  end
55
95
  count += 1
56
96
  else
57
- if yes?("Do you want to link ~/#{dot}? [Yn]", :green)
97
+ if yes?("Do you want to link ~/#{dot}? [Yn]", :yellow)
58
98
  create_link Files.dotfile(file), file
59
99
  count += 1
60
100
  end
61
101
  end
62
102
  end
63
- say "No files were linked.", :yellow if count == 0
103
+ say "No files were linked.", :blue if count == 0
64
104
  end
65
105
 
66
106
  desc :unlink, "Unlink all of your dotfiles"
107
+ long_desc <<-STRING
108
+ `dotify unlink` removes the dotfiles from the home directory and preserves the
109
+ files in the Dotify directory. This allows you to simply run `dotify link` again
110
+ should you decide you want to relink anything to the Dotify files.
111
+ STRING
67
112
  method_option :all, :default => false, :type => :boolean, :aliases => '-a', :desc => 'Remove all installed dotfiles without confirmation'
68
113
  def unlink
69
114
  count = 0
70
115
  Files.installed do |file, dot|
71
- if options[:all] || yes?("Are you sure you want to remove ~/#{dot}? [Yn]", :blue)
116
+ if options[:all] || yes?("Are you sure you want to remove ~/#{dot}? [Yn]", :yellow)
72
117
  remove_file Files.dotfile(file)
73
118
  count += 1
74
119
  end
data/lib/dotify/files.rb CHANGED
@@ -11,7 +11,7 @@ module Dotify
11
11
  include Thor::Actions
12
12
 
13
13
  def dots
14
- @dots ||= file_list(File.join(dotify_path, "/.*"))
14
+ @dots ||= file_list(File.join(Config.path, "/.*"))
15
15
  return @dots unless block_given?
16
16
  @dots.each {|d| yield(d, file_name(d)) }
17
17
  end
@@ -25,6 +25,14 @@ module Dotify
25
25
  installed.each {|i| yield(i, file_name(i)) }
26
26
  end
27
27
 
28
+ def unlinked
29
+ dots = self.dots.map { |f| file_name(f) }
30
+ installed = self.installed.map {|f| file_name(f)}
31
+ unlinked = (dots - installed).map{|f| dotfile(f) }
32
+ return unlinked unless block_given?
33
+ unlinked.each {|u| yield(u, file_name(u)) }
34
+ end
35
+
28
36
  def file_name(file)
29
37
  file.split("/").last
30
38
  end
@@ -37,6 +45,10 @@ module Dotify
37
45
  File.join(Config.home, file_name(file))
38
46
  end
39
47
 
48
+ def dotify(file)
49
+ File.join(Config.path, file_name(file))
50
+ end
51
+
40
52
  def link_dotfile(file)
41
53
  FileUtils.ln_s(file_name(file), Config.home) == 0 ? true : false
42
54
  end
@@ -55,10 +67,6 @@ module Dotify
55
67
  files.select { |f| !['.', '..'].include?(file_name(f)) }
56
68
  end
57
69
 
58
- def dotify_path
59
- Config.path
60
- end
61
-
62
70
  end
63
71
  end
64
72
  end
@@ -1,3 +1,3 @@
1
1
  module Dotify
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -1,4 +1,5 @@
1
1
  require 'spec_helper'
2
+ require 'dotify/config'
2
3
  require 'dotify/files'
3
4
  require 'fileutils'
4
5
 
@@ -13,6 +14,7 @@ describe Dotify::Files do
13
14
  after do
14
15
  Fake.teardown
15
16
  end
17
+
16
18
  it "should respond to the right methods" do
17
19
  Dotify::Files.should respond_to :dots
18
20
  Dotify::Files.should respond_to :installed
@@ -30,6 +32,13 @@ describe Dotify::Files do
30
32
  end
31
33
  end
32
34
 
35
+ describe Dotify::Files, "#dotify" do
36
+ it "should return the path to the file when it is linked in the root" do
37
+ Dotify::Files.dotify(".vimrc").should == File.join(Dotify::Config.path, ".vimrc")
38
+ Dotify::Files.dotify("/spec/home/.bashrc").should == File.join(Dotify::Config.path, ".bashrc")
39
+ end
40
+ end
41
+
33
42
  describe Dotify::Files, "#dots" do
34
43
  before do
35
44
  Dotify::Files.stub(:file_list) do
@@ -50,6 +59,26 @@ describe Dotify::Files do
50
59
  end
51
60
  end
52
61
 
62
+ describe Dotify::Files, "#unlinked" do
63
+ before do
64
+ Dotify::Files.stub(:dots) do
65
+ ['/spec/test/.vimrc', '/spec/test/.bashrc', '/spec/test/.zshrc']
66
+ end
67
+ Dotify::Files.stub(:installed) do
68
+ ['/root/test/.bashrc', '/root/test/.zshrc']
69
+ end
70
+ end
71
+ it "should return the list of unlinked dotfiles in the root path" do
72
+ unlinked = Dotify::Files.unlinked.map { |u| Dotify::Files.file_name(u) }
73
+ unlinked.should include '.vimrc'
74
+ unlinked.should_not include '.bashrc'
75
+ end
76
+ it "shoud yield the unlinked files if a block is given" do
77
+ unlinked = Dotify::Files.unlinked.map { |u| [u, Dotify::Files.file_name(u)] }
78
+ expect { |b| Dotify::Files.unlinked(&b) }.to yield_successive_args(*unlinked)
79
+ end
80
+ end
81
+
53
82
  describe Dotify::Files, "#installed" do
54
83
  before do
55
84
  fake_root, dotify = Fake.paths
@@ -87,7 +116,7 @@ describe Dotify::Files do
87
116
 
88
117
  describe Dotify::Files, "#link_dotfile" do
89
118
  it "should receive a file and link it into the root path" do
90
- first = File.join(Dotify::Files.send(:dotify_path), ".vimrc")
119
+ first = File.join(Dotify::Config.path, ".vimrc")
91
120
  FileUtils.should_receive(:ln_s).with(Dotify::Files.file_name(first), Dotify::Config.home).once
92
121
  Dotify::Files.link_dotfile first
93
122
  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.1.1
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: