dotify 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,9 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'rspec', :version => 2 do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+ end
9
+
data/README.md CHANGED
@@ -31,13 +31,15 @@ To install Dotify, you must first run `dotify install` in your terminal.
31
31
  $ dotify install
32
32
  create /Users/computer-user/.dotify
33
33
  create /Users/computer-user/.dotrc
34
- Do you want to add .bash_history to Dotify? [Yn] n
35
- Do you want to add .bashrc to Dotify? [Yn] y
36
- create /Users/mattbridges/.dotify/.bashrc
34
+ Editing config file...
35
+ Do you want to link .bashrc to the home directory? [Yn] n
36
+ linked /Users/computer-user/.bashrc
37
+ Do you want to link .dotrc to the home directory? [Yn] n
38
+ linked /Users/computer-user/.dotrc
37
39
  Do you want to add .railsrc to Dotify? [Yn] n
38
- create /Users/mattbridges/.dotify/.railsrc
40
+ linked /Users/computer-user/.railsrc
39
41
  Do you want to add .zshrc to Dotify? [Yn] n
40
- create /Users/mattbridges/.dotify/.zshrc
42
+ linked /Users/computer-user/.zshrc
41
43
  ...
42
44
 
43
45
  This will first create a `.dotify` directory in your home directory as well as a `.dotrc` file for Dotify configuration (yes, it is more dotfiles, but this is a good thing!).
@@ -46,61 +48,32 @@ During the installation process, a Vim instance will open with a sample `.dotrc`
46
48
 
47
49
  Alternatively, you could run `dotify setup` to setup Dotify's configuration, followed by `dotify install` to add the initial files into Dotify.
48
50
 
49
- ### Add single files
50
-
51
- After you have setup Dotify, you can add files one by one if you did not add them during setup
52
-
53
- $ dotify add .vimrc
54
- create /Users/mattbridges/.vimrc
55
-
56
- ### Remove single files
57
-
58
- If you don't want a particular dotfile anymore? You can just remove it.
59
-
60
- ***This actually removes the file from the home directory. Do this at your own risk***.
61
-
62
- $ dotify remove .vimrc
63
- remove /Users/mattbridges/.vimrc
64
-
65
- 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.
66
-
67
- ### Link up your files
51
+ ### Link single files
68
52
 
69
- This is the heart of the Dotify tool. This command will link the files within the `~/.dotify` directory into your home directory.
53
+ After you have setup Dotify, you can add files one by one if you did not add them during setup.
70
54
 
71
- $ dotify link
72
- Do you want to link .bash_profile to the home directory? [Yn] Y
73
- linked /Users/mattbridges/.bash_profile
74
- Do you want to link .dotrc to the home directory? [Yn] n
75
- Do you want to link .gitconfig to the home directory? [Yn] Y
76
- linked /Users/mattbridges/.gitconfig
77
- ...
78
-
79
- You can also link files one-by-one by passing the filename to the `link` task.
55
+ $ dotify link .vimrc
56
+ linked /Users/computer-user/.vimrc
80
57
 
81
- $ dotify link .bashrc
82
- Do you want to link ~/.bashrc? [Yn] Y
83
- linked /Users/mattbridges/.bashrc
58
+ ### Unlink the chains...
84
59
 
85
- ### Unlink everything
86
-
87
- Don't want any of the dotfiles anymore? Well, I'm not one to question. Go ahead and wipe them out.
60
+ Don't want any of the dotfiles anymore? Or want to drop one? Well, I'm not one to question. Go ahead and move them back into the home directory.
88
61
 
89
62
  $ dotify unlink
90
- Do you want to unlink .bashrc from the home directory? [Yn] y
91
- unlinked /Users/computer-user/.bashrc
92
- Do you want to unlink .dotrc from the home directory? [Yn] n
93
- Do you want to unlink .gemrc from the home directory? [Yn] y
94
- unlinked /Users/computer-user/.gemrc
63
+ Do you want to unlink .bash_profile from the home directory? [Yn] Y
64
+ unlinked /Users/computer-user/.bash_profile
65
+ Do you want to unlink .dotrc from the home directory? [Yn] Y
66
+ unlinked /Users/computer-user/.dotrc
67
+ Do you want to unlink .gemrc from the home directory? [Yn]
95
68
  ...
96
69
 
97
- Should you run this horrid task accidentally, you can simply run `dotify link` again if you want to restore your previous settings.
70
+ Should you run this task and decide to change your mind, you can simply run `dotify link` or `dotify link [FILE]` again if you want to restore your changes.
98
71
 
