0

I was able to create a Windows Command Prompt that automatically changes its text color on a white background every ~1.5 seconds, thanks to the help of @dbenham and @Woody. I also use PuTTY every day, almost more than Windows Command Prompt, so for fun I would also like to figure out how to do the same thing in PuTTY, no matter which server I connect to (therefore, hopefully there's a way for auto-change-text-color.bat to be read locally instead of having to be put it on whatever server I connect to). All the servers I connect to are Linux distributions via SSH.

My Windows Command Prompt solution is here: https://superuser.com/a/700041/210421 (And here's a quick GIF I made to show what it's doing: http://i.minus.com/iZC4WapYtRVad.gif)

Is there a way to do this via PuTTY with Linux? Could I make a (possibly modified) version of this batch file, or maybe a perl script run in the background of every PuTTY session I open up? I have 10 saved SSH connections, and many more will be added in the future. So if there is a way to make PuTTY find the color-changing .bat file locally instead of having to put the file on every server, that would be very convenient. A solution where I have to place it on every server would also be helpful if that is the only way.

If not with PuTTY, maybe with another common SSH client?

Thank you for any help!

The Windows solution is also quoted here:


I ended up using this as my auto-change-text-color.bat command, because I ended up wanting just the text to change, and got rid of some colors that didn't look well with a white background:

@echo off
:loop
set NUM=1 2 3 4 5 6 8 9 A B C D
for %%x in (%NUM%) do ( 
    color F%%x
    >nul ping localhost -n 4
)
goto loop

As for my Windows Command Prompt shortcut, it starts in my development directory, and the "Target" is:

%COMSPEC% /t:F9 /s /k cd scripts && start /b %COMSPEC% /c auto-change-text-color.bat <nul && cd .. && env

It opens up in my development environment's script directory, runs the color changing script in the background that is stored in my scripts folder, then goes back to the parent folder and runs another batch file setting all my environment variables. It's perfect.


2
  • I guess you could stay within conhost (Windows' default terminal emulator) and just use your batch script with pscp, instead of the main PuTTY executable with its own terminal.
    – Bob
    Aug 3, 2014 at 16:16
  • If the ping command is meant as a delay, try using timeout /t 2 >nul in its place. And pray tell, why do you do this at all? Too much free time?
    – uSlackr
    Aug 3, 2014 at 20:41

1 Answer 1

1

You can do this two ways.

First, and perhaps easiest, set the colors in PuTTy from the configuration

enter image description here

Your second option is to write colors into .bashrc.

This is what I use (in .bashrc)

################################
### Colors ###
################################

BLACK='\e[0;30m'
BLUE='\e[0;34m'
GREEN='\e[0;32m'
CYAN='\e[0;36m'
RED='\e[0;31m'
PURPLE='\e[0;35m'
BROWN='\e[0;33m'
LIGHTGRAY='\e[0;37m'
DARKGRAY='\e[1;30m'
LIGHTBLUE='\e[1;34m'
LIGHTGREEN='\e[1;32m'
LIGHTCYAN='\e[1;36m'
LIGHTRED='\e[1;31m'
LIGHTPURPLE='\e[1;35m'
YELLOW='\e[1;33m'
LIGHTYELLOW='\e[0;33m'
WHITE='\e[1;37m'
NC='\e[0m' # No Color


# Set Less Colors for Man Pages
if [ -x /usr/bin/less ]; then
export LESS_TERMCAP_mb=$'\E[01;31m' # begin blinking
export LESS_TERMCAP_md=$'\E[01;38;5;74m' # begin bold
export LESS_TERMCAP_me=$'\E[0m' # end mode
export LESS_TERMCAP_se=$'\E[0m' # end standout-mode
export LESS_TERMCAP_so=$'\E[38;5;246m' # begin standout-mode - info box
export LESS_TERMCAP_ue=$'\E[0m' # end underline
export LESS_TERMCAP_us=$'\E[04;38;5;146m' # begin underline
fi

# NEW. FANCY PROMPT
if [[ $EUID == 0 ]] ; then
PS1='\[\033[01;31m\]\u\[\033[01;30m\]@\[\033[01;34m\]\h\[\033[01;30m\]:\[\033[01;34m\]\w\[\033[00m\]\$' #RED
else
PS1='\[\033[01;32m\]\u\[\033[01;30m\]@\[\033[01;34m\]\h\[\033[01;30m\]:\[\033[01;34m\]\w\[\033[00m\]\$' #Green

# PS1='\[\033[01;34m\]\u\[\033[01;30m\]@\[\033[01;34m\]\h\[\033[01;30m\]:\[\033[01;34m\]\w\[\033[00m\]\$' #Blue
fi

See also https://wiki.archlinux.org/index.php/Color_Bash_Prompt

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .