-
Notifications
You must be signed in to change notification settings - Fork 2
/
Rakefile
130 lines (115 loc) · 3.13 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
require 'rake'
require 'erb'
task :default => [:install, :install_tools]
desc "install the dot files into user's home directory"
task :install do
replace_all = false
Dir['*'].each do |filename|
next if /Rakefile|README(?:.md|rdoc)|LICENSE/ =~ filename
pathname = File.join(Dir.home, ".#{filename.sub(/\.erb$/, '')}")
if File.exist?(pathname)
if File.identical?(filename, pathname)
puts "identical #{pathname}"
elsif replace_all
replace_file pathname, filename
else
print "overwrite #{pathname}? [ynaq] "
case $stdin.gets.chomp
when 'a'
replace_all = true
replace_file pathname, filename
when 'y'
replace_file pathname, filename
when 'q'
exit
else
puts "skipping #{pathname}"
end
end
else
install_file pathname, filename
end
end
end
desc "install common command-line tools"
task :install_tools => [:install_tmux, :install_macvim, :install_diff_so_fancy]
desc "install Homebrew"
task :install_homebrew do
sh <<~END
if [ `uname` == "Darwin" ] && ! [ -x "$(command -v brew)" ]; then
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
END
end
desc "install NPM using NVM"
task :install_npm do
sh <<~END
if [ -x "$(command -v nvm)" ]; then
nvm install --lts
fi
END
end
desc "install tmux"
task :install_tmux => [:install_homebrew] do
sh <<~END
if [ -x "$(command -v brew)" ]; then
brew install tmux
fi
END
end
desc "install macvim"
task :install_macvim => [:install_homebrew, :install_ag] do
sh <<~END
if [ -x "$(command -v brew)" ]; then
brew install macvim
fi
END
end
desc "install the Silver Searcher (ag)"
task :install_ag => [:install_homebrew] do
sh <<~END
if [ -x "$(command -v apt-get)" ]; then
sudo apt-get install silversearcher-ag
elif [ -x "$(command -v brew)" ]; then
brew install the_silver_searcher
fi
END
end
desc "install diff-so-fancy"
task :install_diff_so_fancy => [:install_npm] do
sh <<~END
if [ -x "$(command -v npm)" ]; then
npm install -g diff-so-fancy
else
echo WARNING: manually install NPM first before installing diff-so-fancy!
fi
END
end
desc "install Vim plugins through Vundle"
task :install_vim_plugins do
sh 'vim +PluginInstall +qall'
end
desc "install Oh My Zsh"
task :install_oh_my_zsh do
path = 'https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh'
sh %<sh -c "$(curl -fsSL #{path})">
end
desc "install ruby-build plugin for rbenv"
task :install_ruby_build do
`git clone [email protected]:sstephenson/ruby-build rbenv/plugins/ruby-build`
end
def replace_file(install_path, filename)
system "rm -rf '#{install_path}'"
install_file(install_path, filename)
end
def install_file(install_path, filename)
if filename =~ /\.erb$/
puts "generating #{install_path}"
open install_path, 'w' do |f|
f << ERB.new(File.read(filename)).result(binding)
end
else
puts "linking #{install_path}"
File.symlink File.join(Dir.pwd, filename), install_path
end
end