forked from pickhardt/betty
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.rb
executable file
·51 lines (40 loc) · 1.43 KB
/
install.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
#!/usr/bin/env ruby
require 'readline'
def ask(prompt="", newline=false)
prompt += "\n" if newline
Readline.readline(prompt, true).squeeze(" ").strip
end
INSTALL_LOC = Dir.home + '/betty/'
if Dir.exist? INSTALL_LOC
puts "Warning: ~/betty already exists!"
end
puts "We will install to ~/betty and put an alias in your .<shell>rc. Hit <enter> or 'y' if this is okay."
STDOUT.flush
CONTINUE = ask "> "
if CONTINUE == "" || CONTINUE == "y"
# copy to ~/betty/
if Dir.exist? INSTALL_LOC
# raise "~/betty already exists! Please manually remove if you want to proceed"
else
COPY_COMMAND = 'cp -rf ' + Dir.pwd + ' ' + INSTALL_LOC
print "Running `" + COPY_COMMAND + "`\n"
system COPY_COMMAND
end
begin
*junk, SHELL = `echo $SHELL`.split('/')
rescue Exception
SHELL="bash" #ruby 1.8 (parsing exceptions are not rescued by default)
end
bash_config = '.' + SHELL.chomp + 'rc'
bash_config = '.bash_profile' if RUBY_PLATFORM.match /darwin/ #and ... ?
SHELLRC = (Dir.home + '/' + bash_config ).chomp
print "Writing an alias called `betty` to " + SHELLRC + "\n"
open(SHELLRC, 'a') do |f|
f.puts "\n"
f.puts "######## Generated by Betty's install script"
f.puts "alias betty=\'#{ Dir.home }/betty/main.rb\'"
end
puts "add auto-complete by typing"
puts "complete -C #{INSTALL_LOC}autocomplete.rb betty"
`#{INSTALL_LOC}autocomplete.rb`
end