LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 07-22-2013, 09:28 AM   #1
textillis
Member
 
Registered: May 2013
Location: Northern Rivers, NSW, Australia
Distribution: Slackware64-current, Mint Nadya
Posts: 299

Rep: Reputation: 2
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?

Last edited by textillis; 07-22-2013 at 09:47 AM.
 
Old 07-22-2013, 09:51 AM   #2
Ygrex
Member
 
Registered: Nov 2004
Location: Russia (St.Petersburg)
Distribution: Debian
Posts: 666

Rep: Reputation: 68
Code:
PS1='\[\033[01;31m\]root\[\033[00m\]\@\h:\w'
 
1 members found this post helpful.
Old 07-22-2013, 10:50 AM   #3
textillis
Member
 
Registered: May 2013
Location: Northern Rivers, NSW, Australia
Distribution: Slackware64-current, Mint Nadya
Posts: 299

Original Poster
Rep: Reputation: 2
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?
 
Old 07-22-2013, 11:24 AM   #4
octoberblu3
Member
 
Registered: Oct 2005
Distribution: Slackware64-current
Posts: 67

Rep: Reputation: 22
http://ascii-table.com/ansi-escape-sequences.php
 
1 members found this post helpful.
Old 07-22-2013, 01:16 PM   #5
textillis
Member
 
Registered: May 2013
Location: Northern Rivers, NSW, Australia
Distribution: Slackware64-current, Mint Nadya
Posts: 299

Original Poster
Rep: Reputation: 2
Thanks octoberblu3!
 
Old 07-22-2013, 01:21 PM   #6
kikinovak
MLED Founder
 
Registered: Jun 2011
Location: Montpezat (South France)
Distribution: CentOS, OpenSUSE
Posts: 3,437

Rep: Reputation: 2095Reputation: 2095Reputation: 2095Reputation: 2095Reputation: 2095Reputation: 2095Reputation: 2095Reputation: 2095Reputation: 2095Reputation: 2095Reputation: 2095
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.
 
1 members found this post helpful.
Old 07-22-2013, 01:31 PM   #7
Diantre
Member
 
Registered: Jun 2011
Distribution: Slackware
Posts: 515

Rep: Reputation: 230Reputation: 230Reputation: 230
More info on bash prompts:

http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/index.html
 
Old 07-22-2013, 01:47 PM   #8
fogpipe
Member
 
Registered: Mar 2011
Distribution: Slackware 64 -current,
Posts: 550

Rep: Reputation: 194Reputation: 194
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.
 
Old 07-22-2013, 01:50 PM   #9
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,836
Blog Entries: 1

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

HTH
 
1 members found this post helpful.
Old 07-22-2013, 03:21 PM   #10
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_12{.0|.1}
Posts: 5,405
Blog Entries: 11

Rep: Reputation: 3358Reputation: 3358Reputation: 3358Reputation: 3358Reputation: 3358Reputation: 3358Reputation: 3358Reputation: 3358Reputation: 3358Reputation: 3358Reputation: 3358
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.
 
1 members found this post helpful.
Old 07-22-2013, 04:44 PM   #11
Gerard Lally
Senior Member
 
Registered: Sep 2009
Location: Brú na Bóinne, IE
Distribution: Slackware, NetBSD
Posts: 1,719

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
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
 
2 members found this post helpful.
Old 07-23-2013, 03:11 AM   #12
textillis
Member
 
Registered: May 2013
Location: Northern Rivers, NSW, Australia
Distribution: Slackware64-current, Mint Nadya
Posts: 299

Original Poster
Rep: Reputation: 2
Niki

Thanks for sharing your .bashrc.

Helps a lot.

Got it looking nice now.
 
Old 07-23-2013, 03:16 AM   #13
textillis
Member
 
Registered: May 2013
Location: Northern Rivers, NSW, Australia
Distribution: Slackware64-current, Mint Nadya
Posts: 299

Original Poster
Rep: Reputation: 2
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 ...
 
Old 07-23-2013, 03:27 AM   #14
textillis
Member
 
Registered: May 2013
Location: Northern Rivers, NSW, Australia
Distribution: Slackware64-current, Mint Nadya
Posts: 299

Original Poster
Rep: Reputation: 2
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
 
Old 07-23-2013, 05:40 AM   #15
textillis
Member
 
Registered: May 2013
Location: Northern Rivers, NSW, Australia
Distribution: Slackware64-current, Mint Nadya
Posts: 299

Original Poster
Rep: Reputation: 2
Quote:
Originally Posted by sycamorex View Post
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.
 
  


Reply

Tags
colorschema, customization, root, shell prompt, shell scripting


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] main non-root user shell prompt lost textillis Slackware 17 07-22-2013 10:06 AM
[SOLVED] customizing the prompt soundie Linux - Newbie 10 09-30-2011 05:02 AM
[SOLVED] Help Customizing Terminal prompt EzioAuditore Linux - Newbie 18 04-07-2011 12:28 PM
Root Shell, Path & Prompt tschima Solaris / OpenSolaris 3 05-03-2008 09:51 PM
Customizing the command prompt sweetnsourbkr Linux - General 4 11-10-2005 12:34 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 06:09 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration