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

Re: Why ``color_prompt`` is only set for ``xterm``? (colored prompt examples)



On 9/5/21, Greg Wooledge <greg@wooledge.org> wrote:
> On Sun, Sep 05, 2021 at 12:28:37AM -0500, Intense Red wrote:
>> > In /root/.bashrc I use this to give a red prompt including host and
>> > full path followed by a new line.
>>
>>    I take this idea a bit further, setting a longer prompt and setting
>> workstation hosts for specific colors for user logins, and then doing a
>> red
>> prompt for servers.
>>
>>    Part of my ~/.bashrc:
>>
>> # Set the hostname to a specific color
>> HostName=`hostname -s`
>> if [ $HostName = "capncrunch" ]; then
>>    HostColor="\[\033[1;36m\]" # Bright Cyan
>>  elif [ $HostName = "piglet" ]; then
>>    HostColor="\[\033[1;35m\]" # Bright Purple
>>  elif [ $HostName = "wiseguy" ]; then
>
> Not a big fan of case statements?
>
> HostName=${HOSTNAME%%.*}
> case $HostName in
>   capncrunch) HostColor="\[\033[1;36m\]";; # Bright Cyan
>   piglet)     HostColor="\[\033[1;35m\]";; # Bright Purple
>   ...
> esac
>
> Also, for the record, your quotes are in the wrong place in your [
> commands.  You need quotes around "$HostName" to avoid globbing and
> word splitting.  You don't need quotes around simple strings like
> capncrunch and piglet, unless one of them contains whitespace or
> punctuation that's significant to the shell.
>
> The missing quotes around "$HostName" have never mattered because so
> far all of your hostnames have been safe.  Maybe that's even a
> guarantee -- I'm not sure what characters are actually allowed in a
> Linux hostname.  But quoting correctly still a good habit to get into.


Thank you for the tweak, Greg. That's a biggie because along the way,
we've seen how things change and fail for that very reason. One of my
partitions' terminal root now calls itself by a package name. NO CLUE
how it happened because I wasn't root while the associated package was
being extracted. Confirming placement of quotation marks, if used,
would be one checkpoint for a massive fail like that.

There's also that thing about how terminals will interpret the
different types of quotes (dumb/typewriter/ASCII versus
typographic/curly/smart) very literally. I experienced THAT fail
firsthand and now try to remember to plug anything I copy into a plain
text editor before then recopying over to a terminal.

Am wondering if, am more like hoping that this quotation marks part of
it would have stood out when I research how to further customize my
own setup. This will be a priceless personalization if I can
eventually coerce it to say "(debootstrap) chroot" in place of some of
the characters there. Shh, don't tell me how. Lead a fish to water,
yada-yada. :)

Cindy :)
-- 
Cindy-Sue Causey
Talking Rock, Pickens County, Georgia, USA
* runs with birdseed *


Reply to: