dotify 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -24,49 +24,13 @@ It is highly recommended that you just install this gem manually since it is onl
24
24
 
25
25
  As dotify is a CLI tool, everything is done in the command line. Here are the current available methods for managing dotfiles.
26
26
 
27
- ### Preparing your system for Dotify
27
+ ### Setting up and installing Dotify
28
28
 
29
- To setup Dotify, you must first run `dotify setup` in your terminal.
29
+ To install Dotify, you must first run `dotify install` in your terminal.
30
30
 
31
- $ dotify setup
31
+ $ dotify install
32
32
  create /Users/computer-user/.dotify
33
33
  create /Users/computer-user/.dotrc
34
-
35
- 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!).
36
-
37
- In order to install files from the home directory into Dotify, you must run the `install` task.
38
-
39
- ### The .dotrc file
40
-
41
- The `.dotrc` file in your home directory serves as the configuration file for Dotify.
42
-
43
- #### Ignoring files
44
-
45
- When you are linking files in your Dotify directory, some files you do not want ever want to link (`.git`, `.gitmodules`, `.gitignore`, .etc) because they are used specifically for that directory (such as git versioning). You can configure Dotify to ignore these files when calling `dotify link` in the `.dotrc` in this way:
46
-
47
- $ cat ~/.dotrc
48
- ignore:
49
- dotify:
50
- - '.git'
51
- - '.gitmodules'
52
- - '.gitignore'
53
-
54
- The same can be done for the home directory when running `dotify setup`. There are some directories that you should not move around (`.dropbox`, `.rbenv`, `.rvm`) and do not want to accidentally attempt to move. You can do that in your `.dotrc` file as well:
55
-
56
- $ cat ~/.dotrc
57
- ignore:
58
- dotfiles:
59
- - '.dropbox'
60
- - '.rbenv'
61
- - '.rvm'
62
-
63
- More configuration options will likely be added in future versions, so be sure to check up here for your options.
64
-
65
- ### Install Dotify
66
-
67
- Now that you have configured Dotify to your liking, you should now run `dotify install`.
68
-
69
- $ dotify install
70
34
  Do you want to add .bash_history to Dotify? [Yn] n
71
35
  Do you want to add .bashrc to Dotify? [Yn] y
72
36
  create /Users/mattbridges/.dotify/.bashrc
@@ -76,6 +40,12 @@ Now that you have configured Dotify to your liking, you should now run `dotify i
76
40
  create /Users/mattbridges/.dotify/.zshrc
77
41
  ...
78
42
 
43
+ 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!).
44
+
45
+ During the installation process, a Vim instance will open with a sample `.dotrc` file for you to edit and configure if you desire. This will allow your configuration to be used prior to Dotify's full installation. See more about the `.dotrc` file in the [Configuration](https://github.com/mattdbridges/dotify/tree/cli-rewrite#configuration) section.
46
+
47
+ Alternatively, you could run `dotify setup` to setup Dotify's configuration, followed by `dotify install` to add the initial files into Dotify.
48
+
79
49
  ### Add single files
80
50
 
81
51
  After you have setup Dotify, you can add files one by one if you did not add them during setup
@@ -99,31 +69,29 @@ If you do this and decide to change your mind, the file is still located in the
99
69
  This is the heart of the Dotify tool. This command will link the files within the `~/.dotify` directory into your home directory.
100
70
 
101
71
  $ dotify link
102
- Do you want to link ~/.bashrc? [Yn] Y
103
- create /Users/computer-user/.bashrc
104
- Do you want to link ~/.gemrc? [Yn] Y
105
- identical /Users/computer-user/.gemrc
106
- Do you want to link ~/.gitconfig? [Yn] Y
107
- create /Users/computer-user/.gitconfig
108
- Do you want to link ~/.gitignore? [Yn] Y
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
109
77
  ...
110
78
 
111
79
  You can also link files one-by-one by passing the filename to the `link` task.
112
80
 
113
81
  $ dotify link .bashrc
114
82
  Do you want to link ~/.bashrc? [Yn] Y
115
- create /Users/computer-user/.bashrc
83
+ linked /Users/mattbridges/.bashrc
116
84
 
117
85
  ### Unlink everything
118
86
 
119
87
  Don't want any of the dotfiles anymore? Well, I'm not one to question. Go ahead and wipe them out.
120
88
 
121
89
  $ dotify unlink
122
- Are you sure you want to remove ~/.bashrc? [Yn] Y
123
- remove /Users/computer-user/.bashrc
124
- Are you sure you want to remove ~/.gemrc? [Yn] Y
125
- remove /Users/computer-user/.gemrc
126
- Are you sure you want to remove ~/.gitconfig? [Yn] n
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
127
95
  ...
128
96
 
129
97
  Should you run this horrid task accidentally, you can simply run `dotify link` again if you want to restore your previous settings.
@@ -134,16 +102,63 @@ By default, `unlink` loops through all of the Dotify files. You can also pass a
134
102
  Are you sure you want to remove ~/.bashrc? [Yn] Y
135
103
  remove /Users/mattbridges/.bashrc
136
104
 
137
- ## Confused?
105
+ ## Versioning
106
+
107
+ The whole purpose of this gem was to manage the dotfiles on your system. What better way to do this than under version control using [Git](http://git-scm.com/) and [Github](https://github.com)?
108
+
109
+ * To version your Dotify installation, simple make `.dotify` a Git repository. If you don't know how to do that, I recommend you start reading [here](http://git-scm.com/book/en/Getting-Started).
110
+ * Add your remote repository via `git remote add [NAME] [REPO]`.
111
+
112
+ *From this point, you can manage your dotfiles entirely from Dotify.*
113
+
114
+ * To edit a dotfile managed by Dotify, simple run `dotify edit [DOTFILE]` and replace **[DOTFILE]** with the name of the file you want to edit. This will open a Vim instance containing that file for editing.
115
+ * Once you have saved your edits, simple run `dotify save` and Dotify will walk you through the steps of committing your changes and pushing them up to Github.
116
+
117
+ ## Configuration
118
+
119
+ The `.dotrc` file in your home directory serves as the configuration file for Dotify. It is a [YAML](http://www.yaml.org/) formatted file.
120
+
121
+ #### Dotify Editor
122
+
123
+ When you run `dotify edit [DOTFILE]`, by default the file opens in Vim for editing. You can change this by adding this following to your `.dotrc` file.
124
+
125
+ editor: 'vi'
126
+ # or 'vim' or 'emacs' etc...
127
+
128
+ Vim and Emacs are the only two editors that have been successfully used with this configuration option, but if you find another, please [let me know](https://github.com/mattdbridges/dotify/issues/new) and I will update the documentation.
129
+
130
+ #### Ignoring files
131
+
132
+ When you are linking files in your Dotify directory, some files you do not want ever want to link (`.git`, `.gitmodules`, `.gitignore`, .etc) because they are used specifically for that directory (such as git versioning). You can configure Dotify to ignore these files when calling `dotify link` in the `.dotrc` in this way:
133
+
134
+ $ cat ~/.dotrc
135
+ ignore:
136
+ dotify:
137
+ - '.git'
138
+ - '.gitmodules'
139
+ - '.gitignore'
140
+
141
+ The same can be done for the home directory when running `dotify setup`. There are some directories that you should not move around (`.dropbox`, `.rbenv`, `.rvm`) and do not want to accidentally attempt to move. You can do that in your `.dotrc` file as well:
142
+
143
+ $ cat ~/.dotrc
144
+ ignore:
145
+ dotfiles:
146
+ - '.dropbox'
147
+ - '.rbenv'
148
+ - '.rvm'
149
+
150
+ More configuration options will likely be added in future versions, so be sure to check up here for your options.
138
151
 
139
- Dotify can manages dotfiles from two different directions:
152
+ ## Clarifying the add/remove/link/unlink tasks
140
153
 
141
- 1. `add` and `remove` both look in the user's home directory for dotfiles to manage
142
- 2. `link` and `unlink` both look in the Dotify directory for dotfiles to manage.
154
+ Here is a little clarification on the `add`/`remove`/`link`/`unlink` tasks.
143
155
 
144
- 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.
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.
145
160
 
146
- 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.
161
+ For instructions on how to use these methods, use `dotify help [TASK]` for further explanation.
147
162
 
148
163
  ## Not sure what to do?
149
164
 
@@ -151,12 +166,16 @@ This tool is powered by the amazing library, [Thor](http://whatisthor.com/). You
151
166
 
152
167
  $ dotify help
153
168
  Tasks:
154
- dotify add [FILENAME] # Add a single dotfile to the Dotify directory
155
- dotify help [TASK] # Describe available tasks or one specific task
156
- dotify link # Link up all of your dotfiles
157
- dotify remove [FILENAME] # Remove a single dotfile from Dotify
158
- dotify setup # Setup your system for Dotify to manage your dotfiles
159
- dotify unlink # Unlink all of your dotfiles
169
+ dotify add {{FILENAME}} # Add a one or more dotfiles to Dotify. (FILENAME is optional)
170
+ dotify edit [FILE] # Edit a dotify file
171
+ dotify help [TASK] # Describe available tasks or one specific task
172
+ 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
176
+ 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)
178
+ dotify version # Check your Dotify version
160
179
 
161
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.
162
181
 
@@ -32,24 +32,31 @@ module Dotify
32
32
  def save
33
33
  Dir.chdir(Config.path) do
34
34
  system 'git fetch'
35
- uncommitted = `git status`.chomp.to_i != 2
35
+ uncommitted = `git status | wc -l`.chomp.to_i != 2
36
36
  if uncommitted
37
+ puts `git status` # show the status output
37
38
  message = !options[:message].nil? ? options[:message] : ask("Commit message:", :blue)
38
39
  system 'git add .'
39
40
  system "git commit -m '#{message.gsub(/[']/, '\\\\\'')}'"
40
- end
41
- if `git log origin/master.. --oneline | wc -l`.chomp.to_i != 0
42
- say 'Pushing up to Github...', :blue
43
- system 'git push origin master'
41
+ if `git log origin/master.. --oneline | wc -l`.chomp.to_i != 0
42
+ say 'Pushing up to Github...', :blue
43
+ system 'git push origin master'
44
+ end
45
+ else
46
+ say 'Dotify has nothing to save.', :blue
44
47
  end
45
48
  end
46
49
  end
47
50
 
48
- desc :edit, "Edit a dotify file"
51
+ desc 'edit [FILE]', "Edit a dotify file"
49
52
  method_option :save, :aliases => '-s', :default => false, :type => :boolean, :require => true, :desc => "Save Dotify files and push to Github"
50
53
  def edit(filename)
51
- system "#{Config.editor} #{Files.dotify(filename)}"
52
- save if options[:save] == true
54
+ if Files.linked.include? Files.dotify(filename)
55
+ exec "#{Config.editor} #{Files.dotify(filename)}"
56
+ save if options[:save] == true
57
+ else
58
+ say "'#{Files.filename(filename)}' has not been linked by Dotify. Please run `dotify link #{Files.filename(filename)}` to edit this file.", :blue
59
+ end
53
60
  end
