[Bug 1894352] Re: bash-completion not working properly with directories with spaces in them when using some commands

Brian Murray 1894352 at bugs.launchpad.net
Mon Sep 7 15:43:48 UTC 2020


** Tags added: rls-ff-incoming

-- 
You received this bug notification because you are a member of Ubuntu
Foundations Bugs, which is subscribed to bash-completion in Ubuntu.
https://bugs.launchpad.net/bugs/1894352

Title:
  bash-completion not working properly with directories with spaces in
  them when using some commands

Status in bash-completion package in Ubuntu:
  New

Bug description:
  Good evening!

  Unfortunately, I need to report an issue with Ununtu 20.04's bash-
  completion (bash_completion version 2.10).  It can't properly expand
  directories with spaces when there are multiple options when using
  some commands.  Here is an example:

  $ mkdir -p "p00p/p00p 1"
  $ mkdir -p "p00p/p00p 2"
  $ ls -d p00p/p00p\ 1 p00p/p00p\ 2
  'p00p/p00p 1'  'p00p/p00p 2'
  $ ls p00p/p0<tab><tab> 
  p00p 1/ p00p 2/
  $ ls p00p/p0<tab>1<tab>   # <-- works: yields the expanded command: ls p00p/p00p\ 1/
  $ wine p00p/p0<tab><tab>  # <-- does NOT work: fails to show possible expansions: p00p 1/ p00p 2/
  $ wine p00p/p0<tab>1<tab> # <-- does NOT work: fails to expand to: wine p00p/p00p\ 1/

  I temporarily fixed it by patching the portion of bash_completion
  which invokes plusdirs with the version from my raspberry pi OS
  (bash_completion version 2.8).  Here's the patch that fixes it:

  --- /usr/share/bash-completion/bash_completion	2020-09-04 20:39:18.453560935 -0700
  +++ /home/xxx/bash_completion	2020-09-04 20:39:13.625394958 -0700
  @@ -563,37 +559,28 @@
       _tilde "$cur" || return
   
       local -a toks
  -    local reset
  +    local x reset
   
  -    if [[ "$1" == -d ]]; then
           reset=$(shopt -po noglob); set -o noglob
           toks=( $(compgen -d -- "$cur") )
  -        IFS=' '; $reset; IFS=$'\n'
  -    else
  +    eval $reset
  +
  +    if [[ "$1" != -d ]]; then
           local quoted
           _quote_readline_by_ref "$cur" quoted
   
           # Munge xspec to contain uppercase version too
           # http://thread.gmane.org/gmane.comp.shells.bash.bugs/15294/focus=15306
  -        local xspec=${1:+"!*.@($1|${1^^})"} plusdirs=()
  -
  -        # Use plusdirs to get dir completions if we have a xspec; if we don't,
  -        # there's no need, dirs come along with other completions. Don't use
  -        # plusdirs quite yet if fallback is in use though, in order to not ruin
  -        # the fallback condition with the "plus" dirs.
  -        local opts=( -f -X "$xspec" )
  -        [[ $xspec ]] && plusdirs=(-o plusdirs)
  -        [[ ${COMP_FILEDIR_FALLBACK-} ]] || opts+=( "${plusdirs[@]}" )
  -
  +        local xspec=${1:+"!*.@($1|${1^^})"}
           reset=$(shopt -po noglob); set -o noglob
  -        toks+=( $(compgen "${opts[@]}" -- $quoted) )
  -        IFS=' '; $reset; IFS=$'\n'
  +        toks+=( $( compgen -f -X "$xspec" -- $quoted ) )
  +        eval $reset
   
           # Try without filter if it failed to produce anything and configured to
           [[ -n ${COMP_FILEDIR_FALLBACK:-} && -n "$1" && ${#toks[@]} -lt 1 ]] && {
               reset=$(shopt -po noglob); set -o noglob
  -            toks+=( $(compgen -f "${plusdirs[@]}" -- $quoted) )
  -            IFS=' '; $reset; IFS=$'\n'
  +            toks+=( $( compgen -f -- $quoted ) )
  +            eval $reset
           }
       fi

  <EOF>

  Unfortunately, to apply the patch with patch -p0, I had to type in the
  name of the file to patch because the patch I saved was only a subset
  of the patch produced by "diff -u -w" and my diff-fu isn't good enough
  to know how to fix it.  But, providing the name of the file to be
  patched when prompted (/usr/share/bash-completion/bash_completion)
  made it work and after I sourced the new file the issue was fixed.

  Thus, this appears to be a regression of sorts but my bash programming
  skills aren't good enough to fix it myself while ensuring that any
  functionality provided by the portions that I replaced isn't lost.

  Thank you!

  Very sincerely,

  Jason A. Pfeil

  ProblemType: Bug
  DistroRelease: Ubuntu 20.04
  Package: bash-completion 1:2.10-1ubuntu1 [modified: usr/share/bash-completion/bash_completion]
  ProcVersionSignature: Ubuntu 5.4.0-45.49-generic 5.4.55
  Uname: Linux 5.4.0-45-generic x86_64
  NonfreeKernelModules: nvidia_modeset nvidia
  ApportVersion: 2.20.11-0ubuntu27.8
  Architecture: amd64
  CasperMD5CheckResult: skip
  CurrentDesktop: ubuntu:GNOME
  Date: Fri Sep  4 20:50:10 2020
  Dependencies:
   
  EcryptfsInUse: Yes
  InstallationDate: Installed on 2020-08-29 (7 days ago)
  InstallationMedia: Ubuntu 20.04.1 LTS "Focal Fossa" - Release amd64 (20200731)
  PackageArchitecture: all
  ProcEnviron:
   TERM=xterm-256color
   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)

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/bash-completion/+bug/1894352/+subscriptions



More information about the foundations-bugs mailing list