?p> To set a prompt that looks like
/usr/users/smith
porthos:smith >
with the first line in bold and the second line as normal text you may use the following definitions in your shell startup files:
For csh, add to your .cshrc file:
set BOLD='^[[1m'
set UNDLN='^[[4m'
set BLREV='^[[5m'
set REV='^[[7m'
set OFF='^[[0m'
set sys = `/bin/hostname | cut -f1 -d.`
alias p 'set prompt="${REV}`pwd`${OFF}
${sys}:${USER} > "'
alias cd 'cd !*; p'
alias chdir 'chdir !*; p'
alias popd 'popd !*; p'
alias pushd 'pushd !*; p'
p
For korn shell, add this to your .profile file:
BOLD='^[[1m'
UNDLN='^[[4m'
BLREV='^[[5m'
REV='^[[7m'
OFF='^[[0m'
sys=`/bin/hostname | cut -f1 -d.`
# if you want to use something other than the real name
[ "$sys" = "porthos" ] && sys="athos"
PS1='${REV}$PWD${OFF}
${sys}:${USER} > '
Note that the character depicted here as '^[' is the escape character, decimal 27, hex 1B. It may be inserted directly using Vi by pressing the keys : ctrl-v, Esc. In Emacs, use ctrl-q, Esc.
----------------------------------------
# .kshrc ( written by B. Miretti in 1999)
#--------------------------------
# display current directory on host writable line for "vt" mode and
# change window name and icon for dtterm.
#)
# Requires the following line in your .profile: # export ENV=$HOME/.kshrc
#--------------------------------
XT_NB="`tput -T dtterm colb7;tput -T dtterm colf0;tput smso`"
XT_RN="`tput -T dtterm colb0;tput -T dtterm colf1;tput smso`"
XT_NG="`tput -T dtterm colb2;tput -T dtterm colf0;tput smso`"
XT_NY="`tput -T dtterm colb3;tput -T dtterm colf0;tput smso`"
XT_NC="`tput -T dtterm colb6;tput -T dtterm colf0;tput smso`"
SPC=" "
XT_ON="\033[2$~\033[1$}\r${XT_NB}"
XT_OFF="${SPC}${SPC}${SPC}${SPC}\033[m\033[K\033[0$}"
#--------------------------------
# Note: KSHRC_VERSION is defined at your convenience in
# the .profile file or let blank
# Example: # export KSHRC_VERSION="`sizer -v|awk '{print $4}'` "
#-------------------------------
function _cd
{
'cd' $1
if test "`tty`" != "not at tty"
then
CLUNAME=`sysconfig -q clubase
2>/dev/null|grep ^cluster_name|awk '{print $3}'`
HOSTNAME="`hostname -s`${CLUNAME:+($CLUNAME)}"
case "${TERM}"
in
"dtterm")
echo "\033]0;${USER}@${HOSTNAME} on ${PWD}\007\c"
;;
vt*)
CONS="";test "`tty`" = "/dev/console" &&
CONS="${XT_RN}*CONSOLE*${XT_NB} "
echo "${XT_ON}${CONS}${KSHRC_VERSION}$USER@${HOSTNAME} on \c"
test -L $PWD && echo "${XT_NC}-> \c"
if test -w ${PWD}
then
echo "${XT_NG}${PWD}${XT_OFF}\c"
else
echo "${XT_NY}${PWD} (ro)${XT_OFF}\c"
fi
;;
esac
fi
} typeset -fx _cd
alias -x cd=_cd
alias cd..='cd ..'
function Display_Last
{ last=`fc -lnr|head -1`
CLUNAME=`sysconfig -q clubase 2>/dev/null|grep ^cluster_name|awk '{print 3}'`
HOSTNAME="`hostname -s`${CLUNAME:+($CLUNAME)}" case "${TERM}"
in
"dtterm")
echo "\033]0;${USER}@${HOSTNAME} executing { `echo $last` }\007\c"
;;
vt*)
test "`tty`" = "/dev/console" &&
CONS="${XT_RN}*CONSOLE*${XT_NB} " || CONS=""
echo "${XT_ON}${CONS}${KSHRC_VERSION $USER@${HOSTNAME} executing
${XT_NC}{ `echo $last` }${XT_OFF}\c"
;;
esac
}
function _login
{
trap '_cd . ' 1 2 9 14 15 17
Display_Last
'login' $*
_cd .
}
typeset -fx _login
alias -x login=_login
function _rlogin
{
trap '_cd . ' 1 2 9 14 15 17
Display_Last
'rlogin' $*
_cd .
}
typeset -fx _rlogin
alias -x rlogin=_rlogin
function _setld
{
trap '_cd . ' 1 2 9 14 15 17
Display_Last
'setld' $*
_cd .
}
typeset -fx _setld
alias -x setld=_setld
function _te.net
{
trap '_cd .' 1 2 9 14 15 17
Display_Last
'telnet' $*
_cd .
}
typeset -fx _telnet
alias -x telnet=_telnet
# Note: sometimes the su command does not work when aliased
# Should remove the aliasing in case of issue.
function _su
{
trap '_cd . ' 1 2 9 14 15 17
Display_Last
'su' $*
_cd .
}
typeset -fx _su
alias -x su=_su
function _tip
{
trap '_cd . ' 1 2 9 14 15 17
Display_Last
tip $*
_cd .
}
typeset -fx _tip
alias -x tip=_tip
set -o emacs
cd .
-----------------------------
延伸阅读
文章来源于领测软件测试网 https://www.ltesting.net/