-
Notifications
You must be signed in to change notification settings - Fork 1
/
dotfiles
executable file
·135 lines (112 loc) · 3.74 KB
/
dotfiles
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
#! /usr/bin/env ruby
require 'yaml'
#### HELPERS
$repo = File.expand_path(File.join(__dir__, '../'))
$home = Dir.home
def load_config
config_file_yaml = File.join($repo, "config/local/vars.yaml")
vars = {}
if File.exist?(config_file_yaml)
vars = YAML.load_file(config_file_yaml)
end
return vars
end
def save_config(vars)
config_file_yaml = File.join($repo, "config/local/vars.yaml")
parent = File.join($repo, "config/local")
Dir.mkdir(parent) unless Dir.exists?(parent)
File.write(config_file_yaml, vars.to_yaml)
zsh_output = vars.map { |key, var| "export #{key}=\"#{var}\"" }.join("\n")
File.write(File.join($repo, "config/local/vars.zsh"), zsh_output)
fish_output = vars.map { |key, var| "set -gx #{key} #{var}" }.join("\n")
File.write(File.join($repo, "config/local/vars.fish"), fish_output)
git_output = "[user]\n name = #{vars['GIT_NAME']}\n email = #{vars['GIT_EMAIL']}\n"
File.write(File.join($home, ".gitconfig_local"), git_output) # TODO: move to config dir, but then gitconfig would depend on checkout location.
end
#### COMMANDS
def getBrew()
system('/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"')
end
def brewBundle()
brew_file = File.join($repo, "setup/Brewfile")
system("brew bundle install --file #{brew_file}")
end
def link()
file = File.join($repo, 'config/links.yaml')
yaml_file = YAML.load_file(file)
yaml_file['mkdirs-in-home'].each do |dir|
# ruby's mkdir isn't recursive
system("mkdir", "-p", File.join($home, dir))
end
yaml_file['links'].each do |link|
new_link = File.join($home, link['home'])
File.symlink(File.join($repo, link['repo']), new_link) unless File.exist?(new_link)
end
end
def prefs()
system(File.join($repo, "setup/dwrites.sh"))
system("killall Dock")
system("duti", File.join($repo, "setup/duti.conf"))
system("cat", File.join($repo, "setup/preferences.txt"))
end
def configure()
vars = load_config()
puts "The following config are local to this machine:"
if !vars['GIT_NAME']
print "Name (git ops): "
vars['GIT_NAME'] = STDIN.gets.chomp
end
if !vars['GIT_EMAIL']
print "Email (git ops): "
vars['GIT_EMAIL'] = STDIN.gets.chomp
end
if !vars['XCODE_APP']
print 'Xcode app name (ie "Xcode_12_0.app", must be in /Applications): '
vars['XCODE_APP'] = STDIN.gets.chomp
end
save_config(vars)
end
def fish()
system("sudo echo /opt/homebrew/bin/fish >> /etc/shells")
system("chsh -s /opt/homebrew/bin/fish")
end
def get_xcode_extension
if Dir.exist?("/Applications/XLineTool.app")
puts "-> Already installed, update manually if needed."
return
end
system("curl -L -o ~/Downloads/XLineTool.zip https://github.com/p3l6/XLineTool/releases/latest/download/XLineTool.zip")
system("unzip ~/Downloads/XLineTool.zip -d /Applications/")
puts "Moved to applications. Open app to configure settings."
end
def help
puts "Dotfiles management and setup commands:"
puts " help: print this info"
puts " configure: queries and sets required shell variables"
puts " get-brew: install brew"
puts " bundle: install tools from brewfile"
puts " link: create symlinks"
puts " fish: set fish as default shell"
puts " prefs: load prefs from dwrites, duti conf, and print manual prefs"
puts " xlinetool: download and unpack xcode extension"
end
if ARGV.length == 0
help()
exit
end
ARGV.each do |f|
case f
when "help"; help
when "get-brew"; getBrew
when "bundle"; brewBundle
when "link"; link
when "prefs"; prefs
when "configure"; configure
when "fish"; fish
when "xlinetool"; get_xcode_extension
# TODO: move diff-brewfile here
else
puts "unknown command: #{f}. see help for more info"
exit!
end
end