Changing Your Bash Shell Prompt and Colors
I enjoyed the opportunity to test out my PASS Summit shell scripting session at SQL Saturday Denver. It was the first run on it and Glenn Berry sat in my session. Afterwards, this wise and long-standing member of the community had a very valuable piece of constructive criticism- change the background on my bash terminal for Azure Cloud Shell, as the black background and colors could be troublesome for some attendees.
I agree with him- you never know what the projector quality will be, the lighting in the room, color-blind attendees or other factors that could impact the readability of the demonstration when you have a black background and colored text. I realized, as the Azure Cloud Shell is a service, we have less control of the terminal offered to us, so it was important to tell people how to update their Azure Cloud Shell to change the execution prompt to not be in color and highlight the background in white, with black text bolded for easier reading.
Changing the Azure Cloud Shell Run Commands
Log into your Azure Cloud Shell using the BASH shell interface, (not Powershell, this isn’t the session for that! :))
We’ll need to edit the bash run commands file, also known as .bashrc.
view .bashrc
Using VIM commands on your keyboard, use the “j” key to go down till you see the following lines and use the “#” sign to comment out the lines you see I’ve commented out below. Replace the current PS1 line, (alias for your execution line) with the one I’ve added, which will update the following:
- Change the prompt to be your username
- Change the background of the text on that line to white
- Remove color and change the text to BOLDED black text for prompt
#if [ -n "$force_color_prompt" ]; then # if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then # We have color support; assume it's compliant with Ecma-48 # (ISO/IEC-6429). (Lack of such support is extremely rare, and such # a case would tend to support setf rather than setaf.) # color_prompt=yes # else # color_prompt= # fi #fi #if [ "$color_prompt" = yes ]; then # PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m \]\$ ' #else # PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ ' # Want to have it bold instead PS1="\[\033[47m\]\[\033[1;30m\]\u:\w\$ " #fi #unset color_prompt force_color_prompt
Create a Profile
export PS1="\[\033[47m\]\[\033[1;30m\]\u:\w\$ "
~/.profile_p
- PS1= the first prompt line
- 33= textsize
- 47m= white background
- 1;30m=bold; black text, (and the 1 is not bold for every Linux distribution, so if you experience something different, lucky you, you get to look up what it is for your “flavor”!)
- u=username