Article View: gnu.bash.bug
Article #1007Current directory in prompt
From: Anders Ellefsrud
Date: Mon, 12 Jun 1989 18:14
Date: Mon, 12 Jun 1989 18:14
49 lines
1667 bytes
1667 bytes
Following is a small hack to substitute ~ for $HOME in the prompt string.
I use \~ (instead of \w) for this effect.
anders@ifi.uio.no
*** parse.y.orig Mon Jun 12 19:00:48 1989
--- parse.y Mon Jun 12 19:40:04 1989
***************
*** 1370,1375 ****
--- 1370,1376 ----
\n CRLF
\s the name of the shell
\w the current working directory
+ \~ the current working directory with ~ substituted for $HOME
\u your username
\h the hostname
\# the command number of this command
***************
*** 1456,1461 ****
--- 1457,1463 ----
}
case 'w':
+ case '~':
{
/* We would like to use the value of $PWD, but it turns out that
this could be a bad idea because the user could set PWD to
***************
*** 1477,1482 ****
--- 1479,1495 ----
temp = (char *)xmalloc (MAXPATHLEN);
getwd (temp);
#endif /* EFFICIENT */
+
+ if (c == '~') {
+ int idx;
+ if (t_string = get_string_value ("HOME")) {
+ idx = strlen(t_string);
+ if (idx > 1 && strncmp(temp, t_string, idx) == 0) {
+ temp[0] = '~';
+ strcpy( temp + 1, temp + idx);
+ }
+ }
+ }
goto add_string;
}
Technical Details
Message-ID:
<CMM.0.88.613678264.anders@horn.uio.no>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!IFI.UIO.NO!andersShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!IFI.UIO.NO!anders From: anders@IFI.UIO.NO (Anders Ellefsrud) Newsgroups: gnu.bash.bug Subject: Current directory in prompt Message-ID: <CMM.0.88.613678264.anders@horn.uio.no> Date: 12 Jun 89 18:14:23 GMT Sender: daemon@tut.cis.ohio-state.edu Distribution: gnu Organization: GNUs Not Usenet Lines: 49 X-Unparsable-Date: Mon, 12 Jun 1989 20:11:04 MET DST