Yes, you can. As it is i once wrote a script function to make that easier, here it is:
Code :
# ------------------------------------------------------------------------------
# f_SetTerminalSequences set terminal sequences according to TERMCAP db
# ------------------------------------------------------------------------------
# Author.....: Wolf Machowitsch, Quest
# last update: 1998 11 27 by: Konstanze Scholz, IBM
# ------------------------------------------------------------------------------
# Revision history:
# - 0.99 1998 10 21 Original Creation
# Setting and resetting the attributes should be
# worked on.
#
# - 1.00 1998 11 27 Production Release
# elaborated on the documentation and replaced the
# TERMCAP sequences to ANSI-esc-Sequences. See note
# below.
#
# - 1.10 1998 11 27 Production Release
# Added checks for the variables
# o ANIMATED (= bold,blink,underscore,..)
# o COLOURED (= coloured animation)
# o COLORED (same as COLOURED)
#
# ------------------------------------------------------------------------------
# Usage:
# USAGE:
# f_SetTerminalSequences( <void> ) ==> <void>
#
# SYNOPSIS:
# f_SetTerminalSequences initializes and exports variables to
# make use of the terminals highlighting capabilities such as
# different colours, bold/underlined output, etc..
# f_SetTerminalSequences accepts no parameters and returns no
# meaningful return codes.
#
# CAVEAT:
# This function relies on the TERMCAP database, therefore it
# cannot be guaranteed that the settings all work correct with
# any terminal. This holds true especially for IBM systems -
# Big Mama Blue just can't get the TERMCAP correct.
#
# NOTE: explanation of colour setting sequences
# Colours are set via a 3-bit 'status nybble' in which the basic
# colours (blue, green, red) are turned on or off by setting their
# respective bits to 1 or 0. The resulting values are added and
# converted to a decimal number to give the number of the colour.
# The following table shows the connection between colour numbers
# and colours:
#
# dec. bin. colour
# | | | 0 ^= 000 ^= black
# | | | 1 ^= 001 ^= red
# blue green red 2 ^= 010 ^= green
# | | | 3 ^= 011 ^= brown (== green+red)
# | | +---- 1/0 * (2**0) 4 ^= 100 ^= blue
# | +---------- 1/0 * (2**1) 5 ^= 101 ^= magenta (== blue+red)
# +---------------- 1/0 * (2**2) 6 ^= 110 ^= cyan (== blue+green)
# 7 ^= 111 ^= white(== blue+green+red)
#
# In case of a (coloured) XTerm, AIXTerm, etc. these colours are added to
# the windows settings provided to the X11. Therefore 'white' does not
# necessarily mean a RGB-value of /FF/FF/FF, but a considerably lighter
# colour than 'black' (i.e. "white added to the basic colour scheme of the
# underlying term").
#
# Prerequisites:
# - The FPATH environment variable must be set to use this function.
#
# ------------------------------------------------------------------------------
# Known Bugs:
# The TERMCAP entries for AIXTerm and XTerm under AIX are crap.
# Therefore we use the (in theory not so common) ESC-sequences
# here instead of the term capabilities (I've tried them and
# commented them out, you are free to retry again.) to get the
# standout modes. They are left here in comments because *in
# theory* this would be the preferable way.
#
# For the hardboiled EMACS user i have even gone so far as to put
# folding mode sequences into it. How low can one sink i wonder...
# ------------------------------------------------------------------------------
# ......................(C) 98 Wolf Machowitsch ................................
# ------------------------------------------------------------------------------
f_SetTerminalSequences ()
{
if [ -n "$ANIMATED" -o -n "$COLOURED" -o -n "$COLORED" ] ; then
# {{{ terminal sequences for bold,italic,...
# -------------------------------------- TERMCAP text attributes
# export _N="$(print $(tput rmso;tput rmul) )" # switch to normal video
# export _B="$(print $(tput bold) )" # switch to bold video
# export _U="$(print $(tput smul) )" # switch to underlined video
# export _F="${ESC}[5m" # switch to blinking video
# export _R="$(print $(tput rev) )" # switch to reverse video
# ------------------------------------ text attributes the ANSI way
typeset ESC=" " # ATTENTION! this is a
# quoted ESC-char!!
export _N="${ESC}[0m" # switch to normal video
export _B="${ESC}[1m" # switch to bold video
export _U="${ESC}[4m" # switch to underlined video
export _F="${ESC}[5m" # switch to blinking video
export _R="${ESC}[7m" # switch to reverse video
# }}}
if [[ -n "$COLOURED" || -n "$COLORED" ]] ; then
# {{{ terminal sequences for coloured animation
# ---------------------------------------------- colours
export ColBgBlack=$(print $(tput colb0) ) # background colour 0 => black
export ColBgRed=$(print $(tput colb1) ) # background colour 1 => red
export ColBgGreen=$(print $(tput colb2) ) # background colour 2 => green
export ColBgBrown=$(print $(tput colb3) ) # background colour 3 => brown
export ColBgBlue=$(print $(tput colb4) ) # background colour 4 => blue
export ColBgMagenta=$(print $(tput colb5) ) # background colour 5 => magenta
export ColBgCyan=$(print $(tput colb6) ) # background colour 6 => cyan
export ColBgWhite=$(print $(tput colb7) ) # background colour 7 => white
export ColFgBlack=$(print $(tput colf0) ) # foreground colour 0 => black
export ColFgRed=$(print $(tput colf1) ) # foreground colour 1 => red
export ColFgGreen=$(print $(tput colf2) ) # foreground colour 2 => green
export ColFgBrown=$(print $(tput colf3) ) # foreground colour 3 => brown
export ColFgBlue=$(print $(tput colf4) ) # foreground colour 4 => blue
export ColFgMagenta=$(print $(tput colf5) ) # foreground colour 5 => magenta
export ColFgCyan=$(print $(tput colf6) ) # foreground colour 6 => cyan
export ColFgWhite=$(print $(tput colf7) ) # foreground colour 7 => white
# ---------------------------------------------- compatibility layer
export _bgd=$ColBgBlack
export _bgr=$ColBgRed
export _bgg=$ColBgGreen
export _bgy=$ColBgBrown
export _bgb=$ColBgBlue
export _bgc=$ColBgMagenta # these two lines were mixed
export _bgm=$ColBgCyan # up in the original by TW
export _bgbg=$ColBgWhite
export _fgd=$ColFgBlack
export _fgr=$ColFgRed
export _fgg=$ColFgGreen
export _fgy=$ColFgBrown
export _fgb=$ColFgBlue
export _fgc=$ColFgMagenta # these two lines were mixed
export _fgm=$ColFgCyan # up in the original by TW
export _fgbg=$ColFgWhite
# }}}
fi
else
# {{{ reset all variables containing escape sequences
export _N="" _B="" _U="" _F="" _R=""
export _bgd="" _bgr="" _bgg="" _bgy="" _bgb="" _bgc="" _bgm="" _bgbg=""
export _fgd="" _fgr="" _fgg="" _fgy="" _fgb="" _fgc="" _fgm="" _fgbg=""
# }}}
fi
return 0
}
One thing to keep in mind: the ESC-char does not survive copy&paste. You will have to enter it after saving this to a file. Enter "CTRL-V" in vi to quote the next character, then press the ESC key to enter the escape character.
I hope this helps.
bakunin