Skip to content

Commit 1a04691

Browse files
committed
Fix rapid7#2504, edit command fixes I missed 3y ago
local_editor was never nil, so there was some dead code.
1 parent dbdc558 commit 1a04691

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

features/commands/help.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Feature: Help command
4646
------- -----------
4747
advanced Displays advanced options for one or more modules
4848
back Move back from the current context
49-
edit Edit the current module with $VISUAL or $EDITOR
49+
edit Edit the current module with the preferred editor
5050
info Displays information about one or more modules
5151
loadpath Searches for and loads modules from a path
5252
options Displays global options or for one or more modules

lib/msf/ui/console/command_dispatcher/modules.rb

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Modules
2727
def commands
2828
{
2929
"back" => "Move back from the current context",
30-
"edit" => "Edit the current module with $VISUAL or $EDITOR",
30+
"edit" => "Edit the current module with the preferred editor",
3131
"advanced" => "Displays advanced options for one or more modules",
3232
"info" => "Displays information about one or more modules",
3333
"options" => "Displays global options or for one or more modules",
@@ -61,39 +61,40 @@ def name
6161
"Module"
6262
end
6363

64-
6564
def local_editor
66-
Rex::Compat.getenv('VISUAL') || Rex::Compat.getenv('EDITOR') || '/usr/bin/vim'
65+
framework.datastore['LocalEditor'] || Rex::Compat.getenv('VISUAL') || Rex::Compat.getenv('EDITOR')
6766
end
6867

6968
def cmd_edit_help
7069
msg = "Edit the currently active module"
71-
msg = "#{msg} #{local_editor ? "with #{local_editor}" : "($VISUAL or $EDITOR must be set first)"}."
70+
msg = "#{msg} #{local_editor ? "with #{local_editor}" : "(LocalEditor or $VISUAL/$EDITOR should be set first)"}."
7271
print_line "Usage: edit"
7372
print_line
7473
print_line msg
75-
print_line "When done editing, you must reload the module with 'reload' or 'rexploit'."
74+
print_line "When done editing, you must reload the module with 'reload' or 'rerun'."
7675
print_line
7776
end
7877

7978
#
8079
# Edit the currently active module
8180
#
8281
def cmd_edit
83-
unless local_editor
84-
print_error "$VISUAL or $EDITOR must be set first. Try 'export EDITOR=/usr/bin/vim'"
85-
return
86-
end
8782
if active_module
88-
path = active_module.file_path
89-
print_status "Launching #{local_editor} #{path}"
90-
system(local_editor,path)
83+
editor = local_editor
84+
path = active_module.file_path
85+
86+
if editor.nil?
87+
editor = 'vim'
88+
print_warning("LocalEditor or $VISUAL/$EDITOR should be set. Falling back on #{editor}.")
89+
end
90+
91+
print_status("Launching #{editor} #{path}")
92+
system(editor, path)
9193
else
92-
print_error "Nothing to edit -- try using a module first."
94+
print_error('Nothing to edit -- try using a module first.')
9395
end
9496
end
9597

96-
9798
def cmd_advanced_help
9899
print_line 'Usage: advanced [mod1 mod2 ...]'
99100
print_line

0 commit comments

Comments
 (0)