99
72
  By default, `unlink` loops through all of the Dotify files. You can also pass a filename to `unlink` to unlink a single file.
100
73
 
101
74
  $ dotify unlink .bashrc
102
75
  Are you sure you want to remove ~/.bashrc? [Yn] Y
103
- remove /Users/mattbridges/.bashrc
76
+ unlinked /Users/computer-user/.bashrc
104
77
 
105
78
  ## Versioning
106
79
 
@@ -149,36 +122,21 @@ The same can be done for the home directory when running `dotify setup`. There a
149
122
 
150
123
  More configuration options will likely be added in future versions, so be sure to check up here for your options.
151
124
 
152
- ## Clarifying the add/remove/link/unlink tasks
153
-
154
- Here is a little clarification on the `add`/`remove`/`link`/`unlink` tasks.
155
-
156
- * `dotify add` adds one or more dotfiles in the users' home directory into Dotify.
157
- * `dotify remove` removes one or more linked dotfiles from Dotify and returns them to the home directory.
158
- * `dotify link` links one or more files added to Dotify into the home directory.
159
- * `dotify unlink` simply removes one or more home directory files that are linked into Dotify.
160
-
161
- For instructions on how to use these methods, use `dotify help [TASK]` for further explanation.
162
-
163
125
  ## Not sure what to do?
164
126
 
