Module: Ronin::UI::Console::Commands Private
- Defined in:
- lib/ronin/ui/console/commands.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Allows for executing shell commands prefixed by a !
.
Constant Summary collapse
- EXECUTABLES =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Names and statuses of executables.
Hash.new do |hash,key| hash[key] = Env.paths.any? do |dir| path = dir.join(key) (path.file? && path.executable?) end end
- BLACKLIST =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Blacklist of known commands that conflict with Ruby keywords.
Class Method Summary collapse
-
.cd(*arguments) ⇒ Boolean
private
Equivalent of the
cd
command, usingDir.chdir
. -
.edit(*arguments) ⇒ Boolean
private
Edits a path and re-loads the code.
-
.export(*arguments) ⇒ true
private
Equivalent of the
export
orset
commands.
Instance Method Summary collapse
-
#executable?(name) ⇒ Boolean
protected
private
Determines if an executable exists on the system.
-
#loop_eval(input) ⇒ Object
private
Dynamically execute shell commands, instead of Ruby.
Class Method Details
.cd(*arguments) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Equivalent of the cd
command, using Dir.chdir
.
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/ronin/ui/console/commands.rb', line 86 def Commands.cd(*arguments) old_pwd = Dir.pwd new_cwd = if arguments.empty? Env.home elsif arguments.first == '-' unless ENV['OLDPWD'] print_warning 'cd: OLDPWD not set' return false end ENV['OLDPWD'] else arguments.first end Dir.chdir(new_cwd) ENV['OLDPWD'] = old_pwd return true end |
.edit(*arguments) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Edits a path and re-loads the code.
132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/ronin/ui/console/commands.rb', line 132 def Commands.edit(*arguments) path = arguments.first if Env.editor path ||= Tempfile.new(['ronin-console', '.rb']).path system(Env.editor,path) && load(path) else print_error "Please set the EDITOR env variable" return false end end |
.export(*arguments) ⇒ true
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Equivalent of the export
or set
commands.
115 116 117 118 119 120 121 |
# File 'lib/ronin/ui/console/commands.rb', line 115 def Commands.export(*arguments) arguments.each do |pair| name, value = pair.split('=',2) ENV[name] = value end end |
Instance Method Details
#executable?(name) ⇒ Boolean (protected)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Determines if an executable exists on the system.
156 157 158 |
# File 'lib/ronin/ui/console/commands.rb', line 156 def executable?(name) (File.file?(name) && File.executable?(name)) || EXECUTABLES[name] end |
#loop_eval(input) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Dynamically execute shell commands, instead of Ruby.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/ronin/ui/console/commands.rb', line 58 def loop_eval(input) if input[0,1] == '!' command = input[1..-1] name, arguments = command.split(' ') unless BLACKLIST.include?(name) if Commands.singleton_class.method_defined?(name) arguments ||= [] return Commands.send(name,*arguments) elsif executable?(name) return system(command) end end end super(input) end |