Tab-completion with directories/links

25

8

I have this problem with tab-completion in terminal in both archlinux and ubuntu:

I have a link which links to a directory named "something" in my home directory. Now when I open a terminal and want to do something with that directory, let's say just cd, I'd type cd somet and then hit tab because now "something" is the only possibility it gets completed.

The problem is that there is no slash after something (as there should be since it's a link to a directory). I have to hit tab one more time for the slash to appear.

Is there a way to fix this, ie. so that the slash appears directly?

houbysoft

Posted 2010-06-21T21:27:26.837

Reputation: 4 276

Answers

40

echo "set mark-symlinked-directories on" >> ~/.inputrc

Ctrl+x, then Ctrl+r

via Ubuntu Forums - Strange bash shell tab completion behaviour

N Heinrichs

Posted 2010-06-21T21:27:26.837

Reputation: 561

1Don't forget to include the default file in /etc/inputrc. Otherwise things like ctrl left won't work anymore. $include /etc/inputrc – keiki – 2016-09-19T08:00:28.977

2Noteworthy: this also works for OSX – isakkarlsson – 2013-10-06T20:07:49.870

4

I get the same behaviour, execpt I don't regard it as a bug/problem. The first completion is for the link itself, and the second is for the link's target (which happens to be a directory).

Consider this:

$ ssh devio.us
fredden@wolfman $ mkdir directory 
fredden@wolfman $ ln -s directory link 
fredden@wolfman $ ls -l link 
lrwxr-xr-x  1 fredden  shifty  9 Jun 21 18:03 link -> directory
fredden@wolfman $ ls -l link/
total 8
drwxr-xr-x  2 fredden  shifty  512 Jun 21 18:03 .
drwxr-xr-x  3 fredden  shifty  512 Jun 21 18:03 ..
fredden@wolfman $ 

fredden

Posted 2010-06-21T21:27:26.837

Reputation: 286

3Would also say that this is a feature. This is 100% consistent treatment as with the difference between rm something and rm something/. – Benjamin Bannier – 2010-06-21T22:36:18.970

I see. So if it is by design, I assume there is no way around it? It's just that I have to cd to the dir/link quite often, and typing tab twice takes more time. – houbysoft – 2010-06-21T22:49:58.077

1Not sure if this helps, but <code>cd link</code> and <code>cd link/</code> yield the same results for me. – fredden – 2010-06-22T22:30:49.647

2I believe the OP wants to cd into a subdir of link, so type "cd lin<tab>abc" to get "cd link/abc" rather than "cd linkabc" (i.e. not have to also type the slash), even though "cd link" and "cd link/" do behave identically. – None – 2010-06-24T12:55:43.453

and Roger Pate: yes, I know it behaves the same way, the problem is exactly as Roger Pate said. Oh well, I guess I'll have to type tab twice.. – houbysoft – 2010-06-28T01:34:10.333