fix issues with home directory replacement, from Torsten Sillke:

• if $PWD = ${HOME}foo, no longer show as ~foo in PS1
• simplify ~, ~+, and ~- exactly as $PWD is upon shell entry
  (fixes HOME=/home/./foo but PWD=/home/foo)
This commit is contained in:
tg 2016-07-24 23:05:52 +00:00
parent 8370c0dd4d
commit e0e63c65e6
3 changed files with 27 additions and 11 deletions

View File

@ -1,5 +1,5 @@
# $Id$
# $MirOS: src/bin/mksh/dot.mkshrc,v 1.105 2016/04/09 16:33:23 tg Exp $
# $MirOS: src/bin/mksh/dot.mkshrc,v 1.106 2016/07/24 23:05:51 tg Exp $
#-
# Copyright (c) 2002, 2003, 2004, 2006, 2007, 2008, 2009, 2010,
# 2011, 2012, 2013, 2014, 2015, 2016
@ -40,8 +40,8 @@ PS4='[$EPOCHREALTIME] '; PS1=$'\001\r''${|
(( e )) && REPLY+="$e|"
REPLY+=${USER}@${HOSTNAME%%.*}:
\typeset d=${PWD:-?} p=~; [[ $p = ?(*/) ]] || d=${d/#$p/\~}
\typeset m=${%d} n p=...; (( m > 0 )) || m=${#d}
\typeset d=${PWD:-?}/ p=~; [[ $p = ?(*/) ]] || d=${d/#$p\//\~/}
d=${d%/}; \typeset m=${%d} n p=...; (( m > 0 )) || m=${#d}
(( m > (n = (COLUMNS/3 < 7 ? 7 : COLUMNS/3)) )) && d=${d:(-n)} || p=
REPLY+=$p$d

26
eval.c
View File

@ -23,7 +23,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.189 2016/06/26 00:44:57 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.190 2016/07/24 23:05:52 tg Exp $");
/*
* string expansion
@ -1714,11 +1714,13 @@ maybe_expand_tilde(const char *p, XString *dsp, char **dpp, bool isassign)
*
* based on a version by Arnold Robbins
*/
char *
do_tilde(char *cp)
{
char *dp = null;
#ifndef MKSH_NOPWNAM
bool do_simplify = true;
#endif
if (cp[0] == '\0')
dp = str_val(global("HOME"));
@ -1727,11 +1729,25 @@ do_tilde(char *cp)
else if (ksh_isdash(cp))
dp = str_val(global("OLDPWD"));
#ifndef MKSH_NOPWNAM
else
else {
dp = homedir(cp);
do_simplify = false;
}
#endif
/* If HOME, PWD or OLDPWD are not set, don't expand ~ */
return (dp == null ? NULL : dp);
/* if parameters aren't set, don't expand ~ */
if (dp == NULL || dp == null)
return (NULL);
/* simplify parameters as if cwd upon entry */
#ifndef MKSH_NOPWNAM
if (do_simplify)
#endif
{
strdupx(dp, dp, ATEMP);
simplify_path(dp);
}
return (dp);
}
#ifndef MKSH_NOPWNAM

6
mksh.1
View File

@ -1,4 +1,4 @@
.\" $MirOS: src/bin/mksh/mksh.1,v 1.399 2016/06/25 23:52:06 tg Exp $
.\" $MirOS: src/bin/mksh/mksh.1,v 1.400 2016/07/24 23:05:52 tg Exp $
.\" $OpenBSD: ksh.1,v 1.160 2015/07/04 13:27:04 feinerer Exp $
.\"-
.\" Copyright © 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
@ -76,7 +76,7 @@
.\" with -mandoc, it might implement .Mx itself, but we want to
.\" use our own definition. And .Dd must come *first*, always.
.\"
.Dd $Mdocdate: June 25 2016 $
.Dd $Mdocdate: July 24 2016 $
.\"
.\" Check which macro package we use, and do other -mdoc setup.
.\"
@ -2138,7 +2138,7 @@ If the login name is empty,
.Ql + ,
or
.Ql \- ,
the value of the
the simplified value of the
.Ev HOME ,
.Ev PWD ,
or