Fri, 22 Jan 2016 17:44:49 -0500
Add some zsh options
94
51ca19919894
Try to make setup easier, unify shell environments
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
1 | #!/usr/bin/env ruby |
51ca19919894
Try to make setup easier, unify shell environments
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
2 | # vim: et sts=2 sw=2 fdm=marker |
51ca19919894
Try to make setup easier, unify shell environments
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
3 | |
136
b634c40e658b
Update, got omz files in right place
Meredith Howard <mhoward@roomag.org>
parents:
96
diff
changeset
|
4 | # we don't yet have rbenv so keep safe for ruby 1.9 |
94
51ca19919894
Try to make setup easier, unify shell environments
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
5 | |
152
69896d410e89
add easy update option for stuff that's git-based
Meredith Howard <mhoward@roomag.org>
parents:
136
diff
changeset
|
6 | require 'getoptlong' |
69896d410e89
add easy update option for stuff that's git-based
Meredith Howard <mhoward@roomag.org>
parents:
136
diff
changeset
|
7 | |
94
51ca19919894
Try to make setup easier, unify shell environments
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
8 | if `which git` == '' |
51ca19919894
Try to make setup easier, unify shell environments
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
9 | puts "please install git" |
51ca19919894
Try to make setup easier, unify shell environments
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
10 | exit 1 |
51ca19919894
Try to make setup easier, unify shell environments
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
11 | end |
51ca19919894
Try to make setup easier, unify shell environments
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
12 | |
152
69896d410e89
add easy update option for stuff that's git-based
Meredith Howard <mhoward@roomag.org>
parents:
136
diff
changeset
|
13 | def main |
160 | 14 | if ARGV.length == 0 |
15 | ARGV << '--help' | |
16 | end | |
17 | ||
152
69896d410e89
add easy update option for stuff that's git-based
Meredith Howard <mhoward@roomag.org>
parents:
136
diff
changeset
|
18 | opts = GetoptLong.new( |
69896d410e89
add easy update option for stuff that's git-based
Meredith Howard <mhoward@roomag.org>
parents:
136
diff
changeset
|
19 | [ '--help', '-h', GetoptLong::NO_ARGUMENT ], |
69896d410e89
add easy update option for stuff that's git-based
Meredith Howard <mhoward@roomag.org>
parents:
136
diff
changeset
|
20 | [ '--update', '-u', GetoptLong::NO_ARGUMENT ], |
69896d410e89
add easy update option for stuff that's git-based
Meredith Howard <mhoward@roomag.org>
parents:
136
diff
changeset
|
21 | [ '--setup', '-s', GetoptLong::NO_ARGUMENT ], |
69896d410e89
add easy update option for stuff that's git-based
Meredith Howard <mhoward@roomag.org>
parents:
136
diff
changeset
|
22 | ); |
69896d410e89
add easy update option for stuff that's git-based
Meredith Howard <mhoward@roomag.org>
parents:
136
diff
changeset
|
23 | |
184
ddb5e993a367
Handle all passed options, chdir to bindir
Meredith Howard <mhoward@roomag.org>
parents:
160
diff
changeset
|
24 | Dir.chdir( |
ddb5e993a367
Handle all passed options, chdir to bindir
Meredith Howard <mhoward@roomag.org>
parents:
160
diff
changeset
|
25 | File.dirname File.expand_path $0 |
ddb5e993a367
Handle all passed options, chdir to bindir
Meredith Howard <mhoward@roomag.org>
parents:
160
diff
changeset
|
26 | ) |
ddb5e993a367
Handle all passed options, chdir to bindir
Meredith Howard <mhoward@roomag.org>
parents:
160
diff
changeset
|
27 | |
ddb5e993a367
Handle all passed options, chdir to bindir
Meredith Howard <mhoward@roomag.org>
parents:
160
diff
changeset
|
28 | opts.each do |opt, arg| |
ddb5e993a367
Handle all passed options, chdir to bindir
Meredith Howard <mhoward@roomag.org>
parents:
160
diff
changeset
|
29 | case opt |
ddb5e993a367
Handle all passed options, chdir to bindir
Meredith Howard <mhoward@roomag.org>
parents:
160
diff
changeset
|
30 | when '--help' |
ddb5e993a367
Handle all passed options, chdir to bindir
Meredith Howard <mhoward@roomag.org>
parents:
160
diff
changeset
|
31 | puts <<-ENDHELP.sub(/^\s+/,'') |
ddb5e993a367
Handle all passed options, chdir to bindir
Meredith Howard <mhoward@roomag.org>
parents:
160
diff
changeset
|
32 | #{$0} usage: |
ddb5e993a367
Handle all passed options, chdir to bindir
Meredith Howard <mhoward@roomag.org>
parents:
160
diff
changeset
|
33 | -h --help This help message |
ddb5e993a367
Handle all passed options, chdir to bindir
Meredith Howard <mhoward@roomag.org>
parents:
160
diff
changeset
|
34 | -s --setup Perform home directory setup (git clone) |
ddb5e993a367
Handle all passed options, chdir to bindir
Meredith Howard <mhoward@roomag.org>
parents:
160
diff
changeset
|
35 | -u --update Update git stuff (git pull) |
ddb5e993a367
Handle all passed options, chdir to bindir
Meredith Howard <mhoward@roomag.org>
parents:
160
diff
changeset
|
36 | ENDHELP |
ddb5e993a367
Handle all passed options, chdir to bindir
Meredith Howard <mhoward@roomag.org>
parents:
160
diff
changeset
|
37 | exit 1 |
ddb5e993a367
Handle all passed options, chdir to bindir
Meredith Howard <mhoward@roomag.org>
parents:
160
diff
changeset
|
38 | when '--setup' |
ddb5e993a367
Handle all passed options, chdir to bindir
Meredith Howard <mhoward@roomag.org>
parents:
160
diff
changeset
|
39 | setup |
ddb5e993a367
Handle all passed options, chdir to bindir
Meredith Howard <mhoward@roomag.org>
parents:
160
diff
changeset
|
40 | when '--update' |
ddb5e993a367
Handle all passed options, chdir to bindir
Meredith Howard <mhoward@roomag.org>
parents:
160
diff
changeset
|
41 | update |
ddb5e993a367
Handle all passed options, chdir to bindir
Meredith Howard <mhoward@roomag.org>
parents:
160
diff
changeset
|
42 | end |
152
69896d410e89
add easy update option for stuff that's git-based
Meredith Howard <mhoward@roomag.org>
parents:
136
diff
changeset
|
43 | end |
69896d410e89
add easy update option for stuff that's git-based
Meredith Howard <mhoward@roomag.org>
parents:
136
diff
changeset
|
44 | end |
94
51ca19919894
Try to make setup easier, unify shell environments
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
45 | |
136
b634c40e658b
Update, got omz files in right place
Meredith Howard <mhoward@roomag.org>
parents:
96
diff
changeset
|
46 | # just checks and bails after each call, output already in STDERR |
96 | 47 | def do_cmds (*cmds) |
48 | cmds.each do |cmd| | |
49 | puts "$ #{cmd}" | |
50 | system( cmd ) or exit $? | |
94
51ca19919894
Try to make setup easier, unify shell environments
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
51 | end |
96 | 52 | end |
94
51ca19919894
Try to make setup easier, unify shell environments
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
53 | |
51ca19919894
Try to make setup easier, unify shell environments
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
54 | |
152
69896d410e89
add easy update option for stuff that's git-based
Meredith Howard <mhoward@roomag.org>
parents:
136
diff
changeset
|
55 | def setup |
241 | 56 | # zgen {{{ |
57 | if Dir.exists?('.zgen') | |
58 | puts "zgen already installed" | |
152
69896d410e89
add easy update option for stuff that's git-based
Meredith Howard <mhoward@roomag.org>
parents:
136
diff
changeset
|
59 | else |
241 | 60 | puts "Installing zgen..." |
152
69896d410e89
add easy update option for stuff that's git-based
Meredith Howard <mhoward@roomag.org>
parents:
136
diff
changeset
|
61 | |
69896d410e89
add easy update option for stuff that's git-based
Meredith Howard <mhoward@roomag.org>
parents:
136
diff
changeset
|
62 | do_cmds \ |
241 | 63 | 'git clone https://github.com/tarjoilija/zgen.git .zgen' |
152
69896d410e89
add easy update option for stuff that's git-based
Meredith Howard <mhoward@roomag.org>
parents:
136
diff
changeset
|
64 | end |
69896d410e89
add easy update option for stuff that's git-based
Meredith Howard <mhoward@roomag.org>
parents:
136
diff
changeset
|
65 | # }}} |
69896d410e89
add easy update option for stuff that's git-based
Meredith Howard <mhoward@roomag.org>
parents:
136
diff
changeset
|
66 | |
69896d410e89
add easy update option for stuff that's git-based
Meredith Howard <mhoward@roomag.org>
parents:
136
diff
changeset
|
67 | # plenv {{{ |
69896d410e89
add easy update option for stuff that's git-based
Meredith Howard <mhoward@roomag.org>
parents:
136
diff
changeset
|
68 | if Dir.exists?('.plenv') |
69896d410e89
add easy update option for stuff that's git-based
Meredith Howard <mhoward@roomag.org>
parents:
136
diff
changeset
|
69 | puts "plenv already installed" |
69896d410e89
add easy update option for stuff that's git-based
Meredith Howard <mhoward@roomag.org>
parents:
136
diff
changeset
|
70 | else |
69896d410e89
add easy update option for stuff that's git-based
Meredith Howard <mhoward@roomag.org>
parents:
136
diff
changeset
|
71 | puts "Installing plenv..." |
94
51ca19919894
Try to make setup easier, unify shell environments
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
72 | |
152
69896d410e89
add easy update option for stuff that's git-based
Meredith Howard <mhoward@roomag.org>
parents:
136
diff
changeset
|
73 | do_cmds \ |
241 | 74 | 'git clone https://github.com/tokuhirom/plenv.git .plenv', |
75 | 'git clone https://github.com/tokuhirom/Perl-Build.git .plenv/plugins/perl-build/' | |
152
69896d410e89
add easy update option for stuff that's git-based
Meredith Howard <mhoward@roomag.org>
parents:
136
diff
changeset
|
76 | end |
69896d410e89
add easy update option for stuff that's git-based
Meredith Howard <mhoward@roomag.org>
parents:
136
diff
changeset
|
77 | # }}} |
94
51ca19919894
Try to make setup easier, unify shell environments
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
78 | |
152
69896d410e89
add easy update option for stuff that's git-based
Meredith Howard <mhoward@roomag.org>
parents:
136
diff
changeset
|
79 | # rbenv {{{ |
69896d410e89
add easy update option for stuff that's git-based
Meredith Howard <mhoward@roomag.org>
parents:
136
diff
changeset
|
80 | if Dir.exists?('.rbenv') |
69896d410e89
add easy update option for stuff that's git-based
Meredith Howard <mhoward@roomag.org>
parents:
136
diff
changeset
|
81 | puts "rbenv already installed" |
69896d410e89
add easy update option for stuff that's git-based
Meredith Howard <mhoward@roomag.org>
parents:
136
diff
changeset
|
82 | else |
69896d410e89
add easy update option for stuff that's git-based
Meredith Howard <mhoward@roomag.org>
parents:
136
diff
changeset
|
83 | puts "Installing rbenv..." |
94
51ca19919894
Try to make setup easier, unify shell environments
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
84 | |
152
69896d410e89
add easy update option for stuff that's git-based
Meredith Howard <mhoward@roomag.org>
parents:
136
diff
changeset
|
85 | do_cmds \ |
69896d410e89
add easy update option for stuff that's git-based
Meredith Howard <mhoward@roomag.org>
parents:
136
diff
changeset
|
86 | 'git clone https://github.com/sstephenson/rbenv.git .rbenv', |
69896d410e89
add easy update option for stuff that's git-based
Meredith Howard <mhoward@roomag.org>
parents:
136
diff
changeset
|
87 | 'git clone https://github.com/sstephenson/ruby-build.git .rbenv/plugins/ruby-build/' |
69896d410e89
add easy update option for stuff that's git-based
Meredith Howard <mhoward@roomag.org>
parents:
136
diff
changeset
|
88 | end |
69896d410e89
add easy update option for stuff that's git-based
Meredith Howard <mhoward@roomag.org>
parents:
136
diff
changeset
|
89 | # }}} |
94
51ca19919894
Try to make setup easier, unify shell environments
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
90 | |
213 | 91 | # ndenv {{{ |
92 | if Dir.exists?('.ndenv') | |
93 | puts "ndenv already installed" | |
94 | else | |
95 | puts "Installing ndenv..." | |
96 | ||
97 | do_cmds \ | |
98 | 'git clone https://github.com/riywo/ndenv.git .ndenv', | |
99 | 'git clone https://github.com/riywo/node-build.git .ndenv/plugins/node-build' | |
100 | end | |
101 | # }}} | |
152
69896d410e89
add easy update option for stuff that's git-based
Meredith Howard <mhoward@roomag.org>
parents:
136
diff
changeset
|
102 | end |
69896d410e89
add easy update option for stuff that's git-based
Meredith Howard <mhoward@roomag.org>
parents:
136
diff
changeset
|
103 | |
69896d410e89
add easy update option for stuff that's git-based
Meredith Howard <mhoward@roomag.org>
parents:
136
diff
changeset
|
104 | def update |
241 | 105 | [ '.zgen', |
152
69896d410e89
add easy update option for stuff that's git-based
Meredith Howard <mhoward@roomag.org>
parents:
136
diff
changeset
|
106 | '.plenv', |
69896d410e89
add easy update option for stuff that's git-based
Meredith Howard <mhoward@roomag.org>
parents:
136
diff
changeset
|
107 | '.plenv/plugins/perl-build', |
69896d410e89
add easy update option for stuff that's git-based
Meredith Howard <mhoward@roomag.org>
parents:
136
diff
changeset
|
108 | '.rbenv', |
69896d410e89
add easy update option for stuff that's git-based
Meredith Howard <mhoward@roomag.org>
parents:
136
diff
changeset
|
109 | '.rbenv/plugins/ruby-build', |
213 | 110 | '.ndenv', |
111 | '.ndenv/plugins/node-build', | |
152
69896d410e89
add easy update option for stuff that's git-based
Meredith Howard <mhoward@roomag.org>
parents:
136
diff
changeset
|
112 | ].each do |dir| |
69896d410e89
add easy update option for stuff that's git-based
Meredith Howard <mhoward@roomag.org>
parents:
136
diff
changeset
|
113 | do_cmds \ |
185
4e227517a5cd
chdir not actually available everywhere
Meredith Howard <mhoward@roomag.org>
parents:
184
diff
changeset
|
114 | "cd ~/#{dir} && git pull origin master" |
94
51ca19919894
Try to make setup easier, unify shell environments
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
115 | end |
152
69896d410e89
add easy update option for stuff that's git-based
Meredith Howard <mhoward@roomag.org>
parents:
136
diff
changeset
|
116 | end |
94
51ca19919894
Try to make setup easier, unify shell environments
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
117 | |
152
69896d410e89
add easy update option for stuff that's git-based
Meredith Howard <mhoward@roomag.org>
parents:
136
diff
changeset
|
118 | main |
136
b634c40e658b
Update, got omz files in right place
Meredith Howard <mhoward@roomag.org>
parents:
96
diff
changeset
|
119 |