38

I have this on the command line:

ln -sf $PWD/wine-

and then I hit Tab to complete the filename. In earlier versions of Ubuntu, this worked just fine to complete the wine- filename (and as a side-effect $PWD would be expanded at that time). But now it turns it in to

ln -sf \$PWD/wine-

which isn't what I meant at all and doesn't complete anything as the file does not literally start with $.

How do I get completion back to the less broken behaviour?

set tells me these are my current settings:

BASHOPTS=checkwinsize:cmdhist:expand_aliases:extquote:force_fignore:hostcomplete:interactive_comments:progcomp:promptvars:sourcepath
SHELLOPTS=braceexpand:emacs:hashall:histexpand:history:interactive-comments:monitor
35

I've found that bash versions >= 4.2.29 have a new direxpand shopt setting. (See man docs/bash.1 if you check out a new bash, or see bash.1 from line 8951)

If one uses Quantal Quetzal 12.10 or otherwise gets hold of (or checks out and builds) a new bash, then:

shopt -s direxpand

Gives me the behavior I want, need and love.

Workaround: In the meantime, Ctrl+Alt+E instead of Tab does what I want too. But is awkward.

BTW, There are several threads called "bash tab variable expansion question?" in gnu.bash.bug. From reading them, I found the info here.

  • 2
    a version of bash with direxpand is making its way into Precise (12.04): See bugs.launchpad.net/bugs/778627 – keturn Mar 31 '13 at 19:48
  • 7
    Would be even better if I didn't have my huge path expanded and could continue using an un-escaped variable with completion. – jozxyqk Aug 28 '14 at 6:17
  • @jozxyqk Did you ever find a way to get that no-path-expansion feature? – Ungeheuer Apr 8 at 16:40
  • @Ungeheuer I'm currently using bash 4.4.19 on Ubuntu 18.04 and it just works. Not sure when this changed. – jozxyqk Apr 26 at 22:12
2

search _filedir() in the top level bash_completion script and change the line

compopt -o filenames 2>/dev/null

to

compopt -o filenames -o noquote 2>/dev/null
  • In 12.04 GNU bash, version 4.2.25 this suggestion gives the error: compopt: noquote: invalid option name – arielf Nov 14 '15 at 0:28
1

For those (like me) with 12.04 can use ~+ instead of $PWD...

for example :

cd /bin
echo ~+/ls
/bin/ls
1

Even with the updated bash, I was finding $ still gets escaped.

  • Removing the bash-completion (1:2.1-3.fc20) package
  • or simply not sourcing /etc/bashrc from ~/.bashrc seemed to fix it.

I suspect I'll now be missing some features I'm normally used to but haven't noticed any yet.


Alternative (at least for Fedora 26), add export BASH_COMPLETION_VERSINFO=0 before sourcing /etc/bashrc. This makes the problematic script think its already been sourced.

0

I encountered the same problem with Bash in Cygwin. I fixed my problem by setting the following option.

shopt -s cdable_vars

http://www.gnu.org/software/bash/manual/html_node/The-Shopt-Builtin.html

0

Disabling the shell option 'complete_fullquote' does the job:

shopt -u complete_fullquote
  • $ shopt -u complete_fullquote -bash: shopt: complete_fullquote: invalid shell option name – Anton Gorev Sep 5 at 20:34
0
shopt -u progcomp

This fixed it for me, it also removed a lot of "intelligent" completion options which I have found get in the way by not completing files that I know are there because the stupid thing thinks I don't want them as arguments to a particular command. ARRRGH

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.