Skip to content

Commit 968ae8e

Browse files
committed
Land rapid7#8925, Allow edit to optionally take a path
2 parents b10d6b8 + 9afb098 commit 968ae8e

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

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

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,30 +66,37 @@ def local_editor
6666
end
6767

6868
def cmd_edit_help
69-
msg = "Edit the currently active module"
70-
msg = "#{msg} #{local_editor ? "with #{local_editor}" : "(LocalEditor or $VISUAL/$EDITOR should be set first)"}."
71-
print_line "Usage: edit"
69+
print_line "Usage: edit [file/to/edit.rb]"
7270
print_line
73-
print_line msg
74-
print_line "When done editing, you must reload the module with 'reload' or 'rerun'."
71+
print_line "Edit a local file or the currently active module with #{local_editor}"
72+
print_line "If a file path is specified it will automatically be reloaded after editing"
73+
print_line "Otherwise, you can reload the active module with 'reload' or 'rerun'."
7574
print_line
7675
end
7776

7877
#
7978
# Edit the currently active module
8079
#
81-
def cmd_edit
82-
if active_module
83-
editor = local_editor
84-
path = active_module.file_path
80+
def cmd_edit(*args)
81+
if args.length > 0
82+
path = args[0]
83+
elsif active_module
84+
path = active_module.file_path
85+
end
8586

87+
if path
88+
editor = local_editor
8689
if editor.nil?
8790
editor = 'vim'
8891
print_warning("LocalEditor or $VISUAL/$EDITOR should be set. Falling back on #{editor}.")
8992
end
9093

9194
print_status("Launching #{editor} #{path}")
9295
system(editor, path)
96+
97+
if args.length > 0
98+
load args[0]
99+
end
93100
else
94101
print_error('Nothing to edit -- try using a module first.')
95102
end

0 commit comments

Comments
 (0)