Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Extra informative Bash prompt
View unanswered posts
View posts from last 24 hours

Goto page Previous  1, 2, 3, 4, 5, 6, 7, 8, 9  Next  
Reply to topic    Gentoo Forums Forum Index Gentoo Chat
View previous topic :: View next topic  
Author Message
laffer
n00b
n00b


Joined: 08 May 2003
Posts: 33
Location: Kalamazoo, MI

PostPosted: Sun Jun 13, 2004 12:22 am    Post subject: Reply with quote

After some trial and error, this is the bash prompt that I have decided to use:

Quote:
PS1="\n\[\e[30;1m\]\[\016\]l\[\017\](\[\e[34;1m\]\u@\h\[\e[30;1m\])-(\[\e[34;1m\]\j\[\e[30;1m\])-(\[\e[34;1m\]\@ \d\[\e[30;1m\])->\[\e[30;1m\]\n\[\016\]m\[\017\]-(\[\[\e[32;1m\]\w\[\e[30;1m\])-(\[\e[32;1m\]\$(/bin/ls -1 | /usr/bin/wc -l | /bin/sed 's: ::g') files, \$(/bin/ls -lah | /bin/grep -m 1 total | /bin/sed 's/total //')b\[\e[30;1m\])--> \[\e[0m\]"


It looks like this; however, the green is lighter:

┌(user@hostname)-(0)-(08:19 PM Sat Jun 12)->
└-(~)-(15 files, 2.7Mb)-->

Mike
Back to top
View user's profile Send private message
pagerc@ufl.edu
n00b
n00b


Joined: 02 Jan 2004
Posts: 15

PostPosted: Sun Jun 13, 2004 3:54 am    Post subject: Reply with quote

One of the reasons I made my prompt is to help in the efficiency of execution. I only call ls once in my entire script. I avoid calling ps at all if possible. The reason behind this is if the system has lots of running processes or if you enter a directory with lots of files, you will be executing those commands on every prompt display. That can encumber your system and introduce a noticeable delay into your prompt display.

Now mine isn't perfect, it works about as fast as you can get, but you could make it faster replacing sed with some fancy bash string manipulation. However, it does remove multiple ls's in the same directory, and it also only does one ls for all file related information.

Stuff like this might be important if you intend to use your prompt for a long time. So, if anyone would like to fix my problem with spaces and hyphens in file name lists, I think everyone could benefit from modifying my prompt to their tastes.
Back to top
View user's profile Send private message
dalek
Veteran
Veteran


Joined: 19 Sep 2003
Posts: 1353
Location: Mississippi USA

PostPosted: Sun Jun 13, 2004 4:41 am    Post subject: Reply with quote

AnarchE wrote:
I'm surprised no one has posted this yet, but here is a really great Bash HOWTO written by the Daniel Robbins (CEO and President of Gentoo) on this page:

http://www-106.ibm.com/developerworks/library/bash2.html

Explains in great detail everything you might need to know about bash scripting.


That link no longer works. I did find it though just in case someone looks. Here it is:

http://www-106.ibm.com/developerworks/linux/library/l-tip-prompt/

That should help.

Later

:D :D :D
_________________
My rig: Gigabyte GA-970A-UD3P mobo, AMD FX-8350 Eight-Core CPU, ZALMAN CNPS10X Performa CPU cooler,
G.SKILL 32GB DDR3 PC3 12800 Memory Nvidia GTX-650 video card LG W2253 Monitor
60TBs of hard drive space using LVM
Cooler Master HAF-932 Case
Back to top
View user's profile Send private message
meowsqueak
Veteran
Veteran


Joined: 26 Aug 2003
Posts: 1549
Location: New Zealand

PostPosted: Sun Jun 13, 2004 9:15 pm    Post subject: Reply with quote

pagerc@ufl.edu wrote:
Anyways, turns out that the PS1 string if modified in PROMPT_COMMAND gets standard bash string interpretation done, and \$ evaluates to the following character, where what we want is \\\$.


You hit the nail on the head there - I too evaluate PS1 inside a function for every new prompt, so double-escaping $ solves the problem. I don't think it's ugly - to me it's completely logical albeit not obvious. PS1 strings are hardly ever pretty anyway... :lol:
Back to top
View user's profile Send private message
Stanley56
n00b
n00b


Joined: 07 Jan 2004
Posts: 65
Location: Belgium

PostPosted: Sat Jul 24, 2004 9:14 pm    Post subject: Reply with quote

I've adjusted the one that comes standard a bit so it would be a little more informative: (meant for a dark background)

For users:
/etc/
user@host $

For root:
/etc/
host #

Here is the code:
Code:
users:
PS1='\[\033[01;33m\]\w\[\033[0m\]\n\[\033[01;32m\]\u@\h\[\033[00m\] \[\033[01;34m\]\$ \[\033[00m\]'

root:
PS1='\[\033[01;33m\]\w\[\033[0m\]\n\[\033[01;31m\]\h\[\033[00m\] \[\033[01;34m\]\$ \[\033[00m\]'


And for every user i've put "source /etc/profile" in their ~/.bachrc so that the color changes when you switch to root and back...
_________________
"In a world without fences, who needs gates?" :D
Back to top
View user's profile Send private message
FonderiaDigitale
Veteran
Veteran


Joined: 06 Nov 2003
Posts: 1710
Location: Rome, Italy

PostPosted: Sat Jul 24, 2004 9:58 pm    Post subject: Reply with quote

you should check EasyPrompt in the italian forum, perhaps it could be useful.
_________________
Come disse un amico, i sistemisti sono un po' come gli artigiani per l'informatica :)
Back to top
View user's profile Send private message
tms
n00b
n00b


Joined: 26 Mar 2004
Posts: 31

PostPosted: Wed Oct 27, 2004 9:53 pm    Post subject: Reply with quote

how about this:

I would like my prompt to be something like "40c/78% user@host currentdir"

The problem is I have two batteries. acpi shows only stats about one of them. when battery1 is fully charged, it will show battery2. after battery2 has been fully charged it wont show anything

btw, how about an official howto with several examples of popular bash prompts on the website?
Back to top
View user's profile Send private message
John5788
Advocate
Advocate


Joined: 06 Apr 2004
Posts: 2140
Location: 127.0.0.1

PostPosted: Sat Nov 06, 2004 4:37 am    Post subject: Reply with quote

http://www-106.ibm.com/developerworks/linux/library/l-tip-prompt/

theres a good page. BTW heres mine if anyone wants to try it out:

Code:
export PS1="[\e[31m\$(pwd)\e[0m :: \e[32m\@\e[0m :: \e[33m\l\e[0m]\n[\e[32m\u\e[0m@\e[34m\H\e[0m] \$ "


looks like this

[/home/john5788 :: 08:35 PM :: 1]
[john5788@john5788.x5788.net] $
_________________
John5788
Back to top
View user's profile Send private message
dalek
Veteran
Veteran


Joined: 19 Sep 2003
Posts: 1353
Location: Mississippi USA

PostPosted: Sat Nov 06, 2004 8:14 am    Post subject: Reply with quote

Well crap, I did a update and let it overwrite mine. I hope I posted it here somewhere.

This sucks.

:evil: :evil: :evil:
_________________
My rig: Gigabyte GA-970A-UD3P mobo, AMD FX-8350 Eight-Core CPU, ZALMAN CNPS10X Performa CPU cooler,
G.SKILL 32GB DDR3 PC3 12800 Memory Nvidia GTX-650 video card LG W2253 Monitor
60TBs of hard drive space using LVM
Cooler Master HAF-932 Case
Back to top
View user's profile Send private message
John5788
Advocate
Advocate


Joined: 06 Apr 2004
Posts: 2140
Location: 127.0.0.1

PostPosted: Sat Nov 06, 2004 6:22 pm    Post subject: Reply with quote

dalek wrote:
Well crap, I did a update and let it overwrite mine. I hope I posted it here somewhere.

This sucks.

:evil: :evil: :evil:


thats why you should keep it in ~/.bashrc not in /etc/profile :)
_________________
John5788
Back to top
View user's profile Send private message
dalek
Veteran
Veteran


Joined: 19 Sep 2003
Posts: 1353
Location: Mississippi USA

