help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-bash] Completing file names with spaces in them.


From: R. Clayton
Subject: [Help-bash] Completing file names with spaces in them.
Date: Fri, 30 Dec 2016 22:41:17 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)

My bash completion file looks like this

  $ cat .bash_completion
  __completer() {

    local cur="${COMP_WORDS[COMP_CWORD]}"
    local files=($(ls 2>/dev/null -1 ${cur}*.$1))

    case address@hidden in
      0) COMPREPLY=() ;;

      1) COMPREPLY=( "${files[0]}" ) ;;

      *) COMPREPLY=( $(compgen -W "${files[*]}" -- ${cur}) ) ;;
    esac
    }


  _xpdf() {
    __completer pdf
    return 0
    }

  complete -F _xpdf xpdf

  $

and it has some trouble completing when the filename has spaces in it:

  $ ls
  An inter-process communication facility for UNIX.pdf
  IC-study-problems-(1972).pdf

  $

"xpdf IC<tab>" completes just fine:

  $ xpdf IC-study-problems-(1972).pdf

but "xpdf An<tab><tab>" completes into a bunch of "files," including the IC
file ("xpdf <tab>" produces the same behavior):

  $ xpdf An
  An                            IC-study-problems-(1972).pdf
  communication                 inter-process
  facility                      UNIX.pdf
  for                           

  $ xpdf An

The first tab completes to the "file" An, the second tab produces the choices
shown.  My suspicion is that the array definition for files is getting messed
up by filename spaces.

I can sort of get what I want by doing this

  local IFS=''
  local files=($(ls 2>/dev/null -1 ${cur}*.$1))

in __completer.  Now "xpdf An<tab>" completes to

  $ xpdf An inter-process communication facility for UNIX.pdf

but xpdf doesn't handle this well at all.

What is the explanation for what's going on, and how do I get around it?




reply via email to

[Prev in Thread] Current Thread [Next in Thread]