54
61
 
55
62
  desc :version, "Check your Dotify version"
@@ -67,95 +74,96 @@ module Dotify
67
74
  end
68
75
 
69
76
  desc :setup, "Setup your system for Dotify to manage your dotfiles"
70
- method_option :install, :default => false, :type => :boolean, :aliases => '-i', :desc => "Run Dotify install right away. This does not allow for customizing your .dotrc file before attempting install files into Dotify."
71
- method_option :verbose, :default => true, :type => :boolean, :aliases => '-v', :desc => "Setup Dotify with verbose output."
77
+ method_option :install, :type => :boolean, :default => true, :desc => "Install Dotify after setup"
78
+ method_option "edit-config", :type => :boolean, :default => true, :desc => "Edit Dotify's configuration."
79
+ method_options :verbose => true
72
80
  def setup
73
- return say('Dotify has already been setup!', :blue) if Dotify.installed?
74
- empty_directory(Config.path, :verbose => options[:verbose])
75
- dotrc = File.join(Config.home, Config::DOTIFY_CONFIG)
76
- template Config::DOTIFY_CONFIG, dotrc, :verbose => options[:verbose]
81
+ # Warn if Dotify is already setup
82
+ if !Dotify.installed?
83
+ say "Dotify is already setup", :blue
84
+ end
85
+
86
+ # Create the Dotify directory unless it already exists
87
+ unless File.exists?(Config.path)
88
+ empty_directory(Config.path, :verbose => options[:verbose])
89
+ end
90
+
91
+ # Create the Dotify config file unless it already exists
92
+ unless File.exists?(Config.file)
93
+ template '.dotrc', Config.file, :verbose => options[:verbose]
94
+ end
95
+
96
+ say "Editing config file...", :blue
97
+ sleep 1 # Give a little time for reading the message
98
+ invoke :edit, [Config.file]
99
+ say "Config file updated.", :blue
100
+
101
+ # Run install task if specified
77
102
  invoke :install if options[:install] == true
78
103
  end
79
104
 
80
105
  desc :install, "Install files from your home directory into Dotify"
81
- method_option :link, :default => false, :type => :boolean, :aliases => '-l', :desc => "Link dotfiles when setup is complete"
82
106
  def install
83
107
  invoke :setup unless Dotify.installed?
84
- Files.uninstalled do |path, file|
85
- add_file(file, options.merge(:quiet => true)) unless Config.dirname == file
86
- end
87
- say "Dotify has been successfully setup.", :blue
88
- if options[:link]
89
- say "Linking up the new dotfiles...", :blue
90
- invoke :link, nil, { :all => true }
91
- end
108
+ invoke :add
92
109
  end
93
110
 
94
- desc "add [FILENAME]", "Add a single dotfile to the Dotify directory"
95
- method_option :force, :default => false, :type => :boolean, :aliases => '-f', :desc => "Add file without confirmation"
96
- def add(file)
97
- return not_setup_warning unless Dotify.installed?
98
- add_file(file, options)
111
+ desc "add {{FILENAME}}", "Add a one or more dotfiles to Dotify. (FILENAME is optional)"
112
+ method_option :force, :type => :boolean, :default => false, :aliases => '-f', :desc => "Remove Dotify file(s) without confirmation"
113
+ def add(file=nil)
114
+ not_setup_warning unless Dotify.installed?
115
+ if file.nil?
116
+ Files.uninstalled { |path, file| add_dotify_file(file, options) }
117
+ else
118
+ add_dotify_file(file, options.merge(:single => true))
119
+ end
99
120
  end
100
121
 
101
- desc "remove [FILENAME]", "Remove a single dotfile from Dotify"
102
- long_desc <<-STRING
103
- `dotify remove [FILENAME]` removes the dotfiles from the Dotify directory
104
- and moves it back into the home directory. If you decide you want Dotify
105
- to manage that file again, you can simply run `dotify add [FILENAME]` to
106
- add it back again.
107
- STRING
108
- method_option :force, :default => false, :type => :boolean, :aliases => '-f', :desc => "Remove file without confirmation"
109
- method_option :quiet, :default => false, :type => :boolean, :aliases => '-q', :desc => "Don't output anything"
110
- def remove(file)
111
- return not_setup_warning unless Dotify.installed?
112
- if !File.exists?(Files.dotify(file))
113
- say "Dotify is not currently managing ~/#{file}.", :blue unless options[:quiet] == true
114
- return
115
- end
116
- if options[:force] == true || yes?("Are you sure you want to remove #{file} from Dotify? [Yn]", :yellow)
117
- remove_file Files.dotfile(file), :verbose => false
118
- copy_file Files.dotify(file), Files.dotfile(file), :verbose => false
119
- remove_file Files.dotify(file), :verbose => false
120
- say_status :removed, Files.dotify(file) unless options[:quiet] == true
122
+ desc "remove {{FILENAME}}", "Remove a single dotfile from Dotify (FILENAME is optional)"
123
+ long_desc <<-DESC
124
+ This removes the dotfiles from the Dotify directory and move \
125
+ it back into the home directory. If you decide you want Dotify \
126
+ to manage that file again, you can simply run `dotify add [FILENAME]` \
127
+ to add it back again.
128
+ DESC
129
+ method_option :force, :type => :boolean, :default => false, :aliases => '-f', :desc => "Remove Dotify file(s) without confirmation"
130
+ def remove(file=nil)
131
+ not_setup_warning unless Dotify.installed?
132
+ if file.nil?
133
+ Files.linked { |path, file| remove_dotify_file(file, options) }
134
+ else
135
+ remove_dotify_file(file, options)
121
136
  end
122
137
  end
123
138
 
124
139
  desc 'link {{FILENAME}}', "Link up one or all of your dotfiles (FILENAME is optional)"
125
- method_option :all, :default => false, :type => :boolean, :aliases => '-a', :desc => "Link dotfiles without confirmation"
140
+ method_option :force, :default => false, :type => :boolean, :aliases => '-f', :desc => "Link dotfiles without confirmation"
126
141
  def link(file=nil)
127
- return not_setup_warning unless Dotify.installed?
142
+ not_setup_warning unless Dotify.installed?
128
143
  if file.nil?
129
- count = 0
130
- Files.dots do |file, dot|
131
- count += 1 if link_file(file, dot, options) == true
144
+ Files.unlinked do |path, file|
145
+ link_file(file, options)
132
146
  end
133
- say "No files were linked.", :blue if count == 0
134
147
  else
135
- link_file(file, Files.filename(file), options)
148
+ link_file(file, options)
136
149
  end
137
150
  end
138
151
 
139
152
  desc 'unlink {{FILENAME}}', "Unlink one or all of your dotfiles (FILENAME is optional)"
140
- long_desc <<-STRING
141
- `dotify unlink` removes the dotfiles from the home directory and preserves the
142
- files in the Dotify directory. This allows you to simply run `dotify link` again
153
+ long_desc <<-DESC
154
+ This removes the dotfiles from the home directory and preserves the \
155
+ files in the Dotify directory. This allows you to simply run `dotify link` again \
143
156
  should you decide you want to relink anything to the Dotify files.
144
- STRING
145
- method_option :all, :default => false, :type => :boolean, :aliases => '-a', :desc => 'Remove all installed dotfiles without confirmation'
157
+ DESC
158
+ method_option :force, :default => false, :type => :boolean, :aliases => '-f', :desc => 'Remove all installed dotfiles without confirmation'
146
159
  def unlink(file = nil)
147
- return not_setup_warning unless Dotify.installed?
160
+ not_setup_warning unless Dotify.installed?
148
161
  if file.nil?
149
- count = 0
150
- Files.installed do |file, dot|
151
- if options[:all] || yes?("Are you sure you want to remove ~/#{dot}? [Yn]", :yellow)
152
- unlink_file(file)
153
- count += 1
154
- end
162
+ Files.linked do |path, file|
163
+ unlink_file(file, options)
155
164
  end
156
- say "No files were unlinked.", :blue if count == 0
157
165
  else
158
- unlink_file(file)
166
+ unlink_file(file, options)
159
167
  end
160
168
  end
161
169
 
@@ -165,53 +173,78 @@ module Dotify
165
173
  say('Dotify has not been setup yet! You need to run \'dotify setup\' first.', :yellow)
166
174
  end
167
175
 
168
- def unlink_file(file)
169
- remove_file Files.dotfile(file)
170
- return true
176
+ def unlink_file(file, options = {})
177
+ file = Files.filename(file)
178
+ dot = Files.dotfile(file)
179
+ dotify = Files.dotify(file)
180
+ if File.exists?(dot) && File.exists?(dotify)
181
+ if options[:force] == true || yes?("Do you want to unlink #{file} from the home directory? [Yn]", :blue)
182
+ FileUtils.rm_rf dot
183
+ say_status :unlinked, dot
184
+ end
185
+ else
186
+ say "'#{file}' does not exist in Dotify.", :blue
187
+ end
171
188
  end
172
189
 
173
- def link_file(file, dot, options = {})
174
- if options[:all]
175
- if File.exists? Files.dotfile(file)
176
- replace_link Files.dotfile(file), file
177
- else
178
- create_link Files.dotfile(file), file
190
+ def link_file(file, options = {})
191
+ file = Files.filename(file)
192
+ home = Files.dotfile(file)
193
+ path = Files.dotify(file)
194
+ status = case
195
+ when !File.exists?(home) then :linked
196
+ when File.exists?(home) then :replaced; end
197
+ if File.exists?(path)
198
+ if options[:force] == true || yes?("Do you want to link #{file} to the home directory? [Yn]", :blue)
199
+ FileUtils.rm_rf(home, :verbose => false)
200
+ FileUtils.ln_s(path, home, :verbose => false)
201
+ say_status status, home
179
202
  end
180
- return true
181
203
  else
182
- if yes?("Do you want to link ~/#{dot}? [Yn]", :yellow)
183
- create_link Files.dotfile(file), file
184
- return true
185
- end
186
- return false
204
+ say "'#{file}' does not exist in the home directory.", :blue
187
205
  end
188
- return false
189
206
  end
190
207
 
191
- def add_file(file, options = {})
208
+ def remove_dotify_file(file, options = {})
192
209
  file = Files.filename(file)
193
- dotfile = Files.dotfile(file)
194
- dotify_file = Files.dotify(file)
195
-
196
- if !File.exist?(dotfile) || !File.identical?(dotfile, dotify_file)
197
- if options[:force] == true || yes?("Do you want to add #{file} to Dotify? [Yn]", :yellow)
198
- if File.directory?(dotfile)
199
- FileUtils.rm_rf dotify_file
200
- FileUtils.cp_r dotfile, dotify_file
201
- say_status :create, dotify_file
210
+ home = Files.dotfile(file)
211
+ path = Files.dotify(file)
212
+ if File.exist?(home) && File.exist?(path)
213
+ if options[:force] == true || yes?("Do you want to remove #{file} from Dotify? [Yn]", :blue)
214
+ FileUtils.rm_rf(home, :verbose => false)
215
+ if File.directory? path
216
+ FileUtils.cp_r(path, home, :verbose => false)
202
217
  else
203
- copy_file dotfile, dotify_file
218
+ FileUtils.cp(path, home, :verbose => false)
204
219
  end
220
+ FileUtils.rm_rf(path, :verbose => false)
221
+ say_status :removed, path
205
222
  end
223
+ elsif File.exist?(home) && !File.exist?(path)
224
+ say "The file '#{file}' is not managed by Dotify. Cannot remove.", :blue
206
225
  else
207
- say "'#{file}' does not exist or is already installed in Dotify.", :blue unless options[:quiet] == true
226
+ say "The file '~/#{file}' does not exist", :blue
208
227
  end
209
228
  end
210
229
 
211
- def replace_link(dotfile, file)
212
- remove_file dotfile, :verbose => false
213
- create_link dotfile, file, :verbose => false
214
- say_status :replace, dotfile
230
+ def add_dotify_file(file, options = {})
231
+ file = Files.filename(file)
232
+ home = Files.dotfile(file)
233
+ path = Files.dotify(file)
234
+ if File.exist?(home)
235
+ if options[:force] == true || yes?("Do you want to add #{file} to Dotify? [Yn]", :blue)
236
+ if File.directory? home
237
+ FileUtils.cp_r(home, path, :verbose => false)
238
+ else
239
+ FileUtils.cp(home, path, :verbose => false)
240
+ say_status :adding, path
241
+ end
242
+ end
243
+ else
244
+ if options[:single] == true
245
+ say "The file '#{file}' doesn't exist or Dotify already manages it.", :blue
246
+ end
247
+ end
215
248
  end
216
249
 
217
250
  end
@@ -5,13 +5,18 @@ require 'yaml'
5
5
  module Dotify
6
6
  class Config
7
7
 
8
- DOTIFY_DIRNAME = '.dotify'
9
- DOTIFY_CONFIG = '.dotrc'
8
+ DIRNAME = '.dotify'
9
+ CONFIG_FILE = '.dotrc'
10
+ EDITOR = 'vim'
11
+ DEFAULT_IGNORE = {
12
+ :dotify => %w[.git .gitmodule],
13
+ :dotfiles => %w[.DS_Store .Trash .dropbox .dotify]
14
+ }
10
15
 
11
16
  class << self
12
17
 
13
18
  def dirname
14
- @dirname ||= DOTIFY_DIRNAME
19
+ @dirname ||= DIRNAME
15
20
  end
16
21
 
17
22
  def installed?
@@ -23,16 +28,16 @@ module Dotify
23
28
  end
24
29
 
25
30
  def editor
26
- config.fetch(:editor, 'vi')
31
+ config.fetch(:editor, 'vim')
27
32
  end
28
33
 
29
34
  def load_config!
30
- config = File.exists?(config_file) ? (YAML.load_file(config_file) || {}) : {}
35
+ config = File.exists?(file) ? (YAML.load_file(file) || {}) : {}
31
36
  symbolize_keys!(config)
32
37
  end
33
38
 
34
39
  def ignore(what)
35
- config.fetch(:ignore, {}).fetch(what, [])
40
+ (config.fetch(:ignore, {}).fetch(what, []) + DEFAULT_IGNORE.fetch(what, [])).uniq
36
41
  end
37
42
 
38
43
  def config
@@ -43,11 +48,11 @@ module Dotify
43
48
  Thor::Util.user_home
44
49
  end
45
50
 
46
- private
51
+ def file
52
+ File.join(home, CONFIG_FILE)
53
+ end
47
54
 
48
- def config_file
49
- File.join(home, DOTIFY_CONFIG)
50
- end
55
+ private
51
56
 
52
57
  def symbolize_keys!(opts)
53
58
  sym_opts = {}
@@ -10,33 +10,33 @@ module Dotify
10
10
  include Thor::Shell
11
11
  include Thor::Actions
12
12
 
13
- def dots
14
- @dots ||= FileList.dotify
15
- return @dots unless block_given?
16
- @dots.each {|d| yield(d, filename(d)) }
13
+ def linked
14
+ @linked ||= FileList.dotify
15
+ return @linked unless block_given?
16
+ @linked.each {|d| yield(d, filename(d)) }
17
17
  end
