forked from ethanis/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRakefile
More file actions
113 lines (93 loc) · 3.24 KB
/
Rakefile
File metadata and controls
113 lines (93 loc) · 3.24 KB
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
require 'rake'
require 'erb'
desc "install the dot files into user's home directory"
task :install do
replace_all = false
install_utilities
Dir['*'].each do |file|
next if %w[Rakefile Readme.md LICENSE].include? file
if File.exist?(File.join(ENV['HOME'], ".#{file.sub('.erb', '')}"))
if File.identical? file, File.join(ENV['HOME'], ".#{file.sub('.erb', '')}")
puts "identical ~/.#{file.sub('.erb', '')}"
elsif replace_all
replace_file(file)
else
print "overwrite ~/.#{file.sub('.erb', '')}? [ynaq] "
case $stdin.gets.chomp
when 'a'
replace_all = true
replace_file(file)
when 'y'
replace_file(file)
when 'q'
exit
else
puts "skipping ~/.#{file.sub('.erb', '')}"
end
end
else
link_file(file)
end
end
end
def install_utilities
install_homebrew
install_homebrew_utils
install_node
install_npm_packages
install_gems
install_dotnet
end
def install_homebrew
puts "Installing homebrew"
system('/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"', out: STDOUT) unless command_found?("brew")
end
def install_homebrew_utils
puts "Installing rbenv"
system('brew install rbenv', out: STDOUT) unless command_found?("rbenv")
puts "Installing thefuck"
system('brew install thefuck', out: STDOUT) unless command_found?("thefuck")
puts "Installing zsh-syntax-highlighting"
system('brew install zsh-syntax-highlighting', out: STDOUT) unless File.exist?("/usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh")
puts "Installing zsh-history-substring-search"
system('brew install zsh-history-substring-search', out: STDOUT) unless File.exist?("/usr/local/share/zsh-history-substring-search/zsh-history-substring-search.zsh")
end
def install_node
puts "Installing nvm"
system('curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash', out: STDOUT) unless File.exist?("/Users/ethanis/.nvm/nvm.sh")
puts "Installing node"
system('nvm install node', out: STDOUT) unless command_found?("node")
end
def install_npm_packages
puts "Installing spaceship-prompt"
system('npm install -g spaceship-prompt', out: STDOUT) unless command_found?("node")
end
def install_gems
puts "Installing colorls"
system('gem install colorls', out: STDOUT) unless command_found?("colorls")
end
def install_dotnet
puts "Installing dotnet dependencies"
system("brew install mono-libgdiplus") unless command_found?("dotnet")
puts "Installing dotnet sdk"
# installs LTS by default
system('curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin', out: STDOUT) unless command_found?("dotnet")
end
def command_found?(command)
system("which #{command} > /dev/null 2>&1")
end
def replace_file(file)
system %Q{rm -rf "$HOME/.#{file.sub('.erb', '')}"}
link_file(file)
end
def link_file(file)
if file =~ /.erb$/
puts "generating ~/.#{file.sub('.erb', '')}"
File.open(File.join(ENV['HOME'], ".#{file.sub('.erb', '')}"), 'w') do |new_file|
new_file.write ERB.new(File.read(file)).result(binding)
end
else
puts "linking ~/.#{file}"
system %Q{ln -s "$PWD/#{file}" "$HOME/.#{file}"}
end
end