Project

General

Profile

Actions

Bug #2931

closed

PS1 prompt in default user .profile is incorrect

Added by Jim Klimov almost 11 years ago. Updated almost 6 years ago.

Status:
Resolved
Priority:
Normal
Assignee:
Category:
OS/Net (Kernel and Userland)
Target version:
Start date:
2012-06-25
Due date:
% Done:

100%

Estimated time:
Difficulty:
Medium
Tags:
illumos

Description

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:

PS1='${LOGNAME}@$(/usr/bin/hostname):$(
    [[ "${LOGNAME}" == "root" ]] && printf "%s" "${PWD/${HOME}/~}# " ||
    printf "%s" "${PWD/${HOME}/~}\$ ")'

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:

root@openindiana:/# cd /zones/build/zone1/root/etc
root@openindiana:/zones/build/zone1~/etc# ...

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

root@openindiana:/# mkdir /root/subdir
root@openindiana:/# cd /root/subdir/
root@openindiana:~/subdir# ...

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):

PS1='${LOGNAME}@$(/usr/bin/hostname):$(
    echo ${PWD} | sed "s,^${HOME}\(\/.*\)*$,\~\1,")$(
    [[ "${LOGNAME}" == "root" ]] && echo "# " || echo "$ " )'

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

Actions #1

Updated by Yuri Pankov almost 11 years ago

Why not use something simple (bash is default shell anyway):

PS1="\u@\h:\w\\$ " 

Actions #2

Updated by Jim Klimov almost 11 years ago

That does make sense and this or similar definition was used in .bash_profile for ages.
IMHO, the .profile shared by different shell implementations should use the "minimal common syntax" as to work in all shells. For example, the bash-builtins are bound to be faster than calling external programs every time - so an override in user's or default bash_profile is encouraged (perhaps as part of this or another bug? - add equivalent default profiles optimized for specific shells)

Actions #3

Updated by Ken Mays over 10 years ago

  • Assignee set to OI illumos
Actions #4

Updated by Electric Monk over 6 years ago

git commit 719d176126cc1c689a469d4c3553d770d1c4e94e

commit  719d176126cc1c689a469d4c3553d770d1c4e94e
Author: Toomas Soome <tsoome@me.com>
Date:   2016-12-02T14:53:39.000Z

    6723 etc/skel needs cleanup
    2931 PS1 prompt in default user .profile is incorrect
    Reviewed by: Andrew Stormont <andyjstormont@gmail.com>
    Reviewed by: Lauri Tirkkonen <lotheac@iki.fi>
    Reviewed by: Gordon Ross <Gordon.W.Ross@gmail.com>
    Reviewed by: Adam Števko <adam.stevko@gmail.com>
    Reviewed by: Alexander Pyhalov <apyhalov@gmail.com>
    Approved by: Hans Rosenfeld <rosenfeld@grumpf.hope-2000.org>

Actions #5

Updated by Aurélien Larcher almost 6 years ago

  • Category set to OS/Net (Kernel and Userland)
  • Status changed from New to Resolved
  • Target version set to Hipster
  • % Done changed from 0 to 100
  • Tags changed from needs-triage to illumos

Resolved by referenced illumos ticket.

Actions

Also available in: Atom PDF