Reverse a default flag

0

As a context. I have a folder which I have symlinked into my $HOME directory.

~> ls -s /var/www/to_link "$HOME/linked"

I cd into "$HOME/linked"

So, by default, pwd shows the current directory including symlinks. In this case, it would be /home/christopher/linked. If I want to have it return /var/www/to_link I have to type pwd -P. I generally find this second form more useful than the first, but I would like both to be available.

  • Is it possible to have pwd default to include the -P flag, and then use another flag to include symlinks? So basically, pwd would return /var/www/to_link and pwd -X (or some other flag) would return the original /home/christopher/linked.

cwallenpoole

Posted 2015-01-27T15:59:47.750

Reputation: 742

Answers

1

Both cd and pwd have options -P and -L. It seems you want to use cd -P by default (which then sets $PWD to the physical directory, which then affects your bash prompt and the output of pwd).

You can put one of these in your .bashrc:

alias cd='cd -P'

cd () { builtin cd -P "$@"; }

If you want to see "~/linked" in your bash prompt, you'll use the "logical" cd: cd -L ~/linked

glenn jackman

Posted 2015-01-27T15:59:47.750

Reputation: 18 546