Method: Rip::Setup#setup_startup_script

Defined in:
lib/rip/setup.rb

#setup_startup_script(script = nil) ⇒ Object

Modifies the shell startup script(s) and inserts the Rip configuration statements.

Returns whether a startup script has been modified. If one of the startup scripts already contain the Rip configuration statements, then nothing will be modified and false will be returned.

TODO: Requires the startup script, but probably acceptable for most? –rue



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/rip/setup.rb', line 132

def setup_startup_script(script = nil)
  if script
    script = File.expand_path(script)
  else
    script = startup_script
  end

  if script.empty? || !File.exists?(script)
    ui.puts "rip: please create one of these startup scripts in $HOME and re-run:"
    ui.abort STARTUP_SCRIPTS.map { |s| '  ' + s }
  end

  if File.read(script).include? 'RIPDIR'
    ui.puts "rip: env variables already present in startup script"
    false
  else
    ui.puts "rip: adding env variables to #{script}"
    File.open(script, 'a+') do |f|
      f.puts startup_script_template
    end
    true
  end
end