0

I'm using the bash shell and use lots of soft links. One minor but annoying behavior I observe is the fact that I need to hit tab twice to complete the name of a soft link to a directory. e.g.

$ mkdir dir1
$ ln -s dir1 link1

Using autocompletion, entering, "cd d" produces "cd dir1/", but entering "cd l" produces "cd link1", when I'd really like it to produce "cd link1/"

1

I think you're looking for the readline variables mark-directories, and mark-symlinked-directories. Just add the following to your ~/.inputrc file and re-load it with CtrlxCtrlr.

set mark-directories on
set mark-symlinked-directories on

To ensure that CtrlxCtrlr works you should also have the following in your ~/.inputrc. (See this question.)

"\C-x\C-r": re-read-init-file

Incidentally, if you want to list the current settings of your readline variables, use the following command: (See also man bash for more details.)

bind -v
  • Which of these manpages are you referring to, when you say man bind? manpages.ubuntu.com/cgi-bin/search.py?q=bind – muru Dec 4 '15 at 20:52
  • Sorry, neither one is right. I should have said man bash, as the bind command is a bash built-in. I will edit my answer. – Miguel Gualdron Dec 4 '15 at 21:06
  • I was unaware (and did not have) a .inputrc file, but now I do! Note that the "\C-x\C-r": re-read-init-file gave me an error so I removed it. – mikemtnbikes Dec 9 '15 at 15:58
0

Tab here is acting as an auto complete, all it does is search for relevant files and directories there to complete your command.

As far as I know, in bash you can not tell it to do other wise, you can try using other shells, maybe they can.

However there isn't really a difference. since both commands will get you to the same directory...

update

According to here you can use this to cd to the parenting directory:

Here is a way of changing to the target of the given symbolic link:

cd -P .

Here is how it works

user@host:~/tmp$ ls 
@a b
user@host:~/tmp$ file a
a: symbolic link to `b/c'
user@host:~/tmp$ cd a
user@host:~/tmp/a$ cd .
user@host:~/tmp/a$ cd -P .a
user@host:~/tmp/b/c$

You can alias it to

cdl='cd -P'

From the bash manual:

The -P option says to use the physical directory structure instead of following symbolic links

  • While this wasn't the solution I was looking for (Mig10 nailed it), knowing about the -P option on cd is pretty cool. Thanks. – mikemtnbikes Dec 17 '15 at 18:37
  • Sorry I couldn't be of help :-) @mikemtnbikes – MCSH Dec 17 '15 at 23:14

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.