LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   on: customizing root's shell prompt (https://www.linuxquestions.org/questions/slackware-14/on-customizing-roots-shell-prompt-4175470500/)

textillis 07-22-2013 09:28 AM

on: customizing root's shell prompt
 
Salve Slackers,

Encouraged by some humble customization of my user shell prompt (encouraged in that I did not break anything in the act) I took my heart in my hands and made a:
  1. - /root/.bashrc; and a
  2. -/root/.bash_profile; and then

I configured my root prompt to my fancy.

Questions:
  1. -is their anything unconventional and/or shoddy about this solution to making my root prompt purty; and
  2. -how do I colour elements of same, to make it even purtier?

That is, how do I edit this:
root\@\h:\w
so that "root" becomes root, for instance?

Ygrex 07-22-2013 09:51 AM

Code:

PS1='\[\033[01;31m\]root\[\033[00m\]\@\h:\w'

textillis 07-22-2013 10:50 AM

Ah, that has given me St.Petersburg time, with root looking like this:
]root, in orange, not red :)

But thanks anyway: could you tell me where the colorschema is stored?

octoberblu3 07-22-2013 11:24 AM

http://ascii-table.com/ansi-escape-sequences.php

textillis 07-22-2013 01:16 PM

Thanks octoberblu3!

kikinovak 07-22-2013 01:21 PM

Here's my ~/.bashrc:

Code:

if [ "$PS1" ]; then

  # Colored output for 'ls'
  eval `dircolors -b`
  alias ls='ls --color=auto'

  # Some more aliases
  alias ll='ls -al'
  alias ..='cd ..'
  alias ...='cd ../..'
  alias cp='cp -i'
  alias rm='rm -i'
  alias mv='mv -i'
  alias vi='vim'

  # Screencast
  alias screencast='recordmydesktop \
                      --width 1280 \
                      --height 1024 \
                      --v_bitrate 2000000 \
                      --s_quality 10 \
                      -o ~/Vidéos/Captures/Capture.ogv \
                      --overwrite \
                      --pause-shortcut Control+Mod1+p \
                      --stop-shortcut Control+Mod1+space \
                      --delay 10'

  # Command prompt for users
  GREEN='\[\033[0;32m\]'
  WHITE='\[\033[1;37m\]'
  NC='\[\033[0;m\]'
  PS1="$GREEN[$WHITE\u$NC@$WHITE\h$NC:$WHITE\w$GREEN] \$ $NC"

  # Vim is our preferred editor
  EDITOR=vim
  VISUAL=$EDITOR
  export EDITOR VISUAL

  # Needed by libcanberra
  if [ -z "$GTK_MODULES" ] ; then
    GTK_MODULES="canberra-gtk-module"
  else
    GTK_MODULES="$GTK_MODULES:canberra-gtk-module"
  fi
  export GTK_MODULES

fi

And here's /root/.bashrc:

Code:

if [ "$PS1" ]; then

  # Colored output for 'ls'
  eval `dircolors -b`
  alias ls='ls --color=auto'

  # Some more aliases
  alias ll='ls -al'
  alias ..='cd ..'
  alias ...='cd ../..'
  alias cp='cp -i'
  alias rm='rm -i'
  alias mv='mv -i'
  alias vi='vim'
  alias uman='GROFF_ENCODING=utf8 man'

  # Command prompt for root
  WHITE='\[\033[1;37m\]'
  RED='\[\033[0;33m\]'
  NC='\[\033[0m\]'
  PS1="$RED[$WHITE\u$NC@$WHITE\h$NC:$WHITE\W$RED] #$NC "

  # Vim is our preferred editor
  EDITOR=vim
  VISUAL=$EDITOR
  export EDITOR VISUAL

fi

Notice the differently coloured prompts for root and "normal" users.

Diantre 07-22-2013 01:31 PM

More info on bash prompts:

http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/index.html

fogpipe 07-22-2013 01:47 PM

These are what i use:

for root:
PS1="[\[\033[1;31m\]\u\[\033[1;31m\]@\[\033[1;34m\]\h\[\033[1;31m\]\[\033[0;32m\]\[\033[1;35m\]:\W\[\033[0m\]]\[\033[0;31m\]#\[\033[0m\]"


for users:
PS1="[\[\033[1;32m\]\u\[\033[1;31m\]@\[\033[1;34m\]\h\[\033[1;31m\]\[\033[0;32m\]\[\033[1;35m\]:\W\[\033[0m\]]\[\033[0;31m\]$\[\033[0m\]"


This is so that "root" appears in red and users in some other color. I also use different colors for the hosts on my home network as a visual cue for where i am.

sycamorex 07-22-2013 01:50 PM

Slightly late to the game, but here you can also find some info about colourful prompts.

HTH

astrogeek 07-22-2013 03:21 PM

I make all root prompts red on all my boxes, and white (actually light grey) for all non-root local logins.

But I spend a lot of time SShd into other boxes on my local net and a few remote machines, so I color prompts for all remote logins by including something like this in all my .bashrc's:

Code:

#Make prompt colored when logged in remote
export NON_LOCAL_LOGIN=`env | grep SSH`
if [ "$NON_LOCAL_LOGIN" != "" ]; then
      PS1="\033[33m[\u@\h:\w]#\033[0m "
fi;

I also use different colors for different machines so I can spot most of them by color.

So if I see color, I am remote, local if white or always root if red.

Gerard Lally 07-22-2013 04:44 PM

This is what I use for the Korn shell in Slackware and NetBSD:

Code:

case $LOGNAME in
    root)
        PS1='$(print "------------------------------------------------------------------------\n";
print -n "`hostname -f`\n[!]";
if [[ "${PWD#$HOME}" != "$PWD" ]] then;
 print -n "[~${PWD#$HOME}]";
 else;
 print -n "[$PWD]";
fi;
print "\n[`whoami`]# ")' ;;
    *)
        PS1='$(print "------------------------------------------------------------------------\n";
print -n "`hostname -f`\n[!]";
if [[ "${PWD#$HOME}" != "$PWD" ]] then;
print -n "[~${PWD#$HOME}]";
else;
print -n "[$PWD]";
fi;
print "\n[`whoami`]$ ")' ;;
esac
export PS1

It gives me a prompt like one of those below, with dividers on the first line, FQDN on the second, job number and path on the third, and username and prompt on the fourth. I like it like this because I immediately know what machine I am logged into, and a long path does not interfere with the prompt. Although colour is not available I can also quickly check whether or not I am root. Feel free to recommend improvements as I remain an amateur at the shell.

Code:

------------------------------------------------------------------------
slackware.home.local
[10][/usr/local/share/emacs/24.3/etc/]
[gerard]$ su -
Password:
------------------------------------------------------------------------
slackware.home.local
[15][~]
[root]# pwd
/root


textillis 07-23-2013 03:11 AM

Niki
 
Thanks for sharing your .bashrc.

Helps a lot.

Got it looking nice now.

textillis 07-23-2013 03:16 AM

Gezley
 
Thanks man: you are way down the track from me, though I can see you waving off in the distance; if I get a leg up on shell scripting in a hurry, I'll be sure to post a schmick looking .bashrc back here.

Nice looking shell prompt.

thanks again ...

textillis 07-23-2013 03:27 AM

Astrogeek
 
Yeah, I like root in red.

I'm still wrestling with the scripting side of things: never coded anything in my life (still can't program a DVD player)

And I observe that I am surrounded in here -wall-to-wall- by programmers and developers or simply "geek-extraordinaires" ... but fortunately for me there is nothing cliquey or snooty about this forum. So I feel very welcome, you know, part of "the team", but like a dumb little Staffordshire pup, playing mascot to an elite squad of marines, very much like he would feel "part of the team" :)

thanks heaps for the helpful response

textillis 07-23-2013 05:40 AM

Quote:

Originally Posted by sycamorex (Post 4994815)
Slightly late to the game, but here you can also find some info about colourful prompts.

HTH

Not too late all, Sycamorex!
Mighty obliged: the more the better.


All times are GMT -5. The time now is 05:24 AM.