-
Notifications
You must be signed in to change notification settings - Fork 2
/
Rakefile
133 lines (109 loc) · 3.77 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
require 'rake'
require 'erb'
HOME_DIR = File.expand_path('~')
LINKS = {
"/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" =>
"/usr/local/bin/subl",
"/Applications/Sublime Merge.app/Contents/SharedSupport/bin/smerge" =>
"/usr/local/bin/smerge"
}
FILES = {
:dotfiles => {
"files/aws-credentials.yml" => "~/.aws/credentials",
"files/bash_profile.sh" => "~/.bash_profile",
"files/bashrc.sh" => "~/.bashrc",
"files/bundle_config.ini" => "~/.bundle/config",
"files/dotfiles.sh" => "~/.dotfiles",
"files/gemrc.yml" => "~/.gemrc",
"files/gem-credentials.yml" => "~/.gem/credentials",
"files/gitconfig.ini" => "~/.gitconfig",
"files/gitignore_global" => "~/.gitignore_global",
"files/hub.zsh_completion.sh" => "~/.zsh/completions/hub.zsh_completion",
"files/iterm2/switch_automatic.py" => "~/Library/Application\ Support/iTerm2/Scripts/AutoLaunch/switch_automatic.py",
"files/ruby-gemset" => "~/Code/.ruby-gemset",
"files/ruby-version" => "~/Code/.ruby-version",
"files/ssh-config.ini" => "~/.ssh/config",
"files/vimrc.sh" => "~/.vimrc",
"files/zshrc.sh" => "~/.zshrc",
"files/zprofile.sh" => "~/.zprofile"
},
}
################################################################################
def get_user_information
puts "\nPlease write your information:"
@full_name = ask(" - Your full name: ")
@github_user = ask(" - GitHub username (without the @): ")
@github_email = ask(" - GitHub email: ")
@projects_dir = ask(" - Work directory. Like `~/Code`: ")
puts "\nHello! #{@full_name}"
end
def ask message="", required=true
print message
data = STDIN.gets.chomp
if data=="" && required
puts "Aborted. This field can't be blank."
exit
end
data
end
def create_links
LINKS.each do |from, to|
puts "\t#{from} => #{to}"
to.gsub!('~', HOME_DIR)
if File.exist?(from) && !File.exist?(to)
system %Q{ln -s "#{from}" "#{to}"}
else
puts "The destination already exists: #{to}" if File.exist?(to)
puts "The origin file doesn't exist: #{from}" unless File.exist?(from)
end
end
end
def create_files group
FILES[group].each do |from, to|
puts "\t#{from} => #{to}"
to.gsub!('~', HOME_DIR)
# Folders
folder = File.expand_path(File.dirname(to))
system %Q{ mkdir -p "#{folder}"} unless File.exist?(folder)
# Backup
if File.exist?(to) && !File.exist?("#{to}.dotfiles-backup")
system %Q{cp "#{to}" "#{to}.dotfiles-backup"}
end
# Content
content = ERB.new(File.read(from)).result(binding)
File.open(to, 'w') do |new_file|
new_file.write content
end
end
end
def list_files group
puts "Going to replace this files:"
FILES[group].values.sort!.each do |value|
puts "\t#{value}"
end
end
def reload_bash
puts "Please reload your terminal"
end
################################################################################
desc "Help"
task :help do
puts "Please execute rake -T to see the available commands."
end
desc "At user's home directory"
task :install do
get_user_information
list_files :dotfiles
exit if ask("\nContinue? [Y/N]: ", false)!='Y'
create_files :dotfiles
# create_links # Permission denied to link in /usr/local/bin
reload_bash
end
desc "Where to find the backup files"
task :uninstall do
puts "Your original files are safe as *.dotfiles-backup files."
puts "Searching for *.dotfiles-backup files:\n\n"
system %Q{ find ~ -name "*.dotfiles-backup" }
puts "\nJust remove the '.dotfiles-backup' extension and restart your terminal."
end
task :default => :help