Class: Picobox::Shell::StartupScript

Inherits:
Object
  • Object
show all
Defined in:
lib/picobox/shell/startup_script.rb

Direct Known Subclasses

Bash, Zsh

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(os) ⇒ StartupScript

Returns a new instance of StartupScript.



19
20
21
# File 'lib/picobox/shell/startup_script.rb', line 19

def initialize(os)
  @os = os
end

Instance Attribute Details

#osObject (readonly)

Returns the value of attribute os.



17
18
19
# File 'lib/picobox/shell/startup_script.rb', line 17

def os
  @os
end

Class Method Details

.get(os) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/picobox/shell/startup_script.rb', line 5

def get(os)
  case "#{os.user_shell}:#{os.to_s}"
  when /\/bin\/bash:darwin/, /\/bin\/bash:linux/
    Shell::Bash.new(os)
  when /\/bin\/zsh:darwin/, /\/bin\/zsh:linux/
    Shell::Zsh.new(os)
  else
    raise Errors::ShellNotSupported, "#{os.user_shell}:#{os.to_s}"
  end
end

Instance Method Details

#filenameObject

Raises:

  • (::NotImplementedError)


43
44
45
# File 'lib/picobox/shell/startup_script.rb', line 43

def filename
  raise ::NotImplementedError, 'must have filename'
end

#install_extensionsObject



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/picobox/shell/startup_script.rb', line 23

def install_extensions
  source  = "#{Picobox.extensions_dir}/extensions.bash"
  dest    = os.shell_extensions

  TTY::File.copy_file source, dest

  TTY::File.append_to_file(
    filename,
    "\n#{extension}\n"
    )
end

#uninstall_extensionsObject



36
37
38
39
40
# File 'lib/picobox/shell/startup_script.rb', line 36

def uninstall_extensions
  TTY::File.gsub_file filename, /#{Regexp.escape(extension)}/ do
    "# picobox removed #{Time.now}"
  end
end