forked from twerth/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall
executable file
·178 lines (148 loc) · 5.63 KB
/
install
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
#!/usr/bin/env ruby
# encoding: utf-8
require 'fileutils'
def colorize(text, color_code)
"#{color_code}#{text}\e[0m"
end
def red(text); colorize(text, "\e[31m"); end
def green(text); colorize(text, "\e[32m"); end
def yellow(text); colorize(text, "\e[33m"); end
def magenta(text); colorize(text, "\e[35m"); end
class Installer
attr_reader :options, :dotfiles
def initialize
@options = {
:dotfile_dest => File.expand_path("~/"),
:current_dir => File.dirname(File.expand_path(__FILE__))
}
@dotfiles = Dir[File.join(options[:current_dir], "etc", "*")]
end
def all
puts ' * Installing dotfiles, emacs config, zsh config and some utils to your system ...'
puts
installers.each do |installer|
method(installer).call
end
end
def installer_names
installers.map { |installer| installer.to_s.gsub(/install_/, '').to_sym }
end
def installers
methods.grep(/install_/)
end
def install_emacs
with_explanation('Configuring Emacs') do
unless File.exists?("./etc/emacs.d")
system "git clone -q --recursive https://github.com/syl20bnr/spacemacs etc/emacs.d"
end
link_dotfiles(dotfiles.grep(/spacemacs\Z|emacs\.d/))
Dir["etc/spacemacs-private/*"].each do |config_layer|
FileUtils.ln_sf(File.expand_path(config_layer), "etc/emacs.d/private/")
end
end
end
def install_dotfiles
with_explanation("Linking dotfiles found under etc/") do
link_dotfiles(dotfiles - dotfiles.grep(/zsh|emacs\.d/))
end
end
def install_zsh
with_explanation('Installing general zsh config') do
link_dotfiles(dotfiles.grep(/zsh/))
end
with_explanation('Installing zsh plugins') do
zsh_plugins = [
"git://github.com/zsh-users/zsh-syntax-highlighting.git",
"git://github.com/zsh-users/zsh-history-substring-search.git"
]
zsh_plugin_dir = File.join(File.dirname(__FILE__), "etc/zsh.d/plugins")
FileUtils.rm_rf(zsh_plugin_dir)
FileUtils.mkdir(zsh_plugin_dir)
zsh_plugins.each do |plugin|
puts " - Installing #{plugin_name = File.basename(plugin, ".git")} to #{zsh_plugin_dir} ..."
`git clone --quiet #{plugin} #{File.join(zsh_plugin_dir, plugin_name)}`
end
end
with_explanation('Installing zshuery') do
if File.exists?("#{ENV['HOME']}/.zshuery")
`cd ~/.zshuery; git reset --quiet --hard; git pull --quiet origin master`
else
`git clone https://github.com/myfreeweb/zshuery.git ~/.zshuery`
end
`cd ~/.zshuery; git submodule --quiet update --init`
end
end
def link_dotfiles(files)
files.each do |dotfile|
puts " - '#{dotfile}' to '#{options[:dotfile_dest]}' ..."
unless File.exists?(target = File.join(options[:dotfile_dest], ".#{File.basename(dotfile)}"))
FileUtils.ln_s(dotfile, target)
end
end
end
def install_gitconfig
with_explanation('Setting some general git configs') do
git_configs = [
{:key => "color.ui", :value => "auto"},
{:key => "alias.br", :value => "branch"},
{:key => "alias.st", :value => "status -sb"},
{:key => "alias.ci", :value => "commit -m"},
{:key => "alias.ca", :value => "commit -a -m"},
{:key => "alias.co", :value => "checkout"},
{:key => "alias.lg", :value => "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"},
{:key => "alias.unmerged", :value => %Q{!git branch -r --no-merged | grep -v HEAD | xargs -L1 git --no-pager log --pretty=tformat:'%Cgreen%d%Creset | %h | %an | %Cblue%ar%Creset' -1 | column -t -s '|'}},
{:key => "alias.merged", :value => %{!git branch -r --merged | grep -v HEAD | xargs -L1 git --no-pager log --pretty=tformat:'%Cgreen%d%Creset | %h | %an | %Cblue%ar%Creset' -1 | column -t -s '|'}},
{:key => "alias.prune-all", :value => %Q{!git remote | xargs -n 1 git remote prune} },
{:key => "merge.tool", :value => "opendiff"},
{:key => "merge.summary", :value => "true"},
{:key => "push.default", :value => "simple"},
{:key => "core.repositoryformatversion", :value => "0"},
{:key => "core.filemode", :value => "true"},
{:key => "core.bare", :value => "false"},
{:key => "core.pager", :value => "less -R"},
{:key => "core.logallrefupdates", :value => "true"},
{:key => "branch.autosetuprebase", :value => "always"},
{:key => "branch.master.remote", :value => "origin"},
{:key => "branch.master.merge", :value => "refs/heads/master"},
{:key => "i18n.commitEncoding", :value => "utf-8"},
{:key => "log.date", :value => "local"},
{:key => "core.excludesfile", :value => "~/.gitignore"},
]
git_configs.each do |git_config|
puts " - #{git_config[:key]} = #{git_config[:value]}"
system "git config --global --unset-all #{git_config[:key]}"
system %Q{git config --global --add #{git_config[:key]} "#{git_config[:value]}"}
end
end
end
def with_explanation(header, &block)
puts yellow(" > #{header} ...")
yield
puts green(" ✔ OK!")
puts
end
end
puts
puts
puts magenta(" *** DOTFILES INSTALLATION ***")
puts
installer = Installer.new
install_command = ARGV.first || "help"
case install_command.to_sym
when :all
installer.all
when *installer.installer_names
installer.send("install_#{install_command}")
else
puts
puts <<-TXT
Please choose one of the following installers: all, #{installer.installer_names.join(', ')}
TXT
puts
puts red(" ✘ Failed!")
puts
exit(1)
end
puts
puts green(">>>> Everything is done. Enjoy! <<<<<")
puts