Date: Tue, 19 Oct 1999 12:43:37 -0700 (PDT) From: patl@phoenix.volant.org To: Matthew Hunt <mph@astro.caltech.edu> Cc: Arcady Genkin <a.genkin@utoronto.ca>, freebsd-questions@FreeBSD.ORG Subject: Re: Bash prompt (/usr/home/username instead of ~/) Message-ID: <ML-3.4.940362217.4086.patl@asimov> In-Reply-To: <19991019122756.A34003@wopr.caltech.edu>
next in thread | previous in thread | raw e-mail | index | archive | help
On 19-Oct-99 at 12:28, Matthew Hunt (mph@astro.caltech.edu) wrote:
> On Tue, Oct 19, 1999 at 11:51:20AM -0700, patl@phoenix.volant.org wrote:
>
> > As I recall, the goal was to get the initial path components to show
> > up as '~' when appropriate in the prompt; and the 'problem' was that
> > it didn't seem to take effect until after the first 'cd' after setting
> > PS1. The suggestion was to put a 'cd' after the 'PS1=...' in the
> > .bashrc.
> > My point is that you might not be in your home directory when bash is
> > started; and that changing the current directory is likely to be an
> > undesired side-effect. Using 'cd .' should have no side-effects beyond
> > triggering the change in the prompt.
>
> But for me, "cd ." doesn't make the prompt work! I assume that I
> observe the same problem that the original author does:
>
> freefall:/d/users/mph$ pwd
> /d/users/mph
> freefall:~$ echo $HOME
> /home/mph
> freefall:/d/users/mph$ cd .
> freefall:/d/users/mph$ cd
> freefall:~$ pwd
> /home/mph
>
> The problem is that bash's initial idea of where you are (from getcwd(3)
> when it starts?) doesn't match $HOME. When you "cd" (not "cd ."), it
> changes directory to $HOME, and becomes happy.
Hmm. In that case, you'll probably have to wrap the cd in a test to
avoid unexpected current-directory changes when bash is executed from
some other directory. Perhaps something like:
if [ "$(bin/pwd)" = "$HOME" ] ; then builtin cd ; fi
Of course, this won't properly fix cases where you are in a subdir
of your home directory. So maybe you'd prefer something like:
builtin cd $(perl -e '$_=$ENV{PWD};s:^$ENV{HOME}:~:;print')
(Note: These are both untested off-the-top-of-my-head code fragments.)
-Pat
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?ML-3.4.940362217.4086.patl>
