Skip to content
Snippets Groups Projects
Commit 580ef58d authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

Bash completion: Small optimizations


$2 doesn't contain the correct value when completing something like
"--disk-template=…". Getting it via COMP_WORDS is better.

Short options (e.g. -I) can't have an equal sign.

Also add useful debugging commands for development.

Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarOlivier Tharan <olive@google.com>
parent aca55e15
No related branches found
No related tags found
No related merge requests found
...@@ -208,7 +208,8 @@ class CompletionWriter: ...@@ -208,7 +208,8 @@ class CompletionWriter:
if opt.takes_value(): if opt.takes_value():
# Ignore value # Ignore value
for i in opt.all_names: for i in opt.all_names:
ignore.append("%s=*" % utils.ShellQuote(i)) if i.startswith("--"):
ignore.append("%s=*" % utils.ShellQuote(i))
skip_one.append(utils.ShellQuote(i)) skip_one.append(utils.ShellQuote(i))
else: else:
ignore.extend([utils.ShellQuote(i) for i in opt.all_names]) ignore.extend([utils.ShellQuote(i) for i in opt.all_names])
...@@ -392,8 +393,14 @@ def WriteCompletion(sw, scriptname, funcname, ...@@ -392,8 +393,14 @@ def WriteCompletion(sw, scriptname, funcname,
sw.Write("%s() {", funcname) sw.Write("%s() {", funcname)
sw.IncIndent() sw.IncIndent()
try: try:
sw.Write('local cur="$2" prev="$3"') sw.Write("local "
sw.Write("local i first_arg_idx choices compgenargs arg_idx") ' cur="${COMP_WORDS[$COMP_CWORD]}"'
' prev="${COMP_WORDS[COMP_CWORD-1]}"'
' i first_arg_idx choices compgenargs arg_idx')
# Useful for debugging:
#sw.Write("echo cur=\"$cur\" prev=\"$prev\"")
#sw.Write("set | grep ^COMP_")
sw.Write("COMPREPLY=()") sw.Write("COMPREPLY=()")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment