Ensure consistent tab completes

This commit is contained in:
Alan Foster
2020-10-14 14:20:04 +01:00
parent 9e16fb8c4f
commit 832e2263b0
3 changed files with 16 additions and 14 deletions
@@ -1842,7 +1842,6 @@ class Core
# @param words [Array<String>] the previously completed words on the command line. words is always
# at least 1 when tab completion has reached this stage since the command itself has been completed
def cmd_set_tabs(str, words)
# A value has already been specified
return [] if words.length > 2
@@ -1850,8 +1849,7 @@ class Core
if words.length == 2
return tab_complete_option_values(str, words, opt: words[1])
end
Readline.completion_append_character = " "
return tab_complete_option_names(str, words)
tab_complete_option_names(str, words)
end
def cmd_setg_help
@@ -33,19 +33,21 @@ module Msf
def tab_complete_option(str, words)
if str.end_with?('=')
option_name = str.chop
option_value = ''
::Readline.completion_append_character = ' '
return tab_complete_option_values(option_name, words, opt: option_name).map { |value| "#{str}#{value}" }
else
if str.include?('=')
str_split = str.split('=')
option_value = str_split[1].strip
option_name = str_split[0].strip
::Readline.completion_append_character = ' '
return tab_complete_option_values(option_value, words, opt: option_name).map { |value| "#{option_name}=#{value}" }
end
return tab_complete_option_values(option_value, words, opt: option_name).map { |value| "#{str}#{value}" }
elsif str.include?('=')
str_split = str.split('=')
option_name = str_split[0].strip
option_value = str_split[1].strip
::Readline.completion_append_character = ' '
return tab_complete_option_values(option_value, words, opt: option_name).map { |value| "#{option_name}=#{value}" }
end
::Readline.completion_append_character = ' '
return tab_complete_option_names(str, words).map { |name| "#{name}=" }
::Readline.completion_append_character = ''
tab_complete_option_names(str, words).map { |name| "#{name}=" }
end
#
+2
View File
@@ -358,6 +358,8 @@ module DispatcherShell
# Readline.basic_word_break_characters variable being set to \x00
#
def tab_complete(str)
::Readline.completion_append_character = ' '
# Check trailing whitespace so we can tell 'x' from 'x '
str_match = str.match(/[^\\]([\\]{2})*\s+$/)
str_trail = (str_match.nil?) ? '' : str_match[0]