help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: colored verbose


From: alex xmb sw ratchev
Subject: Re: colored verbose
Date: Wed, 8 Nov 2023 12:00:47 +0100

i thought of two ways
i think the better third is a $PS1/2/3 style var ( that i dunno )

thers the script , also as attachment

arg 1 is exec stderr to awk to display by $b ( begin ) and $e ( end ) ansi
escape code strings , sorry im still not with tput codes
then set -x
then test cmds , then cleanup , echo bye , and exit 0
.. this displays for me on termux the cmds in the end

bash bs3 1
foo
1
2
3
bye
+ run1
+ run
+ echo foo
+ seq 3
+ set +x

in maybe bold and maybe reverse ..

arg 2 is trap ' echo use $BASH_COMMAND ' trap
but all that trap ever outputs , is the ' run2 ' function , no subcmds
.. i dunno why

forgot to printf to >&2

bash bs3 2
run2
foo
1
2
3
bye


script

b=$'\e[0;1;7m' e=$'\e[0m'

#shopt -s expand_aliases
# alias run_debug='
#echo foo
#seq 3
# '

 run() {
echo foo
seq 3
 }

 out() {
printf bye\\n
exit 0
 }

 run1() {
run
set +x
exec 2<&3 3<&-
out
 }

 run2() {
#run_debug
run
trap "$bef" debug
out
 }

    case $1 in
   stderr|1)
  exec 3<&2 2> >(
awk -vb="$b" -ve="$e" ' {
print b $0 e
 } '
  )
set -x
run1
   ;;
   debug|2)
bef=$( trap debug )
trap ' printf "$b%s$e\n" "$BASH_COMMAND" ' debug
run2
   ;;
    esac


On Wed, Nov 8, 2023, 11:27 AM lacsaP Patatetom <patatetom@gmail.com> wrote:

> hi,
>
> is it possible to distinguish the lines displayed by bash's verbose mode by
> coloring them ?
>
> for example, with this little script, make the first and third displayed
> lines stand out by coloring them :
>
> bash -v <<~~~
> echo hello world
> seq 5
> ~~~
> echo hello world
> hello world
> seq 5
> 1
> 2
> 3
> 4
> 5
>
> I can color script comments by adding control characters (#\[1;34m colored
> comment\[0m) that are executed when a comment is displayed, but it's not
> very practical or aesthetic...
>
> regards, lacsaP.
>

Attachment: bs3
Description: Binary data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]