PostPosted: Sat Nov 06, 2004 8:40 pm    Post subject: Reply with quote

Doesn't seem to work when I put it in there. :? :?

But since I needed to post anyway:

Code:
export PS1='\[\033[01;31m\]\u@\h \[\033[01;34m\]\w \$ \[\033[00m\]'


Now if I do that again, I can just paste it back in. :wink: :lol:

< bookmarks this thread so I can find it > :idea:

Later

:D :D :D :D
_________________
My rig: Gigabyte GA-970A-UD3P mobo, AMD FX-8350 Eight-Core CPU, ZALMAN CNPS10X Performa CPU cooler,
G.SKILL 32GB DDR3 PC3 12800 Memory Nvidia GTX-650 video card LG W2253 Monitor
60TBs of hard drive space using LVM
Cooler Master HAF-932 Case
Back to top
View user's profile Send private message
elvisthedj
Guru
Guru


Joined: 21 Jun 2004
Posts: 483
Location: Nampa, ID

PostPosted: Sun Nov 07, 2004 10:30 am    Post subject: Here's my prompt :D Reply with quote

Code:

\n\[\033[00;34;34m\]\,,,/ [\[\033[01;37;37m\]\w\[\033[00;34;34m\]] \n\[\033[00;34;34m\](\[\033[01;37;37m\]o\[\033[00;34;34m\]_\[\033[01;37;37m\]o\[\033[00;34;34m\]) [\[\033[01;37;37m\]\u\[\033[01;34;34m\]@\[\033[01;37;37m\]\h\[\033[00;34;34m\]]\n \[\033[00;34;34m\](\[\033[01;37;37m\]-\[\033[00;34;34m\]) [\[\033[01;37;37m\]\d\[\033[00;34;34m\]] \[\033[01;37;37m\]| \[\033[00;34;34m\][\[\033[01;37;37m\]\t\[\033[00;34;34m\]]\n \[\033[01;37;37m\]#


This gives a little blue alien with three info lines. I have a red one with a different face for root. Here's what it looks like:

http://woundedninja.com/prompts.png
Back to top
View user's profile Send private message
GeoffOs
n00b
n00b


Joined: 13 Dec 2003
Posts: 56
Location: Cheshire

PostPosted: Sun Nov 07, 2004 1:27 pm    Post subject: Me Dumb Reply with quote

Stupid question, but how do you activate the changes to your prompt.
I am currently exiting from my ssh session and logging back in.
_________________
Beyond a critical point within a finite space, freedom diminishes as numbers increase. ...
The human question is not how many can possibly survive within the system, but what kind of existence is possible for those who do survive."
Back to top
View user's profile Send private message
dalek
Veteran
Veteran


Joined: 19 Sep 2003
Posts: 1353
Location: Mississippi USA

PostPosted: Sun Nov 07, 2004 1:47 pm    Post subject: Reply with quote

You just did. Logging out and back in should do the trick. This ain't windoze, no reboot needed. :wink:

Later

:D :D :D :D
_________________
My rig: Gigabyte GA-970A-UD3P mobo, AMD FX-8350 Eight-Core CPU, ZALMAN CNPS10X Performa CPU cooler,
G.SKILL 32GB DDR3 PC3 12800 Memory Nvidia GTX-650 video card LG W2253 Monitor
60TBs of hard drive space using LVM
Cooler Master HAF-932 Case
Back to top
View user's profile Send private message
GeoffOs
n00b
n00b


Joined: 13 Dec 2003
Posts: 56
Location: Cheshire

PostPosted: Sun Nov 07, 2004 1:54 pm    Post subject: still dumb Reply with quote

OK, i managed to reason that one out :lol:
But can i do it without logging out and back in again?
_________________
Beyond a critical point within a finite space, freedom diminishes as numbers increase. ...
The human question is not how many can possibly survive within the system, but what kind of existence is possible for those who do survive."
Back to top
View user's profile Send private message
dalek
Veteran
Veteran


Joined: 19 Sep 2003
Posts: 1353
Location: Mississippi USA

PostPosted: Sun Nov 07, 2004 2:06 pm    Post subject: Reply with quote

I think this will work:

Code:
source /etc/profile


That should do it. I put mine in the profile file but I think it will work since it looks at the others. If not, and you put it in ~./bashrc then type in:

Code:
source ~/.bashrc


I haven't tried the last one but it should work. Just point it to the file you put it in.

Later

:D :D :D
_________________
My rig: Gigabyte GA-970A-UD3P mobo, AMD FX-8350 Eight-Core CPU, ZALMAN CNPS10X Performa CPU cooler,
G.SKILL 32GB DDR3 PC3 12800 Memory Nvidia GTX-650 video card LG W2253 Monitor
60TBs of hard drive space using LVM
Cooler Master HAF-932 Case
Back to top
View user's profile Send private message
GeoffOs
n00b
n00b


Joined: 13 Dec 2003
Posts: 56
Location: Cheshire

PostPosted: Sun Nov 07, 2004 2:09 pm    Post subject: Ahhhhhh Reply with quote

I had put the changes in my bashrc
the
Code:
source ~/.bashrc

work a treat
Thanks
_________________
Beyond a critical point within a finite space, freedom diminishes as numbers increase. ...
The human question is not how many can possibly survive within the system, but what kind of existence is possible for those who do survive."
Back to top
View user's profile Send private message
bladdo
Guru
Guru


Joined: 19 Jul 2004
Posts: 334
Location: NJ

PostPosted: Sun Nov 07, 2004 7:37 pm    Post subject: Reply with quote

laffer wrote:
After some trial and error, this is the bash prompt that I have decided to use:

Quote:
PS1="\n\[\e[30;1m\]\[\016\]l\[\017\](\[\e[34;1m\]\u@\h\[\e[30;1m\])-(\[\e[34;1m\]\j\[\e[30;1m\])-(\[\e[34;1m\]\@ \d\[\e[30;1m\])->\[\e[30;1m\]\n\[\016\]m\[\017\]-(\[\[\e[32;1m\]\w\[\e[30;1m\])-(\[\e[32;1m\]\$(/bin/ls -1 | /usr/bin/wc -l | /bin/sed 's: ::g') files, \$(/bin/ls -lah | /bin/grep -m 1 total | /bin/sed 's/total //')b\[\e[30;1m\])--> \[\e[0m\]"


It looks like this; however, the green is lighter:

┌(user@hostname)-(0)-(08:19 PM Sat Jun 12)->
└-(~)-(15 files, 2.7Mb)-->

Mike


Nice :P
_________________
Bladdo formerly >Milo<
bladdo.net - scripting and design
Creator of AIM Bot: Tiny Tiny Bot - the bot that learns
distro: gentoo | window manager: pekwm
Back to top
View user's profile Send private message
DaPhreak
n00b
n00b


Joined: 22 Aug 2004
Posts: 13

PostPosted: Sun Nov 07, 2004 7:59 pm    Post subject: Reply with quote

Well my prompt looks lean and clean (that's what I think :o )

~/.bashrc
Code:

....
RED="\[\e[1;31m\]"
NORMAL="\]\e[00m\]"

SIZE='$( /bin/ls --si -s | /bin/head -n 1 | /bin/awk '\''{ print $2 }'\'')'
TTY=$( /bin/tty | /bin/cut -d'/' -f3-4 )
PS1="${RED}\u${NORMAL}@\h on ${RED}$TTY${NORMAL}\n(${SIZE}) \w \$${NORMAL} "
export PS1
...
shopt -s checkwinsize


Which produced something like this:
phreak@freakazoid on pts/1
(36M) ~ $

Some time ago, I tried to implement an APCI-Battery status without an external program, but didn't found the time yet to make this further.
Back to top
View user's profile Send private message
elvisthedj
Guru
Guru


Joined: 21 Jun 2004
Posts: 483
Location: Nampa, ID

PostPosted: Mon Nov 08, 2004 3:03 am    Post subject: Re: Me Dumb Reply with quote

GeoffOs wrote:
Stupid question, but how do you activate the changes to your prompt.
I am currently exiting from my ssh session and logging back in.


You could put this in /etc/profile which is executed at startup, or in ~/.bashrc which runs each time the user spawns a shell. Either way, it's the same as typing PS1='whatever #' at your current prompt. PS1 is the first prompt PS2 is the second prompt (when more info is needed).



P.S. I had to see if anybody has a goofier prompt than me, so I started a thread about it.. (Come on somebody! Be lamer than me! :)

https://forums.gentoo.org/viewtopic.php?t=248300&highlight=
Back to top
View user's profile Send private message
tms
n00b
n00b


Joined: 26 Mar 2004
Posts: 31

PostPosted: Tue Dec 14, 2004 3:45 pm    Post subject: Reply with quote

here's a link to a thread of mine about support for two batteries in the prompt. I could use some help completing it

https://forums.gentoo.org/viewtopic.php?t=261630&highlight=
Back to top
View user's profile Send private message
Gherald
Veteran
Veteran


Joined: 23 Aug 2004
Posts: 1399
Location: CLUAConsole

PostPosted: Sun Dec 19, 2004 10:40 am    Post subject: Reply with quote

After perusing this thread, I've spent 3 hours (!) creating my own. I think you will find it very interesting, in particular the $PREVCMD variable:
Code:
#get the last command entered
PREVCMD=$(history 1 | awk '{ $1 = ""; sub(/^ */, ""); print; exit }')

So far I have only created a special case for "cd" and "ls" but the possibilities are infinite!

Have a go at it yourself:
Code:
# Color Variables for prompt
GRAD1='\333\262\261\260'
GRAD2='\260\261\262\333'
YLOBRN='\[\e[01;33;43m\]'
WHTBRN='\[\e[01;37;43m\]'
REDBRN='\[\e[00;31;43m\]'
REDBLK='\[\e[00;31;40m\]'
PPLBLK='\[\e[01;35;40m\]'
WHTBLK='\[\e[01;37;40m\]'
NONE='\[\e[00m\]'
HBLK='\[\e[00;30;30m\]'
HBLU='\[\e[01;34;34m\]'
BLU='\[\e[00;34;34m\]'
YEL='\[\e[00;33;33m\]'
WHT='\[\e[01;37;37m\]'
PRPL='\[\e[00;34;35m\]'
HRED='\[\e[01;31;31m\]'
RED='\[\e[0;31m\]'
NORM='\[\e[01;00;0m\]'
BGRN='\[\e[01;32m\]'
CYAN='\[\e[00;36m\]'

PROMPT_COMMAND=_setprompt
function _setprompt {

   _HOST=$(echo $HOSTNAME|tr -s "[:lower:]" "[:upper:]")
   _TTY="\[\e[0;36m\]\$(/usr/bin/tty | /bin/sed -e 's:/dev/::')"
   _PWD=$CYAN"\$(pwd | sed "s=`echo $HOME | sed 's:\/:\\\/:g'`=~=" | sed 's=^\(.\{5\}\)\(.*\)\(.\{15\}\)$=\1...\2...\3=' | sed 's=\.\.\.\.\.\.==' | sed 's=\(.*\)\.\.\..*\.\.\.\(.*\)=\1...\2=')"
   
   #variations for root
   if [ `/usr/bin/whoami` = 'root' ]; then
      _USER_COLOR=$HRED;
      _HIST_COLOR=$RED;
      _USER_STRING=""
   else
      _USER_COLOR=$PRPL
      _HIST_COLOR=$PRPL
      _USER_STRING=$USER
   fi
   
   #get the last command entered
   PREVCMD=$(history 1 | awk '{ $1 = ""; sub(/^ */, ""); print; exit }')
   
   _INFO=""   #print directory info if PREVCMD was a cd or ls
   if [ "$(echo -e $PREVCMD | grep "^\ *\(cd\)\|\(ls\)\ +")" ]; then
      _FILECOUNT=$(/bin/ls -A1 | /bin/grep -v '^[d]' | /usr/bin/wc -l | /bin/sed 's: ::g')
      _DIRCOUNT=$(/bin/ls -Al | /bin/grep '^[d]' | /usr/bin/wc -l | /bin/sed 's: ::g')
      _LINKCOUNT=$(/bin/ls -Al | /bin/grep '^[l]' | /usr/bin/wc -l | /bin/sed 's: ::g')
      _DISKUSED=$(/bin/ls -lAh | /bin/grep -m 1 total | /bin/sed 's/total //')"B"
      _DISKFREE=$(df . -h| tail -n 1 | awk '{print $4}')"B"
      _DISKNAME=$(df . -h| tail -n 1 | awk '{print $1}')
      
      if [ $_LINKCOUNT -eq "0" ]; then
         _LINKCOUNT=", "
      else
         _LINKCOUNT=" ("$_LINKCOUNT" links) "
      fi
      
      #putting it all together
      _INFO=$YEL""$_DISKNAME": "$_DISKUSED" in "$_FILECOUNT" files"$_LINKCOUNT""$_DIRCOUNT" dirs, "$_DISKFREE" free\n"
   fi
   
   _POWER=""   #get apm battery status if available
   if [ -e /proc/apm ]; then
      _POWER=$HBLU""$(/bin/cat /proc/apm | awk '{print $7}' | sed s/%\$/%\ / | sed s/100%\ //)
   fi
         
   export PS1=$_INFO""$_POWER""$_USER_COLOR""$_HOST" "$_USER_STRING"(\j) "$_PWD""$_HIST_COLOR" !\! \[\e[m\]"
} #end _setprompt
Back to top
View user's profile Send private message
gonEH
n00b
n00b


Joined: 16 Jan 2005
Posts: 15
Location: Incheon Korea

PostPosted: Sun Feb 20, 2005 1:53 pm    Post subject: Good information. Reply with quote

Good information.
Thanks alot. ^^
Back to top
View user's profile Send private message
dalek
Veteran
Veteran


Joined: 19 Sep 2003
Posts: 1353
Location: Mississippi USA

PostPosted: Sun Feb 20, 2005 2:04 pm    Post subject: Reply with quote

Is cool ain't it? This is a neat thread to try different things. I do wish I could get the Konsole in KDE to open as white on black instead of that pukey yellow thing.

I'm putting this link in my savers directory. Got to hang on to this one.

Later

:D :D :D :D
_________________
My rig: Gigabyte GA-970A-UD3P mobo, AMD FX-8350 Eight-Core CPU, ZALMAN CNPS10X Performa CPU cooler,
G.SKILL 32GB DDR3 PC3 12800 Memory Nvidia GTX-650 video card LG W2253 Monitor
60TBs of hard drive space using LVM
Cooler Master HAF-932 Case
Back to top
View user's profile Send private message
Nard`
Apprentice
Apprentice


Joined: 23 Jan 2005
Posts: 250

PostPosted: Wed Feb 23, 2005 3:46 pm    Post subject: Reply with quote

My prompt is:

Code:
: \[\e[32m\[\e[1m\u\[\e[0m\[\e[33m\[\e[1m@\[\e[0m\[\e[32m\[\e[1m\h\[\e[0m\[\e[33m:\[\e[0m\[\e[34m\[\e[1m$(pwd | sed s=\/home\/nard-restricted=~= | sed 's=^\(.\{5\}\)\(.*\)\(.\{7\}\)$=\1...\2...\3=' | sed 's=\.\.\.\.\.\.==' | sed 's=\(.*\)\.\.\..*\.\.\.\(.*\)=\1...\2=')\[\e[0m\[\e[36m\[\e[1m\$\[\e[0m\[\e[0m;


Whenever I type a large amount of text, the text starts overwriting itself

It starts at this point

Code:
1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25.26.27.28.29.30.31.32.33.34.35.36.37.38.39.40.41.42.43.44.45.46.47.48.49.50.51.52.53.54.55.56.57.58.59.60.61.62.63.64.65.66.67.68.69.70


after that my prompt dissapears and is replaced with a : and on a line down from that all the text i write from there gets overwritten

this never happens if i use the default prompt.

Nor does it happen if i don't use colors. I've been unable to find anything about this on google

EDIT: Fixed it
_________________
Programming is the process of putting bugs in.
Debugging is the process of attempting to take bugs out, doing an ugly hack, hitting your computer, then claiming insurance.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Gentoo Chat All times are GMT
Goto page Previous  1, 2, 3, 4, 5, 6, 7, 8, 9  Next
Page 6 of 9

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum