Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: can this be done?



Soren Dayton <csdayton@xxxxxxxxxxxxxxxxxxx> wrote:

>Could you do something like display the current command line in a color?
>Note that this is _only_ the current line.

Here's my color prompt stuff again.

Current command line is in cyan.
POSTEDIT is set to turn text back to white afterwards...

--cut--
if [[ "$USE_COLOR" = "" ]] && [[ "$TERM" != "sun" ]]
then
  export USE_COLOR=yes
else
  export USE_COLOR=${USE_COLOR:-no}
fi

#
# Prompt stuff
#
PS2='%(4_.\.\.\. .)%3_> %E'

function precmd
{
  # Look at exit status of last command - attach appropriate signal
  # if it was a signal that caused it.
  local exitstatus=$? 
  if [[ $exitstatus -ge 128 ]]
  then
    psvar[1]=" $signals[$exitstatus-127]"
  else
    psvar[1]=""
  fi
  if [[ -o interactive ]]
  then
    jobs -l
  fi
}

HOSTVER=`uname -r`
[[ $HOSTTYPE = sun4 || $HOSTTYPE = solaris2.3]] && HOSTARCH=`arch -k` || 
HOSTARC
H=$HOSTTYPE

function prompt-mode ()
{
  case $1
  {
    all | ALL | on | ON)
        prompt="$date_prompt
$dir_prompt
$main_prompt" ;;
    dir | DIR)
        prompt="$dir_prompt
$main_prompt" ;;
    date | DATE)
        prompt="$date_prompt
$main_prompt" ;;
    off | OFF)
      prompt="$main_prompt" ;;
  right|RIGHT)
    RPS1="$right_prompt";;
  noright|NORIGHT)
    RPS1="";;
    *)
      echo "Syntax : $0 [on|off|all|dir]
  on|all : Turn on the full prompt.
  dir    : Show the current directory line.
  date   : Show the date line.
  off    : history line only.
  right : turn on right prompt.
  noright : turn off right prompt" ;;
  }
}
alias prm=prompt-mode

if [[ $USE_COLOR = yes ]]
then
 ]] && export COLOR_HILIT="1;"
[[ $TERM = vs100 ]]  && unset COLOR_HILIT
date_prompt="%{ESC[${COLOR_HILIT}31m%}[%{ESC[36m%}%D{%a %y/%m/%d %R 
%Z}%{ESC[31m
%}][%{ESC[32m%}tty%l%{ESC[31m%}][%{ESC[36m%}${HOSTARCH}/${HOSTVER}%{ESC[31m%}]"
dir_prompt="%{ESC[${COLOR_HILIT}31m%}<%{ESC[32m%}%n@%m%{ESC[37m%}:%{ESC[33m%}%~
%
{ESC[31m%}>%{ESC[0m%}"
main_prompt="%{ESC[0m%}zsh%(2L./$SHLVL.) %B%h%b %(?..[%?%v] )%B%#%b 
%{ESC[0;36m%
}"

POSTEDIT="ESC[37;0m"

right_prompt="[%T]"
else
date_prompt="[%B%D{%a %y/%m/%d %R %Z}%b][tty%l][%B${HOSTARCH}/${HOSTVER}%b]"
dir_prompt="<%B%n@%m:%~%b>"
main_prompt="zsh%(2L./$SHLVL.) %B%h%b %(?..[%?%v] )%B%#%b "

right_prompt="[%T]"
fi

prompt-mode off
prompt-mode right

if [[ "$TERM" = "emacs" ]]
then
  export USE_COLOR=no
  prompt="%n@%m:%~
zsh(emacs) %h %(?..[%?%v] )%# "
fi
--end--

Enjoy,
 Andrew.
 - Andrew J. Cosgriff - andrew@xxxxxxxxxxxx - SysAdmin, UNICO Computer Systems.
 email fileserver : "send file help" as subject        PGP, MIME ok & preferred
"There are ten million stories in the Naked City, but no-one can remember
 which one is theirs..." (Laurie Anderson)

 - Andrew J. Cosgriff - andrew@xxxxxxxxxxxx - SysAdmin, UNICO Computer Systems.
 email fileserver : "send file help" as subject        PGP, MIME ok & preferred
"There are ten million stories in the Naked City, but no-one can remember
 which one is theirs..." (Laurie Anderson)




Messages sorted by: Reverse Date, Date, Thread, Author