18
18
 
19
19
  def unlinked
20
- dots = self.dots.map { |d| filename(d) }
20
+ linked = self.linked.map { |d| filename(d) }
21
21
  installed = self.installed.map {|i| filename(i)}
22
- unlinked = (dots - installed).map{|f| dotfile(f) }
22
+ unlinked = (linked - installed).map{|f| dotfile(f) }
23
23
  return unlinked unless block_given?
24
24
  unlinked.each {|u| yield(u, filename(u)) }
25
25
  end
26
26
 
27
27
  def installed
28
- dots = self.dots.map { |f| filename(f) }
28
+ linked = self.linked.map { |f| filename(f) }
29
29
  installed = FileList.home.select do |d|
30
- dots.include?(filename(d))
30
+ linked.include?(filename(d))
31
31
  end
32
32
  return installed unless block_given?
33
33
  installed.each {|i| yield(i, filename(i)) }
34
34
  end
35
35
 
36
36
  def uninstalled
37
- dots = self.dots.map { |f| filename(f) }
37
+ linked = self.linked.map { |f| filename(f) }
38
38
  installed = FileList.home.select do |d|
39
- !dots.include?(filename(d))
39
+ !linked.include?(filename(d))
40
40
  end
41
41
  return installed unless block_given?
42
42
  installed.each {|i| yield(i, filename(i)) }
@@ -1,3 +1,3 @@
1
1
  module Dotify
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -26,7 +26,7 @@ describe Dotify::Config do
26
26
  Dotify::Config.path.should == File.join(Dotify::Config.home, '.dotify')
27
27
  end
28
28
  it "should set a default editor" do
29
- Dotify::Config.editor.should == 'vi'
29
+ Dotify::Config.editor.should == Dotify::Config::EDITOR
30
30
  end
31
31
  it "should allow a custom editor" do
32
32
  Dotify::Config.stub(:config) do
@@ -35,12 +35,28 @@ describe Dotify::Config do
35
35
  Dotify::Config.editor.should == 'subl'
36
36
  end
37
37
  end
38
+
39
+ describe Dotify::Config, "#file" do
40
+ it "should return the right page" do
41
+ Dotify::Config.stub(:home).and_return('/tmp')
42
+ Dotify::Config.file.should == '/tmp/.dotrc'
43
+ end
44
+ end
45
+
38
46
  describe "ignore files" do
39
47
  before do
40
48
  Dotify::Config.stub(:config) do
41
49
  { :ignore => { :dotfiles => %w[.gemrc], :dotify => %w[.gitmodule] } }
42
50
  end
43
51
  end
52
+ it "should have a default set of dotfiles" do
53
+ Dotify::Config.stub(:config).and_return({})
54
+ Dotify::Config.ignore(:dotify).should include '.git'
55
+ Dotify::Config.ignore(:dotify).should include '.gitmodule'
56
+ Dotify::Config.ignore(:dotfiles).should include '.dropbox'
57
+ Dotify::Config.ignore(:dotfiles).should include '.Trash'
58
+ Dotify::Config.ignore(:dotfiles).should include '.dotify'
59
+ end
44
60
  it "should retrieve the list of dotfiles to ignore in the home directory" do
45
61
  Dotify::Config.ignore(:dotfiles).should include '.gemrc'
46
62
  end
@@ -6,8 +6,8 @@ require 'fileutils'
6
6
  describe Dotify::Files do
7
7
 
8
8
  describe "methods" do
9
- it "should respond to dots" do
10
- Dotify::Files.should respond_to :dots
9
+ it "should respond to linked" do
10
+ Dotify::Files.should respond_to :linked
11
11
  end
12
12
  it "should respond to installed" do
13
13
  Dotify::Files.should respond_to :installed
@@ -24,27 +24,28 @@ describe Dotify::Files do
24
24
 
25
25
  describe Dotify::Files, "#dotfile" do
26
26
  it "should return the path to the file when it is linked in the root" do
27
- Dotify::Files.dotfile(".vimrc").should == File.join(Dotify::Config.home, ".vimrc")
28
- Dotify::Files.dotfile("/spec/home/.bashrc").should == File.join(Dotify::Config.home, ".bashrc")
27
+ Dotify::Config.stub(:home).and_return '/home'
28
+ Dotify::Files.dotfile(".vimrc").should == '/home/.vimrc'
29
+ Dotify::Files.dotfile("/spec/home/.bashrc").should == '/home/.bashrc'
29
30
  end
30
31
  end
31
32
 
32
33
  describe Dotify::Files, "#dotify" do
33
34
  it "should return the path to the file when it is linked in the root" do
34
- Dotify::Files.dotify(".vimrc").should == File.join(Dotify::Config.path, ".vimrc")
35
- Dotify::Files.dotify("/spec/home/.bashrc").should == File.join(Dotify::Config.path, ".bashrc")
35
+ Dotify::Config.stub(:path).and_return '/tmp'
36
+ Dotify::Files.dotify(".vimrc").should == '/tmp/.vimrc'
37
+ Dotify::Files.dotify("/spec/home/.bashrc").should == '/tmp/.bashrc'
36
38
  end
37
39
  end
38
40
 
39
- describe Dotify::Files, "#dots" do
41
+ describe Dotify::Files, "#linked" do
40
42
  before do
41
43
  Dotify::FileList.stub(:dotify) do
42
44
  ['/spec/test/.bash_profile', '/spec/test/.bashrc', '/spec/test/.zshrc']
43
45
  end
44
46
  end
45
- let!(:files) { Dotify::Files.dots }
47
+ let!(:files) { Dotify::Files.linked }
46
48
  it "should return the list of dotfiles in the dotify path" do
47
- files
48
49
  files.map! { |f| Dotify::Files.filename(f) }
49
50
  files.should include '.bash_profile'
50
51
  files.should include '.bashrc'
@@ -52,13 +53,13 @@ describe Dotify::Files do
52
53
  end
53
54
  it "shoud yield the files if a block is given" do
54
55
  yields = files.map { |f| [f, Dotify::Files.filename(f)] }
55
- expect { |b| Dotify::Files.dots(&b) }.to yield_successive_args(*yields)
56
+ expect { |b| Dotify::Files.linked(&b) }.to yield_successive_args(*yields)
56
57
  end
57
58
  end
58
59
 
59
60
  describe Dotify::Files, "#unlinked" do
60
61
  before do
61
- Dotify::Files.stub(:dots) do
62
+ Dotify::Files.stub(:linked) do
62
63
  ['/spec/test/.vimrc', '/spec/test/.bashrc', '/spec/test/.zshrc']
63
64
  end
64
65
  Dotify::Files.stub(:installed) do
@@ -78,7 +79,7 @@ describe Dotify::Files do
78
79
 
79
80
  describe Dotify::Files, "#installed" do
80
81
  before do
81
- Dotify::Files.stub(:dots) do
82
+ Dotify::Files.stub(:linked) do
82
83
  %w[/spec/test/.zshrc /spec/test/.bashrc /spec/test/.vimrc /spec/test/.dotify]
83
84
  end
84
85
  Dotify::FileList.stub(:home) do
@@ -100,7 +101,7 @@ describe Dotify::Files do
100
101
 
101
102
  describe Dotify::Files, "#uninstalled" do
102
103
  before do
103
- Dotify::Files.stub(:dots) do
104
+ Dotify::Files.stub(:linked) do
104
105
  %w[/spec/test/.zshrc /spec/test/.bashrc /spec/test/.vimrc /spec/test/.dotify]
105
106
  end
106
107
  Dotify::FileList.stub(:home) do
@@ -5,7 +5,6 @@
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
8
  Dir["./spec/support/**/*.rb"].each { |f| require f }
10
9
 
11
10
  RSpec.configure do |config|
@@ -1,3 +1,9 @@
1
+ # Set the editor to use when editing Dotify dotfiles.
2
+ # Default: 'vim'
3
+ # Options: 'vi', 'vim', 'emacs', '[ANY OTHER TERMINAL BASED EDITOR]'
4
+ #
5
+ # editor: 'vi'
6
+ #
1
7
  # Ignoring files in ~/.dotify when linking:
2
8
  #
3
9
  # ignore:
@@ -5,10 +11,7 @@
5
11
  # - '.git'
6
12
  # - '.gitignore'
7
13
  # - '.gitmodules'
8
- #
9
- # Ignoring files in the home directory when linking:
10
- #
11
- # ignore:
14
+ # # Ignoring files in the home directory when linking:
12
15
  # dotify:
13
16
  # - '.rbenv'
14
17
  # - '.rvm'
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.0
4
+ version: 0.5.0
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-07-02 00:00:00.000000000 Z
12
+ date: 2012-07-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor