-
Notifications
You must be signed in to change notification settings - Fork 4
/
Rakefile
209 lines (187 loc) · 5.21 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
201
202
203
204
205
206
207
208
209
SRC_DIR = File.dirname(File.expand_path(__FILE__))
ZINIT_DIR = File.join(ENV['HOME'], '.zinit')
ZGEN_DIR = File.join(ENV['HOME'], '.zsh/zgen')
DOTFILES_SRCS = %w[
.bashrc
.config
.ctags.d
.dir_colors
.finicky.js
.gitattributes_global
.gitconfig
.gitignore_global
.globalrc
.hammerspoon
.tigrc
.tmux.conf
.vim
.vimrc
.zsh
.zshenv
.zshrc
].freeze
namespace :dotfiles do
desc 'Install dotfiles'
task install: DOTFILES_SRCS do |t|
t.prerequisites.each do |prereq|
src = File.join(SRC_DIR, prereq)
dest = File.join(ENV['HOME'], prereq)
sh "\\rm -rf #{dest}"
sh "ln -sfn #{src} #{dest}"
end
end
end
namespace :zsh do
namespace :zinit do
# @see https://github.com/zdharma/zinit/blob/master/doc/install.sh
desc 'Install zinit'
task :install do
begin
FileUtils.mkdir(ZINIT_DIR)
puts ">>> Downloading zinit to #{ZINIT_DIR}/bin"
sh "cd #{ZINIT_DIR}; git clone --depth 10 https://github.com/zdharma-continuum/zinit.git bin"
puts '>>> Done'
rescue Errno::EEXIST => _
puts 'Zinit directory already exists'
exit 1
end
end
desc 'Uninstall zinit'
task :uninstall do
begin
FileUtils.rm_r(ZINIT_DIR)
puts "Remove directory #{ZINIT_DIR}"
rescue Errno::ENOENT => _
puts "#{ZINIT_DIR} does not exist"
exit 1
end
end
end
end
namespace :tmux do
desc 'Enable italic'
task install: '.tmux/tmux-256color.terminfo' do |t|
sh 'tic -x .tmux/tmux-256color.terminfo'
end
end
namespace :gem do
desc 'Install gem'
task install: 'GemGlobal' do
packages = File.readlines('GemGlobal').map(&:chomp).join(' ')
sh "gem install #{packages}"
end
desc 'Uninstall gem'
task :uninstall do
sh 'gem uninstall --all --ignore-dependencies --executables $(gem list | grep -v "default" | awk "{print $1}")'
sh 'gem install rake bundler'
end
end
namespace :pip do
desc 'Install pip'
task install: 'PipGlobal' do
sh 'pip install setuptools'
sh 'pip install pip --upgrade'
sh 'pip list --outdated --format=legacy | cut -d" " -f1 | xargs pip install --upgrade'
File.readlines('PipGlobal').map(&:chomp).each do |package|
system "pip install #{package} --upgrade"
end
end
desc 'Uninstall pip'
task :uninstall do
pip3file = '/tmp/piplist3.txt'
system "pip3 freeze > #{pip3file} && test -f #{pip3file} && yes | pip3 uninstall -r #{pip3file} && rm #{pip3file}"
end
end
namespace :npm do
desc 'Install node modules'
task install: 'NpmGlobal' do
packages = File.readlines('NpmGlobal').map(&:chomp).join(' ')
sh "yarn global add #{packages}"
end
desc 'Uninstall node modules'
task :uninstall do
sh "rm -rf #{`yarn global dir`}"
end
desc 'Upgrade node modules'
task :upgrade do
sh 'yarn global upgrade'
end
end
namespace :brew do
desc 'Install homebrew packages'
task bundle: 'Brewfile' do
package = File.readlines('Brewfile').map(&:chomp).select do |line|
!line.empty? && line[0] != '#'
end
package.each do |line|
sh "brew #{line}"
end
end
desc 'Install homebrew cask packages'
task cask: 'Caskfile' do
app = File.readlines('Caskfile').map(&:chomp).select do |line|
!line.empty? && line[0] != '#'
end
app.each do |line|
sh "brew #{line}"
end
end
end
namespace :mas do
desc 'Install AppStore packages'
task install: 'Masfile' do
# MasfileからアプリのIDを抽出
apps = File.readlines('Masfile').map(&:chomp).select do |line|
!line.empty? && line[0] != '#'
end
apps = apps.map do |app|
app.split(' ')[1]
end
# インストール済みのアプリを抽出
installed_app = `mas list`.split("\n").map { |app| app.split(' ')[0] }
install_app = apps - installed_app
install_app.map do |app|
sh "mas install #{app}"
end
end
end
# namespace :vscode do
# desc 'Override vscode settings file'
# task settings: ['.config/vscode/settings.json', '.config/vscode/keybindings.json', '.config/vscode/locale.json'] do
# config_root = '~/Library/Application\ Support/Code/User'
# sh "ln -sfn ~/.config/vscode/settings.json #{config_root}/settings.json"
# sh "ln -sfn ~/.config/vscode/keybindings.json #{config_root}/keybindings.json"
# sh "ln -sfn ~/.config/vscode/locale.json #{config_root}/locale.json"
# end
#
# desc 'Install extensions'
# task extension: 'Codefile' do
# File.readlines('Codefile').map(&:chomp).each do |extension|
# sh "code --install-extension #{extension}"
# end
# end
#
# desc 'Export extensions'
# task :export_extension do
# File.write('Codefile', `code --list-extensions`)
# end
# end
namespace :coteditor do
desc 'Integrate command line with citeditor'
task :install do
sh 'ln -sfn /Applications/CotEditor.app/Contents/SharedSupport/bin/cot /usr/local/bin/cot'
end
desc 'Delete cot command'
task :uninstall do
sh 'rm /usr/local/bin/cot'
end
end
namespace :vagrant do
desc 'Install vagrant plugins'
task plugins: 'VagrantPlugins' do
sh 'vagrant plugin update'
File.readlines('VagrantPlugins').map(&:chomp).each do |plugin|
sh "vagrant plugin install #{plugin}"
end
end
end