I know this is kindof crazy. I like to get crazy.
I have a local log colorizing bash function that I wrote. I decided as an experiment that I want to try to use it to colorize the output when I ssh into a server and run less
on one of the logs. I can do this successfully with tail
, but not with less
. Is there a way to use my bash function locally to colorize the less output being returned through ssh? This is what I have tried:
function colorwrap {
while read -r line; do
echo "$line" | colorlog
#printf "$line" | colorlog
done < <("$@")
}
Invoking it like so:
colorwrap ssh -t servername -C less /logs/server.log
With echo
it seems to work a little bit. I can scroll up and down with j
, k
, etc. but things like search and :
don't show up on the screen. But I can quit via :q
even if I can't see it. Also, the colorizing works. But the scrolling is choppy and it's hard to do searches. I'm not even sure it is doing the searches I try to do.
I don't really understand how the control commands work, but I'm guessing it has something to do with terminal allocation and/or echo not interpreting correctly control characters.
Any tips on how to make this work? Or alternative *nix tools that can be used locally to wrap an interactive program running remotely?