-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrakefile.rb
64 lines (50 loc) · 1.84 KB
/
rakefile.rb
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
# frozen_string_literal: true
@dotfiles = %w[.gitconfig .gitignore_global .oh-my-zsh .zshrc .zsh_custom .dotfiles]
def file_exists_or_symlink(path)
File.exist?(path) || File.symlink?(path)
end
task init: %i[prepare_dotfiles prepare_home make_symlinks] do
puts "Done"
end
desc "Prepare dotfiles"
task :prepare_dotfiles do
puts "\nUpdate submodules"
sh "git submodule update --init --remote --force"
# Install vim-plug
sh "curl -fLo ~/.local/share/nvim/site/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim"
end
desc "Prepare home folder"
task :prepare_home do
home_path = File.expand_path("~")
puts "\nRemove dotfiles symbolik links"
@dotfiles.each do |dotfile|
dotfile_expanded_path = File.join home_path, dotfile
rm_r dotfile_expanded_path, verbose: true if file_exists_or_symlink(dotfile_expanded_path)
end
end
desc "Make symlinks of all files into home folder"
task :make_symlinks do
home_path = File.expand_path("~")
puts "\nCreate home symbolik links"
@dotfiles.each do |dotfile|
dotfile_expanded_path = File.expand_path(dotfile)
dest_dotfile_expanded_path = File.join home_path, dotfile
ln_s dotfile_expanded_path, dest_dotfile_expanded_path, verbose: true
end
dotfiles_home_path = File.join home_path, ".dotfiles"
puts "\nCreate applications symbolik links"
%w[
.config/nvim/init.lua
.config/nvim/coc-settings.json
.config/nvim/lua
.p10k.zsh
].each do |file|
file_path = File.join(home_path, *file.split("/"))
dotfiles_file_path = File.join(dotfiles_home_path, *file.delete_prefix(".").split("/"))
rm_r file_path, verbose: true if file_exists_or_symlink(file_path)
mkdir_p(File.dirname(file_path)) unless File.exist?(file_path)
ln_s dotfiles_file_path, file_path, verbose: true
end
end
task default: :init