165
127
  This tool is powered by the amazing library, [Thor](http://whatisthor.com/). You can use the `help` task like so:
166
128
 
167
129
  $ dotify help
168
130
  Tasks:
169
- dotify add {{FILENAME}} # Add a one or more dotfiles to Dotify. (FILENAME is optional)
170
131
  dotify edit [FILE] # Edit a dotify file
171
132
  dotify help [TASK] # Describe available tasks or one specific task
172
133
  dotify install # Install files from your home directory into Dotify
173
- dotify link {{FILENAME}} # Link up one or all of your dotfiles (FILENAME is optional)
174
- dotify remove {{FILENAME}} # Remove a single dotfile from Dotify (FILENAME is optional)
175
- dotify save # Commit Dotify files and push to Github
134
+ dotify link [[FILENAME]] # Link up one or all of your dotfiles (FILENAME is optional)
135
+ dotify save # Save Dotify files and push to Github.
176
136
  dotify setup # Setup your system for Dotify to manage your dotfiles
177
- dotify unlink {{FILENAME}} # Unlink one or all of your dotfiles (FILENAME is optional)
137
+ dotify unlink [[FILENAME]] # Unlink one or all of your dotfiles (FILENAME is optional)
178
138
  dotify version # Check your Dotify version
179
139
 
180
- 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.
181
-
182
140
  ## Contributing
183
141
 
184
142
  This tool is developed with much influence from *37singals*' fantastic idea of **Do Less**. This is meant to be a *simple* tool.
@@ -19,6 +19,7 @@ Gem::Specification.new do |gem|
19
19
  gem.add_dependency "multi_json"
20
20
  gem.add_dependency "json"
21
21
  gem.add_dependency "git"
22
+ gem.add_development_dependency "guard-rspec"
22
23
  gem.add_development_dependency "rspec"
23
24
  gem.add_development_dependency "webmock"
24
25
  gem.add_development_dependency "vcr"
@@ -1,8 +1,16 @@
1
- require 'dotify/config'
2
1
  require 'dotify/version'
3
- require "fileutils"
2
+ require 'dotify/errors'
3
+
4
+ require 'fileutils'
4
5
 
5
6
  module Dotify
7
+
8
+ autoload :Config, 'dotify/config'
9
+ autoload :Files, 'dotify/files'
10
+ autoload :List, 'dotify/list'
11
+ autoload :Unit, 'dotify/unit'
12
+ autoload :CLI, 'dotify/cli'
13
+
6
14
  def self.installed?
7
15
  Config.installed?
8
16
  end
@@ -1,14 +1,10 @@
1
1
  require 'rubygems'
2
2
  require 'thor'
3
3
  require 'fileutils'
4
- require 'json'
5
4
  require 'git'
6
5
  require 'net/http'
7
6
 
8
7
  require 'dotify'
9
- require 'dotify/config'
10
- require 'dotify/files'
11
- require 'dotify/file_list'
12
8
  require 'dotify/version_checker'
13
9
 
14
10
  Dotify::Config.load_config!
@@ -35,9 +31,9 @@ module Dotify
35
31
 
36
32
  desc :save, "Save Dotify files and push to Github."
37
33
  method_option :message, :aliases => '-m', :type => :string, :required => false, :desc => "Git commit message to send to Github"
38
- method_option :force, :aliases => '-f', :type => :boolean, :desc => "Do not ask for confirmation when adding files to the staging area."
39
- method_option :debug, :aliases => '-d', :type => :boolean, :desc => "Show error messages if there is a Git failure."
40
- method_option :verbose, :aliases => '-v', :type => :boolean, :default => true, :desc => "Show error messages if there is a Git failure."
34
+ method_option :force, :aliases => '-f', :type => :boolean, :default => false, :desc => "Do not ask for confirmation when adding files to the staging area."
35
+ method_option :debug, :aliases => '-d', :type => :boolean, :default => false, :desc => "Show error messages if there is a Git failure."
36
+ method_option :verbose, :aliases => '-v', :type => :boolean, :default => true, :desc => "Display file creation and status updates."
41
37
  method_option :push, :aliases => '-p', :type => :boolean, :default => false, :desc => "Force the push to the remote repository."
42
38
  def save
43
39
  if File.exists? Files.dotify('.git') # if the Dotify directory has been made a git repo
@@ -64,7 +60,7 @@ module Dotify
64
60
  repo.push
65
61
  rescue Exception => e
66
62
  say "There was a problem pushing to your remote repo.", :red
67
- say("Grit Error: #{e.message}", :red) if options[:debug]
63
+ say("Git Error: #{e.message}", :red) if options[:debug]
68
64
  return
69
65
  end
70
66
  say "Successfully pushed!", :blue
@@ -76,25 +72,28 @@ module Dotify
76
72
 
77
73
  desc 'edit [FILE]', "Edit a dotify file"
78
74
  method_option :save, :aliases => '-s', :default => false, :type => :boolean, :require => true, :desc => "Save Dotify files and push to Github"
79
- def edit(filename)
80
- if Files.linked.include? Files.dotify(filename)
81
- exec "#{Config.editor} #{Files.dotify(filename)}"
75
+ def edit(file)
76
+ file = Unit.new(file)
77
+ if file.linked?
78
+ exec "#{Config.editor} #{file.dotify}"
82
79
  save if options[:save] == true
83
80
  else
84
- say "'#{Files.filename(filename)}' has not been linked by Dotify. Please run `dotify link #{Files.filename(filename)}` to edit this file.", :blue
81
+ say "'#{file}' has not been linked by Dotify. Please run `dotify link #{file}` to edit this file.", :blue
85
82
  end
86
83
  end
87
84
 
88
85
  desc :version, "Check your Dotify version"
89
86
  method_option :verbose, :aliases => '-v', :default => false, :type => :boolean, :desc => "Output any errors that occur during the Version check."
87
+ method_option :check, :aliases => '-c', :default => false, :type => :boolean, :desc => "Check Rubygems.org to see if your installed version of Dotify is out of date."
90
88
  def version
89
+ return say "Dotify Version: v#{Dotify.version}", :blue unless options[:check]
91
90
  if VersionChecker.out_of_date?
92
91
  say "Your version of Dotify is out of date.", :yellow
93
92
  say " Your Version: #{Dotify.version}", :blue
94
93
  say " Latest Version: #{VersionChecker.version}", :blue
95
94
  say "I recommend that you uninstall Dotify completely before updating", :yellow
96
95
  else
97
- say "Your version of Dotify is up to date: #{Dotify::VERSION}", :blue
96
+ say "Your version of Dotify is up to date: #{Dotify.version}", :blue
98
97
  end
99
98
  rescue Exception => e
100
99
  say "There was an error checking your Dotify version. Please try again.", :red
@@ -107,7 +106,7 @@ module Dotify
107
106
  method_options :verbose => true
108
107
  def setup
109
108
  # Warn if Dotify is already setup
110
- if !Dotify.installed?
109
+ if Dotify.installed?
111
110
  say "Dotify is already setup", :blue
112
111
  end
113
112
 
@@ -122,7 +121,7 @@ module Dotify
122
121
  end
123
122
 
124
123
  say "Editing config file...", :blue
125
- sleep 1 # Give a little time for reading the message
124
+ sleep 0.5 # Give a little time for reading the message
126
125
  invoke :edit, [Config.file]
127
126
  say "Config file updated.", :blue
128
127
 
@@ -133,145 +132,63 @@ module Dotify
133
132
  desc :install, "Install files from your home directory into Dotify"
134
133
  def install
135
134
  invoke :setup unless Dotify.installed?
136
- invoke :add
135
+ invoke :link
137
136
  end
138
137
 
139
- desc "add {{FILENAME}}", "Add a one or more dotfiles to Dotify. (FILENAME is optional)"
140
- method_option :force, :type => :boolean, :default => false, :aliases => '-f', :desc => "Remove Dotify file(s) without confirmation"
141
- def add(file=nil)
142
- not_setup_warning unless Dotify.installed?
143
- if file.nil?
144
- Files.uninstalled { |path, file| add_dotify_file(file, options) }
145
- else
146
- add_dotify_file(file, options.merge(:single => true))
147
- end
148
- end
149
-
150
- desc "remove {{FILENAME}}", "Remove a single dotfile from Dotify (FILENAME is optional)"
138
+ desc 'link [[FILENAME]]', "Link up one or all of your dotfiles (FILENAME is optional)"
151
139
  long_desc <<-DESC
152
- This removes the dotfiles from the Dotify directory and move \
153
- it back into the home directory. If you decide you want Dotify \
154
- to manage that file again, you can simply run `dotify add [FILENAME]` \
155
- to add it back again.
140
+ This task takes a file from the home directory, \
141
+ moves it into Dotify, and symlinks the file in the \
142
+ home directory to the corresponding file in Dotify.
156
143
  DESC
157
- method_option :force, :type => :boolean, :default => false, :aliases => '-f', :desc => "Remove Dotify file(s) without confirmation"
158
- def remove(file=nil)
159
- not_setup_warning unless Dotify.installed?
160
- if file.nil?
161
- Files.linked { |path, file| remove_dotify_file(file, options) }
162
- else
163
- remove_dotify_file(file, options)
164
- end
165
- end
166
-
167
- desc 'link {{FILENAME}}', "Link up one or all of your dotfiles (FILENAME is optional)"
168
- method_option :force, :default => false, :type => :boolean, :aliases => '-f', :desc => "Link dotfiles without confirmation"
169
- def link(file=nil)
170
- not_setup_warning unless Dotify.installed?
171
- if file.nil?
172
- Files.unlinked do |path, file|
173
- link_file(file, options)
174
- end
175
- else
176
- link_file(file, options)
177
- end
144
+ method_option :force, :default => false, :type => :boolean, :aliases => '-f', :desc => "Link dotfiles without confirmation"
145
+ method_option :relink, :default => false, :type => :boolean, :aliases => '-r', :desc => "Relink files already in the"
146
+ def link(file = nil)
147
+ return not_setup_warning unless Dotify.installed?
148
+ # Link a single file
149
+ return link_file Unit.new(file), options unless file.nil?
150
+ # Relink the files
151
+ return Files.linked { |file| link_file(file, options) } if options[:relink]
152
+ # Link the files
153
+ Files.unlinked { |file| link_file(file, options) }
178
154
  end
179
155
 
180
- desc 'unlink {{FILENAME}}', "Unlink one or all of your dotfiles (FILENAME is optional)"
156
+ desc 'unlink [[FILENAME]]', "Unlink one or all of your dotfiles (FILENAME is optional)"
181
157
  long_desc <<-DESC
182
- This removes the dotfiles from the home directory and preserves the \
183
- files in the Dotify directory. This allows you to simply run `dotify link` again \
184
- should you decide you want to relink anything to the Dotify files.
158
+ This task unlinks the dotfile from Dotify and \
159
+ moves it back into the home directory. This will \
160
+ only be run if the file is symlinked to the corresponsing \
161
+ file in Dotify.
185
162
  DESC
186
163
  method_option :force, :default => false, :type => :boolean, :aliases => '-f', :desc => 'Remove all installed dotfiles without confirmation'
187
164
  def unlink(file = nil)
188
- not_setup_warning unless Dotify.installed?
189
- if file.nil?
190
- Files.linked do |path, file|
191
- unlink_file(file, options)
192
- end
193
- else
194
- unlink_file(file, options)
195
- end
165
+ return not_setup_warning unless Dotify.installed?
166
+ # Unlink a single file
167
+ return unlink_file Unit.new(file), options unless file.nil?
168
+ # Unlink the files
169
+ Files.linked { |file| unlink_file(file, options) }
196
170
  end
197
171
 
198
172
  no_tasks do
199
173
 
200
174
  def not_setup_warning
201
- say('Dotify has not been setup yet! You need to run \'dotify setup\' first.', :yellow)
175
+ say "Dotify has not been setup yet! You need to run 'dotify setup' first.", :yellow
202
176
  end
203
177
 
204
178
  def unlink_file(file, options = {})
205
- file = Files.filename(file)
206
- dot = Files.dotfile(file)
207
- dotify = Files.dotify(file)
208
- if File.exists?(dot) && File.exists?(dotify)
209
- if options[:force] == true || yes?("Do you want to unlink #{file} from the home directory? [Yn]", :blue)
210
- FileUtils.rm_rf dot
211
- say_status :unlinked, dot
212
- end
213
- else
214
- say "'#{file}' does not exist in Dotify.", :blue
179
+ say "'#{file}' does not exist in Dotify.", :blue unless file.linked?
180
+ if options[:force] == true || yes?("Do you want to unlink #{file} from the home directory? [Yn]", :blue)
181
+ file.unlink
182
+ say_status :unlinked, file.dotfile
215
183
  end
216
184
  end
217
185
 
218
186
  def link_file(file, options = {})
219
- file = Files.filename(file)
220
- home = Files.dotfile(file)
221
- path = Files.dotify(file)
222
- status = case
223
- when !File.exists?(home) then :linked
224
- when File.exists?(home) then :replaced; end
225
- if File.exists?(path)
226
- if options[:force] == true || yes?("Do you want to link #{file} to the home directory? [Yn]", :blue)
227
- FileUtils.rm_rf(home, :verbose => false)
228
- FileUtils.ln_s(path, home, :verbose => false)
229
- say_status status, home
230
- end
231
- else
232
- say "'#{file}' does not exist in the home directory.", :blue
233
- end
234
- end
235
-
236
- def remove_dotify_file(file, options = {})
237
- file = Files.filename(file)
238
- home = Files.dotfile(file)
239
- path = Files.dotify(file)
240
- if File.exist?(home) && File.exist?(path)
241
- if options[:force] == true || yes?("Do you want to remove #{file} from Dotify? [Yn]", :blue)
242
- FileUtils.rm_rf(home, :verbose => false)
243
- if File.directory? path
244
- FileUtils.cp_r(path, home, :verbose => false)
245
- else
246
- FileUtils.cp(path, home, :verbose => false)
247
- end
248
- FileUtils.rm_rf(path, :verbose => false)
249
- say_status :removed, path
250
- end
251
- elsif File.exist?(home) && !File.exist?(path)
252
- say "The file '#{file}' is not managed by Dotify. Cannot remove.", :blue
253
- else
254
- say "The file '~/#{file}' does not exist", :blue
255
- end
256
- end
257
-
258
- def add_dotify_file(file, options = {})
259
- file = Files.filename(file)
260
- home = Files.dotfile(file)
261
- path = Files.dotify(file)
262
- if File.exist?(home)
263
- if options[:force] == true || yes?("Do you want to add #{file} to Dotify? [Yn]", :blue)
264
- if File.directory? home
265
- FileUtils.cp_r(home, path, :verbose => false)
266
- else
267
- FileUtils.cp(home, path, :verbose => false)
268
- say_status :adding, path
269
- end
270
- end
271
- else
272
- if options[:single] == true
273
- say "The file '#{file}' doesn't exist or Dotify already manages it.", :blue
274
- end
187
+ return say_status :linked, file.dotfile if file.linked?
188
+ return say "'#{file}' does not exist in the home directory.", :blue unless file.in_home_dir?
189
+ if options[:force] == true || yes?("Do you want to link #{file} to the home directory? [Yn]", :blue)
190
+ file.link
191
+ say_status :linked, file.dotfile
275
192
  end
276
193
  end
277
194
 
@@ -9,7 +9,7 @@ module Dotify
9
9
  CONFIG_FILE = '.dotrc'
10
10
  EDITOR = 'vim'
11
11
  DEFAULT_IGNORE = {
12
- :dotify => %w[.git .gitmodule],
12
+ :dotify => %w[.DS_Store .git .gitmodule],
13
13
  :dotfiles => %w[.DS_Store .Trash .dropbox .dotify]
14
14
  }
15
15
 
@@ -19,14 +19,18 @@ module Dotify
19
19
  @dirname ||= DIRNAME
20
20
  end
21
21
 
22
- def installed?
23
- File.directory?(File.join(home, dirname))
22
+ def home
23
+ Thor::Util.user_home
24
24
  end
25
25
 
26
26
  def path
27
27
  File.join(home, dirname)
28
28
  end
29
29
 
30
+ def installed?
31
+ File.exists?(path) && File.directory?(path)
32
+ end
33
+
30
34
  def editor
31
35
  config.fetch(:editor, 'vim')
32
36
  end
@@ -44,10 +48,6 @@ module Dotify
44
48
  @config || load_config!
45
49
  end
46
50
 
47
- def home
48
- Thor::Util.user_home
49
- end
50
-
51
51
  def file
52
52
  File.join(home, CONFIG_FILE)
53
53
  end