[Illumos-team] [OpenIndiana Distribution - Bug #2931] PS1 prompt in default user .profile is incorrect

illumos project devnull at illumos.org
Fri Feb 8 03:35:51 UTC 2013


Issue #2931 has been updated by Ken Mays.

Assignee set to OI illumos


----------------------------------------
Bug #2931: PS1 prompt in default user .profile is incorrect
https://www.illumos.org/issues/2931

Author: Jim Klimov
Status: New
Priority: Normal
Assignee: OI illumos
Category: 
Target version: 
Difficulty: Medium
Tags: needs-triage


The PS1 prompt is defined incorrectly in OpenIndiana user's ~/.profile files (cloned for each new user from /etc/skel/.profile). 
Currently this is defined as:
<pre>
PS1='${LOGNAME}@$(/usr/bin/hostname):$(
    [[ "${LOGNAME}" == "root" ]] && printf "%s" "${PWD/${HOME}/~}# " ||
    printf "%s" "${PWD/${HOME}/~}\$ ")'
</pre>

The main problem is with the substitution for HOME: "as is" this eradicates a matching string from anywhere in the current directory path, i.e. "/root" disappears from the paths below:
<pre>
root at openindiana:/# cd /zones/build/zone1/root/etc
root at openindiana:/zones/build/zone1~/etc# ...

root at openindiana:/# mkdir /rootpool
root at openindiana:/# cd /rootpool
root at openindiana:~pool# ...

root at openindiana:/# mkdir /root/subdir
root at openindiana:/# cd /root/subdir/
root at openindiana:~/subdir# ...
</pre>
First can be fixed by prefixing HOME with the dash character (#) in the expression. Second part is problematic for me in bash alone, but I can solve it with sed like shown in the end of the post. Third "seems" to work ;)

A couple of arguable problems are:
1) The directory (substitution) is the same, but used twice (with different characters for root and user); it will be more maintainable (maybe a bit slower?) to split these components as shown below;
2) Is printf better/faster than echo in this simple case of a fixed static line?

Suggested replacement is (choice of escape character to separate parts of the regexp in sed is questionable though):
<pre>
PS1='${LOGNAME}@$(/usr/bin/hostname):$(
    echo ${PWD} | sed "s,^${HOME}\(\/.*\)*$,\~\1,")$(
    [[ "${LOGNAME}" == "root" ]] && echo "# " || echo "$ " )'
</pre>

At least, all the examples above work correctly with this definition.


-- 
You have received this notification because you have either subscribed to it, or are involved in it.
To change your notification preferences, please click here: http://www.illumos.org/my/account



More information about the Illumos-team mailing list