Completions for some long options are missing. (doesn't parse --help output perfectly)

Bug #1167533 reported by Andrew
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
bash-completion (Ubuntu)
Triaged
Low
Unassigned

Bug Description

I noticed today that "--recursive" is missing from the completions for grep. A quick glance grep's man page reveals that other long options such as "--text" are also missing. I'm not sure what the pattern is.

Steps to reproduce:

  1) Type "grep --".
  2) Press <Tab> twice.
  3) Observe that "--recursive" is missing.

ProblemType: Bug
DistroRelease: Ubuntu 13.04
Package: bash-completion 1:2.0-1ubuntu3
ProcVersionSignature: Ubuntu 3.8.0-17.27-generic 3.8.6
Uname: Linux 3.8.0-17-generic x86_64
NonfreeKernelModules: nvidia zfs zunicode zavl zcommon znvpair
ApportVersion: 2.9.2-0ubuntu5
Architecture: amd64
Date: Wed Apr 10 12:32:24 2013
InstallationDate: Installed on 2013-04-07 (2 days ago)
InstallationMedia: Ubuntu 13.04 "Raring Ringtail" - Alpha amd64 (20130402.1)
MarkForUpload: True
PackageArchitecture: all
ProcEnviron:
 TERM=xterm
 PATH=(custom, no user)
 XDG_RUNTIME_DIR=<set>
 LANG=en_US.UTF-8
 SHELL=/bin/bash
SourcePackage: bash-completion
UpgradeStatus: No upgrade log present (probably fresh install)

Revision history for this message
Andrew (andrewkvalheim) wrote :
Revision history for this message
Peter Cordes (peter-cordes) wrote :

bash_completion uses
 sed -ne 's/.*\(--[-A-Za-z0-9]\{1,\}=\{0,1\}\).*/\1/p'
to parse the options out of the --help output for MANY commands, including grep.

Unfortunately, it trips up on lines like this from grep:
  -r, --recursive like --directories=recurse

because the .* matches right up to before --directories=recurse. d'oh.
It gets --directories out of that line.

summary: - Completions for some long options are missing.
+ Completions for some long options are missing. (doesn't parse --help
+ output perfectly)
Revision history for this message
Peter Cordes (peter-cordes) wrote :

fixed it:

echo ' -r, --recursive like --directories=recurse' | sed -ne 's/\([^-]\|-[^-]\)*\(--[-A-Za-z0-9]\{1,\}=\{0,1\}\).*/\2/p'
--recursive

using \([^-]\|-[^-]\)* instead of .* at the front of the pattern makes the greedy match at the front stop at the first --. If there are commands that use -- as formatting in their --help output, then this won't work, e.g.
 -r -- equivalent to --recursive
but otherwise this should be good. It's pretty much standard to list the actual options early in a line, rather than
  like --directories=recurse -r, --recursive

This goes in _longopt(), line 1801 of bash_completion.

I'll submit this upstream, too

Revision history for this message
Peter Cordes (peter-cordes) wrote :

upstream https://alioth.debian.org/tracker/index.php?func=detail&aid=314896&group_id=100114&atid=413095

Patch attached there. Also fixes
ls --directory --[TAB] => now completes options

  rather than deciding that it's right and user is wrong, and only accepting a directory name. Not smart for such a naive function.

Changed in bash-completion (Ubuntu):
status: New → In Progress
tags: added: patch-forwarded-upstream
removed: amd64
Mathew Hodson (mhodson)
Changed in bash-completion (Ubuntu):
importance: Undecided → Low
Revision history for this message
Mathew Hodson (mhodson) wrote :

I don't know if the patch was accepted upstream, but this hasn't made it to Ubuntu.

Test cases in OP and comment #6 still fail on Zesty.

Changed in bash-completion (Ubuntu):
status: In Progress → Triaged
tags: added: testcase
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.