Module: Rush

Defined in:
lib/rush.rb,
lib/rush/shell.rb,
lib/rush/exceptions.rb,
lib/rush/embeddable_shell.rb,
lib/rush/shell/completion.rb

Overview

The top-level Rush module has some convenience methods for accessing the local box.

Defined Under Namespace

Modules: Commands, Completion, Connection, FindBy, HeadTail Classes: Access, BadAccessSpecifier, BashFailed, Box, Config, Dir, DoesNotExist, EmbeddableShell, Entry, Exception, FailedTransmit, File, NameAlreadyExists, NameCannotContainSlash, NotADir, NotAuthorized, Path, Process, ProcessSet, RushdNotRunning, SearchResults, Shell

Class Method Summary collapse

Class Method Details

.[](key) ⇒ Object

Access the root filesystem of the local box.

Examples:

Rush['/etc/hosts'].contents

Parameters:

  • key (String)

    relative path.



12
13
14
# File 'lib/rush.rb', line 12

def self.[](key)
  box[key]
end

.bash(command, options = {}) ⇒ Object

Run a bash command in the root of the local machine. Equivalent to Rush::Box.new.bash.



38
39
40
# File 'lib/rush.rb', line 38

def self.bash(command, options={})
  box.bash(command, options)
end

.boxObject

Create a box object for localhost.



61
62
63
# File 'lib/rush.rb', line 61

def self.box
  @@box = Rush::Box.new
end

.dir(filename) ⇒ Object

Create a dir object from the path of a provided file.

Examples:

Rush.dir(__FILE__).files

Parameters:

  • filename (String)

    path that should be created.



22
23
24
# File 'lib/rush.rb', line 22

def self.dir(filename)
  box[::File.expand_path(::File.dirname(filename)) + '/']
end

.launch_dirObject

Create a dir object based on the shell’s current working directory at the time the program was run.

Examples:

Rush.launch_dir.files


32
33
34
# File 'lib/rush.rb', line 32

def self.launch_dir
  box[::Dir.pwd + '/']
end

.my_processObject

Get the process object for this program’s PID.

Examples:

puts "I'm using #{Rush.my_process.mem} blocks of memory"


56
57
58
# File 'lib/rush.rb', line 56

def self.my_process
  box.processes.filter(:pid => ::Process.pid).first
end

.processesObject

Pull the process list for the local machine.

Examples:

Rush.processes.filter(:cmdline => /ruby/)


47
48
49
# File 'lib/rush.rb', line 47

def self.processes
  box.processes
end

.quote(path) ⇒ Object

Quote a path for use in backticks, say.



66
67
68
# File 'lib/rush.rb', line 66

def self.quote(path)
  path.gsub(/(?=[^a-zA-Z0-9_.\/\-\x7F-\xFF\n])/n, '\\').gsub(/\n/, "'\n'").sub(/^$/, "''")
end