How to make tab completion append slash for directory symlinks?
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?
Enable the mark-symlinked-directories
option for READLINE. There are few ways to do that:
-
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.
-
-
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
-
-
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:
- READLINE section in the manual page of Bash
- The source of the first two ways
- The source of the idea for the third way
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.