From owner-freebsd-questions Tue Oct 19 12:43:46 1999 Delivered-To: freebsd-questions@freebsd.org Received: from phoenix.volant.org (phoenix.volant.org [205.179.79.193]) by hub.freebsd.org (Postfix) with ESMTP id B407817A62 for ; Tue, 19 Oct 1999 12:43:43 -0700 (PDT) (envelope-from patl@phoenix.volant.org) Received: from asimov.phoenix.volant.org ([205.179.79.65]) by phoenix.volant.org with smtp (Exim 1.92 #8) id 11dfAc-0006Wn-00; Tue, 19 Oct 1999 12:43:42 -0700 Received: from localhost by asimov.phoenix.volant.org (SMI-8.6/SMI-SVR4) id MAA07529; Tue, 19 Oct 1999 12:43:38 -0700 Date: Tue, 19 Oct 1999 12:43:37 -0700 (PDT) From: patl@phoenix.volant.org Reply-To: patl@phoenix.volant.org Subject: Re: Bash prompt (/usr/home/username instead of ~/) To: Matthew Hunt Cc: Arcady Genkin , freebsd-questions@FreeBSD.ORG In-Reply-To: <19991019122756.A34003@wopr.caltech.edu> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; CHARSET=US-ASCII Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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