3

My ~/Documents directory is a symlink:

nathan@nathan-desktop:~$ stat Documents
  File: Documents -> /mnt/nathan/extended/Documents

If I want to cd into the directory, I can type:

c d space D o c tab

...and tab completion will append uments to the end of cd Doc as expected. However, it does not append a trailing /, even though the symlink points to a directory.

Is there a way to make Bash do that?

  • That seems like it's a ZSH thing, not Bash, I've never had Bash do that properly. – Thomas Ward Apr 6 '17 at 18:55
4

Enable the mark-symlinked-directories option for READLINE. There are few ways to do that:

  1. Customize your readline by putting commands in an .inputrc file:

    • Create or edit ~/.inputrc and add these lines:

      $include /etc/inputrc
      set mark-symlinked-directories on
      
    • Log-in/Log-out or press ctrl+x and ctrl+r to reload the settings.

  2. Customize your readline by putting commands in the .bashrc file (or in the .profile file):

    • Edit ~/.bashrc and add this line:

      bind 'set mark-symlinked-directories on'
      
    • Log-in/Log-out or source the file:

      source ~/.bashrc
      
  3. Customize the readline for all users by creating a .sh file into the directory /etc/profile.d:

    • Create a file /etc/profile.d/mark-symlinked-directories.sh which should looks like:

      #!/bin/sh
      bind 'set mark-symlinked-directories on'
      

      Executable permissions to this file are not needed.

    • Log-in/Log-out. That's it.

Further reading:


One simple way that I found is double tab for completion:

c d space D o c tab tab

The first tab will append uments, the second one will append / and the third will print the list of contained directories.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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