19

I have a symbolic link for a directory,

e.g ln -s /tmp /xxx

Now when I type /xx and press tab key, bash would complete the line to /xxx

If I press it again it become /xxx/

Now, how can I ask bash to complete /xx to /xxx/ automatically (provided that there's only one match)

daisy
  • 54,555

2 Answers2

29

Add the following line to your ~/.inputrc file:

set mark-symlinked-directories on

See "Readline Init File Syntax" in the Bash Reference Manual for more on this topic.

Warren Young
  • 72,032
  • 3
    WHY have I never searched for this issue? This has been bugging me for so long! (all my personal files reside under a symlink in my home folder) – sylbru Jan 06 '21 at 01:50
3

WORKSFORME on Ubuntu 15.10. What are you on? Are you sure you are using bash and not zsh?

Maybe just maybe :

echo 'set mark-symlinked-directories on' >> ~/.inputrc
echo 'export INPUTRC=~/.inputrc' >> ~/.bashrc
Law29
  • 1,156
  • Mac, updated question – daisy Apr 12 '16 at 05:40
  • 2
    You have the exact opposite problem of http://unix.stackexchange.com/questions/25734/avoid-a-trailing-slash-in-bash-when-completing-a-directory-name-like-zsh?rq=1 right? – Law29 Apr 12 '16 at 05:42
  • I found this nice reference page about the settings that can go into inputrc, might be useful for someone who comes here: https://ss64.com/bash/syntax-inputrc.html – Lajos Mészáros Mar 21 '24 at 08:04