forked from campuscode/cc_dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
132 lines (111 loc) · 3.28 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
require 'rake'
desc 'Install Campus Code Dotfile in your machine'
task :install do
puts "Thank you for choose Campus Code Dotfiles (cc_dotfiles)"
install_files(Dir.glob([
"aliases",
"tmux.conf",
"vimrc",
"zsh",
"zshenv",
"zshrc",
"bin",
"vim",
"git/*",
"irb/*"
]))
install_prereqs
install_fonts
install_vim_plugins
install_zsh_zinit
install_tmux_battery_plugin
tmux_copy_mode
add_vimrc_local
change_shell
installation_message
end
private
def cc_dotfiles_folder
"$HOME/.cc_dotfiles"
end
def install_vim_plugins
system "vim -N \"+set hidden\" \"+syntax on\" +PlugInstall +qall"
end
def change_shell
puts "You will change your default shell to zsh"
run_command %{ chsh -s $(which zsh) }
end
def install_zsh_zinit
puts "Install zinit"
system "bash -c \"$(curl --fail --show-error --silent --location https://raw.githubusercontent.com/zdharma-continuum/zinit/HEAD/scripts/install.sh)\""
file = "#{ENV["HOME"]}/.zshrc"
system "cat #{cc_dotfiles_folder}/zsh/zinit_plugins >> #{file}"
end
def tmux_copy_mode
folder = cc_dotfiles_folder
run_command %{ cp #{folder}/templates/copy_mode_mac.conf.tmp $HOME/.tmux_copy_mode.conf } if macos?
run_command %{ cp #{folder}/templates/copy_mode_linux.conf.tmp $HOME/.tmux_copy_mode.conf } if linux?
end
def add_vimrc_local
run_command %{ cp #{cc_dotfiles_folder}/templates/vimrc.local.tmp $HOME/.vimrc.local }
end
def install_tmux_battery_plugin
folder = '.tmux-battery'
unless File.exists?("#{ENV["HOME"]}/#{folder}")
run_command %{ git clone --depth=1 https://github.com/tmux-plugins/tmux-battery $HOME/#{folder} }
run_command %{ echo "run-shell $HOME/#{folder}/battery.tmux" >> $HOME/.tmux.conf.local }
end
end
def install_files(files)
files.each do |f|
file_name = f.split('/').last
source = "#{ENV["PWD"]}/#{f}"
file = "#{ENV["HOME"]}/.#{file_name}"
if File.exists?(file)
puts "Moving #{file} to #{file}.bkp"
run_command %{ mv #{file} #{file}.bkp }
end
run_command %{ ln -nfs "#{source}" "#{file}" }
end
end
def install_fonts
puts "======================================================"
puts "Installing patched fonts for Powerline/Lightline."
puts "======================================================"
run_command %{ cp -f $HOME/.cc_dotfiles/fonts/* $HOME/Library/Fonts } if macos?
run_command %{ mkdir -p ~/.fonts && cp ~/.cc_dotfiles/fonts/* ~/.fonts && fc-cache -vf ~/.fonts } if linux?
puts
end
def run_command(cmd)
puts "running #{cmd}"
system cmd
rescue
puts "Error running #{cmd}"
end
def macos?
RUBY_PLATFORM.downcase.include?("darwin")
end
def linux?
RUBY_PLATFORM.downcase.include?("linux")
end
def linux_message
puts ''
puts "- Change your terminal window to Run command as login shell and RESTART"
puts ''
puts "- You can find more information about this on \r
https://github.com/rvm/ubuntu_rvm"
end
def installation_message
puts ''
puts ''
puts '======================================================================='
puts 'Thank you!'
puts ''
puts ''
linux_message if linux?
puts '======================================================================='
end
def install_prereqs
run_command %{ $HOME/.cc_dotfiles/mac.sh } if macos?
run_command %{ $HOME/.cc_dotfiles/ubuntu.sh } if linux?
end