Hello, i'm a bit late, but..
Hugues Moretto-Viry <[email protected]> wrote:
|Hi guys,
|
|I'm slowly switching from bash to mksh. So far, I like mksh and it's a real
|pleasure to use it.
[.]
|Another question, I'm trying to export my bash PS1 to mksh. On bash, I can
|apply a color on the typed command and another color on the output.
|I use the following line: "trap "printf '\e[0m'" DEBUG".
i'm using the stuff below, and the last time i tried (there were
modifications thereafter, but i don't think they hurt in that
area) it worked for all ksh, bash, ash and sh i tried.
In ~/.profile etal:
ENV="${HOME}/.shrc"
export ENV
# Some (ksh(1), NetBSD sh(1)) correctly auto-include $ENV, but bash(1) doesn't.
# Also, Heirloom sh(1) doesn't know about it at all, so do include it here and
# let it protect itself against multiple inclusion in the same shell
[ -f "${ENV}" ] && . "${ENV}"
In ${ENV}:
.....
# Determine shell type; aux while there
case ${0} in
*ksh*)
___SHTYPE=${___SHTYPE_KSH}
if [ "${KSH_VERSION}" != "${KSH_VERSION%%MIRBSD*}" ]; then
export ___MKSH=YES
eval "ps1s=\$'\e[31m' ps1e=\$'\e[0m'"
# Mac OS X /bin/ksh doesn't expand PS1 escapes
elif [ "${OSTYPE}" != darwin ]; then
ps1s="\e[31m" ps1e="\e[0m"
fi
.....
;;
*bash*)
___SHTYPE=${___SHTYPE_BASH}
ps1s="\e[31m" ps1e="\e[0m"
;;
*)
___SHTYPE=${___SHTYPE_NONE}
# /bin/sh may be some BSD ash(1)
if [ ${OSTYPE} = freebsd ] || [ ${OSTYPE} = dragonfly ]; then
#ps1s="\e[31m" ps1e="\e[0m" ps1W=' \W'
ps1W=' \W'
fi
.....
;;
esac
export ___SHTYPE
.....
# Prompts are very complicated to get :)
case ${TERM} in
*dumb*) unset ps1s ps1e;;
esac
[ -z "${ps1s}" ] && ps1s='* ' ps1e=
[ ${UID} -eq 0 ] && PS1='#' || PS1='$'
if ( [ ${HISTSIZE##42} = 21 ] ) > /dev/null 2>&1 ; then
# bash(1)/*ksh(1)?
if [ ${___SHTYPE} -ne ${___SHTYPE_NONE} ]; then
PS1="${ps1s}?\$?[${USER}@${HOSTNAME%%.*} \${PWD##*/}]${PS1}${ps1e} "
else
PS1="${ps1s}[${USER}@${HOSTNAME%%.*}${ps1W}]${PS1}${ps1e} "
fi
else
PS1="${ps1s}[${USER}@${HOSTNAME}]${PS1}${ps1e} "
fi
PS2='> '
export PS1 PS2
|--
|H.Moretto
Hope that helps a bit
--steffen