-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
200 lines (158 loc) · 4.78 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
require "fileutils"
require "open-uri"
require "rbconfig"
require "shellwords"
Dir.chdir File.expand_path(__dir__)
def dep(exec, shell = "command -v #{exec} > /dev/null")
deps = ENV.key?("deps") ? ENV["deps"].split(",") : [/.*/]
return if deps.none? { |pat| pat === exec }
sh(shell) do |ok, status|
if !ok || ENV.fetch("force", "").split(",").include?(exec)
block_given? ? yield : exit(status.exitstatus)
end
end
end
def target_dirs(&block)
ENV.fetch("dirs", "*/")
.split(",")
.flat_map { |dir| Dir.glob(dir) }
.uniq
.each(&block)
end
def local_bin(executable)
dir = File.join(Dir.home, ".local/bin")
exe = File.join(dir, executable)
FileUtils.mkdir_p(dir)
yield exe
FileUtils.chmod("+x", exe)
end
desc "Setup dependencies"
task :setup do
case RbConfig::CONFIG["host_os"]
when /(darwin|mac os)/
dep("keyboard", "test `defaults -currentHost read -g KeyRepeat` = 1") do
sh "defaults -currentHost write -g InitialKeyRepeat -int 15"
sh "defaults -currentHost write -g KeyRepeat -int 1"
sh "defaults -currentHost write -g ApplePressAndHoldEnabled -bool false"
end
dep("brew") do
URI.open("https://raw.githubusercontent.com/Homebrew/install/master/install.sh") do |io|
sh "bash", "-c", io.read
end
end
dep("git") do
sh "brew install git"
end
dep("stow") do
sh "brew install stow"
end
dep("htop") do
sh "brew install htop"
end
dep("tmux") do
sh "brew install tmux"
end
dep("xcode-select", "xcode-select --print-path > /dev/null") do
sh "xcode-select --install"
end
dep("nvim") do
sh "brew install neovim"
end
dep("bash completion", "test -f $(brew --prefix)/etc/bash_completion") do
sh "brew install bash-completion"
end
dep("kitty") do
sh "brew install kitty --cask"
end
dep("go") do
sh "brew install go"
end
dep("ripgrep", "command -v rg > /dev/null") do
sh "brew install ripgrep"
end
dep("coreutils", "brew leaves -r | fgrep -xq coreutils") do
sh "brew install coreutils"
end
when /linux/
dep("apt-get", "sudo apt-get update")
dep("git") do
sh "sudo apt-get -y install git-core"
end
dep("stow") do
sh "sudo apt-get -y install stow"
end
dep("htop") do
sh "sudo apt-get -y install htop"
end
dep("tmux") do
sh "sudo apt-get -y install libevent-dev libncurses5-dev"
sh "curl -L https://github.com/tmux/tmux/releases/download/2.8/tmux-2.8.tar.gz | " \
"sudo tar xvz -C /usr/local/src"
Dir.chdir("/usr/local/src/tmux-2.8") do
sh "sudo bash -c './configure && make && make install'"
end
end
dep("nvim") do
sh "sudo apt-get install neovim"
end
dep("go") do
sh "curl -L https://golang.org/dl/go1.16.3.linux-amd64.tar.gz | " \
"sudo tar xvz -C /usr/local"
end
dep("ripgrep", "command -v rg > /dev/null") do
URI.open("https://github.com/BurntSushi/ripgrep/releases/download/12.1.1/ripgrep_12.1.1_amd64.deb") do |io|
IO.copy_stream(io, "/tmp/ripgrep.deb")
io.flush
end
sh "sudo dpkg -i /tmp/ripgrep.deb"
end
else
abort "Don't know how to install on this platform."
end
dep("rbenv", "test -d ~/.rbenv && git -C ~/.rbenv pull") do
sh "git clone https://github.com/sstephenson/rbenv.git ~/.rbenv"
end
dep("ruby-build", "test -d ~/.rbenv/plugins/ruby-build && git -C ~/.rbenv/plugins/ruby-build pull") do
sh "git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build"
end
dep("ruby", "~/.rbenv/bin/rbenv versions | fgrep -q 3.1") do
sh "~/.rbenv/bin/rbenv install 3.1.2 && ~/.rbenv/bin/rbenv global 3.1.2"
end
dep("bundler") do
sh "~/.rbenv/shims/gem install bundler"
end
dep("vim plugins", "nvim -e +PlugInstall! +qa!") do
warn "Failed to install nvim plugins"
end
dep("rust", "command -v rustc > /dev/null") do
sh "curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs " \
"| sh -s -- -y --no-modify-path -c rust-src"
end
dep("rust-analyzer") do
sh "rustup component add rust-analyzer"
end
dep("gopls") do
sh "PATH=$PATH:/usr/local/go/bin GO111MODULE=on go install golang.org/x/tools/gopls@latest"
end
end
desc "Symlink files into $HOME"
task :link do
target_dirs do |dir|
sh "stow -t ~ --ignore='.*\\.gitkeep' #{dir.shellescape}"
end
end
desc "Remove symlinks from $HOME"
task :unlink do
target_dirs do |dir|
sh "stow -t ~ -D #{dir.shellescape}"
end
end
desc "Cleanup installed vim plugins"
task :cleanup do
sh "rm -vrf ~/.vim/plugged"
end
desc "Install dependencies and dotfiles"
task install: [:setup, :link]
desc "Uninstall dotfiles and cleanup"
task uninstall: [:unlink, :cleanup]
task default: :install