Skip to content

bash command completion has a problem with sudo command #790

Description

@mug896

Describe the bug

When the command completion function starts running
there are three variables automatically setting $1, $2, $3.
and $2 is not always the same as ${COMP_WORDS[COMP_CWORD]}.

  1. if $2 value is a member of $COMP_WORDBREAKS variable
    then it's value is empty by default

    ex) command --foo=[tab]
    $2 : (empty) ${COMP_WORDS[COMP_CWORD]} : =

  2. if $2 value start with " or ' (single or double quote)
    then it's quote removed ( "foo --> foo )

    ex) command --foo "bar[tab]
    $2 : bar ${COMP_WORDS[COMP_CWORD]} : "bar

this is an intended work for making completion function simpler
but if i use sudo in front of a command then
$2 value is always the same as ${COMP_WORDS[COMP_CWORD]}
This is a different behavior to the bash default and problematic.
and ends up can not use $2 variable and force to use
${COMP_WORDS[COMP_CWORD]} to support sudo

Versions

  • Operating system name/distribution and version:
    Operating System: Ubuntu 22.04.1 LTS
    Kernel: Linux 5.15.0-43-generic
    Architecture: x86-64
  • bash version: 5.1.16(1)-release
  • bash-completion version: 2.11

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions