netbsdnoob This works with NetBSD's ksh
, ksh93
, dash
and bash
:
PS1='$( printf "\\033[1;37m" )'\
'$( id -un )@$( expr $(hostname) : "\([^.]*\)" ) '\
'$( X="$PWD/"; Y="$HOME/"; '\
' [ "${X#$Y}" = "$PWD/" ] && echo "$PWD" || echo "~${PWD#$HOME}" ) '\
'$( printf "\\033[0m" )'\
'$( [ $(id -u) -eq 0 ] && echo "#" || echo "$" ) '
Be careful copy exactly as shown, and not leave any trailing blanks. NetBSD's /bin/sh
will need a set -o promptcmds
(if that option exists in the shell).
EDIT: Use a different method instead of expr
as the RHS string (ie. the path) may have blanks or regex
meta-chars which will need to be quoted.