Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.debian.user > #239712

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

From Greg Wooledge <greg@wooledge.org>
Newsgroups linux.debian.user
Subject Re: Why ``color_prompt`` is only set for ``xterm``? (colored prompt examples)
Date 2021-09-05 15:10 +0200
Message-ID <CU04i-1ex-13@gated-at.bofh.it> (permalink)
References <CT562-5UL-1@gated-at.bofh.it> <CT6v8-6FH-3@gated-at.bofh.it> <CTnvY-1kV-7@gated-at.bofh.it> <CTST8-53d-5@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


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.

Back to linux.debian.user | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Why ``color_prompt`` is only set for ``xterm``? IL Ka <kazakevichilya@gmail.com> - 2021-09-03 02:20 +0200
  Re: Why ``color_prompt`` is only set for ``xterm``? David Wright <deblis@lionunicorn.co.uk> - 2021-09-03 02:40 +0200
    Re: Why ``color_prompt`` is only set for ``xterm``? Nicholas Geovanis <nickgeovanis@gmail.com> - 2021-09-03 03:10 +0200
    Re: Why ``color_prompt`` is only set for ``xterm``? piorunz <piorunz@gmx.com> - 2021-09-03 03:50 +0200
      Re: Why ``color_prompt`` is only set for ``xterm``? Mark Neyhart <Mark.Neyhart@akleg.gov> - 2021-09-03 22:00 +0200
        Re: Why ``color_prompt`` is only set for ``xterm``? (colored prompt examples) Intense Red <intnsred@golgotha.net> - 2021-09-05 07:30 +0200
          Re: Why ``color_prompt`` is only set for ``xterm``? (colored prompt examples) Cindy Sue Causey <butterflybytes@gmail.com> - 2021-09-05 14:20 +0200
          Re: Why ``color_prompt`` is only set for ``xterm``? (colored prompt  examples) Greg Wooledge <greg@wooledge.org> - 2021-09-05 15:10 +0200
            Re: Why ``color_prompt`` is only set for ``xterm``? (colored prompt examples) Cindy Sue Causey <butterflybytes@gmail.com> - 2021-09-05 15:40 +0200
              Re: Why ``color_prompt`` is only set for ``xterm``? (colored prompt  examples) Greg Wooledge <greg@wooledge.org> - 2021-09-05 15:50 +0200
      Re: Why ``color_prompt`` is only set for ``xterm``? David Wright <deblis@lionunicorn.co.uk> - 2021-09-05 06:30 +0200
        Re: Why ``color_prompt`` is only set for ``xterm``? Greg Wooledge <greg@wooledge.org> - 2021-09-05 15:10 +0200
          Re: Why ``color_prompt`` is only set for ``xterm``? David Wright <deblis@lionunicorn.co.uk> - 2021-09-07 17:10 +0200
    Re: Why ``color_prompt`` is only set for ``xterm``? Nate Bargmann <n0nb@n0nb.us> - 2021-09-05 18:50 +0200
    Re: Why ``color_prompt`` is only set for ``xterm``? Andrei POPESCU <andreimpopescu@gmail.com> - 2021-09-07 20:40 +0200

csiph-web