deploydots 0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. data/bin/deploydots +81 -0
  2. metadata +46 -0
data/bin/deploydots ADDED
@@ -0,0 +1,81 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'find'
4
+
5
+ $replace_all = false
6
+
7
+ home_dir = Dir.home
8
+ dotfiles_dir = File.join home_dir, 'dotfiles'
9
+
10
+ Dir.chdir dotfiles_dir
11
+
12
+ # makes a symlink which points from new -> old
13
+ def link old, new
14
+ if File.exists? new
15
+ if File.symlink? new
16
+ return # symlinked already
17
+ else # file exists but isn't a symlink, assuming regular file
18
+ if $replace_all
19
+ File.delete new
20
+ File.symlink old, new
21
+ return
22
+ end
23
+
24
+ # ask what we should do (replace, replace_all, skip, skip_all, or quit)
25
+ response = nil
26
+ loop do
27
+ puts "#{new} already exists, 1) replace 2) replace all 3) quit"
28
+ begin
29
+ response = Integer gets.chomp
30
+ rescue ArgumentError
31
+ puts "not a valid number"
32
+ end
33
+
34
+ if (1..3).member? response
35
+ break
36
+ else
37
+ puts "number not in range of 1..3"
38
+ redo
39
+ end
40
+ end
41
+
42
+ case response
43
+ when 1
44
+ File.delete new
45
+ File.symlink old, new
46
+ when 2
47
+ $replace_all = true
48
+ File.delete new
49
+ File.symlink old, new
50
+ when 3
51
+ exit
52
+ end
53
+ end
54
+ else
55
+ # just create a regular symlink
56
+ File.symlink old, new
57
+ end
58
+ end
59
+
60
+ Dir['*'].each do |topfile|
61
+ next if topfile == 'README.md'
62
+ dotfile_name = '.' + topfile
63
+ dotfile_path = File.join home_dir, dotfile_name
64
+ topfile_path = File.join dotfiles_dir, topfile
65
+ if File.directory? topfile
66
+ Dir.mkdir dotfile_path unless File.directory? dotfile_path # create the folder unless it already exists
67
+
68
+ Find.find(topfile) do |file|
69
+ dotfile_child_path = File.join(home_dir, '.' + file)
70
+ topfile_child_path = File.join(dotfiles_dir, file)
71
+ if File.directory? topfile_child_path
72
+ Dir.mkdir dotfile_child_path unless File.directory? dotfile_path # create the folder unless it already exists
73
+ else # regular file
74
+ link topfile_child_path, dotfile_child_path
75
+ end
76
+ end
77
+
78
+ else # just a regular file
79
+ link topfile_path, dotfile_path
80
+ end
81
+ end
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: deploydots
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Thomas Dziedzic
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-29 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Symlinks all your dot files from ~/dotfiles into ~
15
+ email: gostrc@gmail.com
16
+ executables:
17
+ - deploydots
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - bin/deploydots
22
+ homepage: https://github.com/gostrc/deploydots
23
+ licenses: []
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ none: false
36
+ requirements:
37
+ - - ! '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubyforge_project:
42
+ rubygems_version: 1.8.15
43
+ signing_key:
44
+ specification_version: 3
45
+ summary: Deploy your dots!
46
+ test_files: []