View Single Post
  #3  
Old 01-21-2014, 04:04 PM
CyrilMtl CyrilMtl is offline
Registered User
 
Join Date: Oct 2010
Posts: 7
my PS1 is :
$ echo $PS1
\[\e]1;\u@\h:\w\007\e]2;\u@\h:\w\007\]\[\033[1m\]\[\033[s\]\[\033[400C\033[16D\]\[\033[38;5;59m\]\[[\]\[\033[38;5;173m\]\[\D{%m/%d} \]\[\033[38;5;167m\]\[\t\]\[\033[38;5;59m\]\[]\]\[\033[u\]\[\033[38;5;221m\]\u\[\033[38;5;59m\]@\[\033[38;5;81m\]\h \[\033[0m\]\[\033[38;5;188m\]\w\[\033[1m\]\[\033[38;5;47m\]\$ \[\033[0m\]

save the cursor position, it put the cursor on the right, back 16 spaces, put the date/time, restore the cursor position, write the basic prompt user, server, parh

On securecrt the cursor position isn't restored to the begin of the line so the prompt is put at the end of the date/time.

(it's on a RHEL6 server, my desktop where I run securecrt is a centos 6)

here is the little bash script if you want to do it :

function prompt_command {
local RETURN_CODE="$?"

local COLOR_P="\033[38;5;"
local COLOR_A="m"
if [ "$TERM" == "fbterm" ] ; then
COLOR_P="\033[1;"
COLOR_A="}"
fi
local SOFT_YELLOW="\[${COLOR_P}221$COLOR_A\]"
local MEDIUM_GRAY="\[${COLOR_P}59$COLOR_A\]"
local SOFT_BLUE="\[${COLOR_P}81$COLOR_A\]"
local LIGHT_GRAY="\[${COLOR_P}188$COLOR_A\]"
local LIGHT_GOLD="\[${COLOR_P}222$COLOR_A\]"
local MEDIUM_ORANGE="\[${COLOR_P}173$COLOR_A\]"
local MEDIUM_RED="\[${COLOR_P}167$COLOR_A\]"
local MEDIUM_GREEN="\[${COLOR_P}47$COLOR_A\]"
local BRIGHT_RED="\[${COLOR_P}196$COLOR_A\]"
local LIGHT_PURPLE="\[${COLOR_P}177$COLOR_A\]"
local RESET="\[\033[0m\]"
local BOLD="\[\033[1m\]"
local SAVE="\[\033[s\]"
local RESTORE="\[\033[u\]"

if [ "$TERM" == "linux" ] ; then
SOFT_YELLOW="\[\033[1;33m\]"
MEDIUM_GRAY="\[\033[1;30m\]"
SOFT_BLUE="\[\033[1;34m\]"
LIGHT_GRAY="\[\033[1;30m\]"
LIGHT_GOLD="\[\033[1;33m\]"
MEDIUM_ORANGE="\[\033[1;33m\]"
MEDIUM_RED="\[\033[1;31m\]"
MEDIUM_GREEN="\[\033[1;32m\]"
BRIGHT_RED="\[\033[1;31m\]"
LIGHT_PURPLE="\[\033[1;35m\]"
fi

local ALIGN_LEFT="\033[1G"
local ALIGN_RIGHT="\033[400C"
local MAKE_SPACE="\033[16D"

local DATE_STRING="\D{%m/%d}"
local TIME_STRING="\t"

local CURRENT_PATH="\w"
if [ -e ~/bin/shorten_pwd ] ; then
CURRENT_PATH=`~/bin/shorten_pwd`
fi

local TITLEBAR=""
case $TERM in
xterm*|*rxvt*|cygwin|interix|Eterm|mlterm|kterm|aterm|putty*)
if [ "${STY}" ] ; then
TITLEBAR="\[\ek\u@\h:$CURRENT_PATH\e\134\]"
else
TITLEBAR="\[\e]1;\u@\h:$CURRENT_PATH\007\e]2;\u@\h:$CURRENT_PATH\007\]"
fi
;;
toaru*)
TITLEBAR="\[\e]1;\u@\h:$CURRENT_PATH\007\]"
;;
screen*)
TITLEBAR="\[\ek\u@\h:$CURRENT_PATH\e\134\]"
;;
esac

local PROMPT_COLOR="$MEDIUM_GREEN"
if [[ ${EUID} == 0 ]] ; then
PROMPT_COLOR="$BRIGHT_RED"
fi

local PROMPT="$BOLD"
PROMPT="$PROMPT$SAVE\[$ALIGN_RIGHT$MAKE_SPACE\]" # Ram the cursor to the right, then back 16 spaces
PROMPT="$PROMPT$MEDIUM_GRAY\[[\]$MEDIUM_ORANGE\[$DATE_STRING \]$MEDIUM_RED\[$TIME_STRING\]$MEDIUM_GRAY\[]\]"
PROMPT="$PROMPT$RESTORE" # Reset the cursor to the left side
PROMPT="$PROMPT$SOFT_YELLOW\u$MEDIUM_GRAY@$SOFT_BLUE\h "

if [[ $RETURN_CODE != 0 ]] ; then
PROMPT="$PROMPT$MEDIUM_RED$RETURN_CODE "
fi

PROMPT="$PROMPT$RESET$LIGHT_GRAY$CURRENT_PATH$BOLD$PROMPT_COLOR\\\$ $RESET"
PS1="$TITLEBAR$PROMPT"
}

export PROMPT_COMMAND=prompt_command
Reply With Quote