-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththelayout.rb
171 lines (155 loc) · 4.85 KB
/
thelayout.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
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
#!/usr/bin/env ruby
# The Layout (thelayout.rb)
# This is a small utility for setting up the Bash and Vim environment
# Written by Tate Galbraith
# June 2017
require 'fileutils'
require 'colorize'
# Download Bash completion file to hidden home - don't overwrite
def download_bash_completion
`wget -nc -O ~/.git-completion.bash https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash`
`chmod 755 ~/.git-completion.bash`
end
# Download Bash prompt file to hidden home - don't overwrite
def download_bash_prompt
`wget -nc -O ~/.git-prompt.sh https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh`
`chmod 755 ~/.git-prompt.sh`
end
# Download Vim theme - don't overwrite
def download_vim_theme
`wget -nc -O ~/.vim/colors/cobalt.vim https://raw.githubusercontent.com/gkjgh/cobalt/master/colors/cobalt.vim`
end
# Download Vim Pathogen - don't overwrite
def download_pathogen
`wget -nc -O ~/.vim/autoload/pathogen.vim https://tpo.pe/pathogen.vim`
end
# Download Vim-Ruby
def download_vimruby
`wget -nc -O ~/.vim/bundle/master.zip https://github.com/vim-ruby/vim-ruby/archive/master.zip`
`unzip ~/.vim/bundle/master.zip -d ~/.vim/bundle`
`rm ~/.vim/bundle/master.zip`
`mv ~/.vim/bundle/vim-ruby-master ~/.vim/bundle/vim-ruby`
end
# Download OhMyZsh
def download_ohmyzsh
`sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"`
end
# Set the OhMyZsh theme
# Read in current .zshrc find config line and change
# Output to temp file then move into existing .zshrc
def install_ohmyzsh_theme
@theme = "muse"
@zshrc_path = File.expand_path("~/.zshrc")
@zshrc_temp_path = File.expand_path("~/.zshrc_temp")
@zshrc_temp_file = File.new(@zshrc_temp_path, "w+")
File.open(@zshrc_path, "r").readlines.each do |line|
if line.include?("ZSH_THEME=")
@zshrc_temp_file.puts line.split("=")[0] + "=" + "\"#{@theme}\""
else
@zshrc_temp_file.puts line
end
end
@zshrc_temp_file.close
FileUtils.mv(@zshrc_temp_path, @zshrc_path)
end
# Add OhMyZsh custom aliases
def install_ohmyzsh_aliases
@zshrc_path = File.expand_path("~/.zshrc")
@aliases = ["gg='git status'"]
@aliases.each do |entry|
`echo 'alias #{entry}' >> #{@zshrc_path}`
end
end
# Make pathogen directories
def install_pathogen
@autoload_dir = File.expand_path("~/.vim/autoload")
@bundle_dir = File.expand_path("~/.vim/bundle")
@pathogen = "pathogen.vim"
@old = "pathogen_old.vim"
if !Dir.exists? @autoload_dir then FileUtils.mkdir(@autoload_dir) end
if !Dir.exists? @bundle_dir then FileUtils.mkdir(@bundle_dir) end
if File.file?("#{@autoload_dir}#{@pathogen}")
FileUtils.mv("#{@autoload_dir}#{@pathogen}", "#{@autoload_dir}#{@old}")
download_pathogen
else
download_pathogen
end
end
# Copy vim colorscheme to .vim/colors directory
def install_vim_theme
@destination = File.expand_path("~/.vim/colors")
if Dir.exists? @destination
download_vim_theme
else
FileUtils.mkdir(@destination)
download_vim_theme
end
end
# Prep Vim-Ruby directories and install
# Rename any existing vim-ruby install to old
def install_vimruby
@vimruby_dir = File.expand_path("~/.vim/bundle/vim-ruby")
@old = File.expand_path("~/.vim/bundle/vim-ruby_old")
if Dir.exists? @vimruby_dir
FileUtils.mv(@vimruby_dir, @old)
download_vimruby
else
download_vimruby
end
end
# Copy .vimrc config to home directory
# Rename any existing config to old
def install_vimrc
@source = ".vimrc"
@old = ".vimrc_old"
@destination = File.expand_path("~/")
if File.file?("#{@destination}#{@source}")
FileUtils.mv("#{@destination}#{@source}", "#{@destination}#{@old}")
FileUtils.cp(@source, @destination)
else
FileUtils.cp(@source, @destination)
end
end
# Copy .bash_profile to home directory
# Rename any existing config to old
def install_bash_profile
@source = ".bash_profile"
@old = ".bash_profile_old"
@destination = File.expand_path("~/")
if File.file?("#{@destination}#{@source}")
FileUtils.mv("#{@destination}#{@source}", "#{@destination}#{@old}")
FileUtils.cp(@source, @destination)
else
FileUtils.cp(@source, @destination)
end
end
# Call installations
# Check operating system
if RUBY_PLATFORM.include?("linux")
@os_version = "linux"
puts "Linux OS detected - proceeding with install...".green
download_bash_completion
download_bash_prompt
install_vimruby
install_pathogen
install_vim_theme
install_vimrc
install_bash_profile
download_ohmyzsh
install_ohmyzsh_theme
elsif RUBY_PLATFORM.include?("darwin")
@os_version = "mac"
puts "Mac OS detected - proceeding with install...".green
download_bash_completion
download_bash_prompt
install_vimruby
install_pathogen
install_vim_theme
install_vimrc
install_bash_profile
download_ohmyzsh
install_ohmyzsh_theme
else
puts "Operating System not supported!".red
exit(1)
end