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
meowsqueak
Veteran
Veteran


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

PostPosted: Wed Jan 21, 2004 7:58 pm    Post subject: Reply with quote

Brother Dysk wrote:
Techie2000 wrote:
one of the great things about Linux :). Very customizable...


Of course you are aware that simply adding a line that says "PROMPT *[$V] $P*" in your AUTOEXEC.BAT file on any MS system will do the same, right?

(Note, displays *[DOS 7.2] c:\*)


I think the keyword here, that distinguishes many shells found on Linux-based systems from those running DOS, is 'very'.

Anyway, why bother customising DOS? It's almost unusable as it is anyway, why make it more so? :wink:
Back to top
View user's profile Send private message
Qubax
Guru
Guru


Joined: 19 Jul 2002
Posts: 451
Location: Tirol, Austria

PostPosted: Wed Jan 21, 2004 10:23 pm    Post subject: Reply with quote

i find this link very helpfull: http://www-106.ibm.com/developerworks/linux/library/l-tip-prompt/
Back to top
View user's profile Send private message
dvc5
Guru
Guru


Joined: 06 Dec 2003
Posts: 433
Location: Sunnyvale, California

PostPosted: Sun Feb 29, 2004 8:13 pm    Post subject: Reply with quote

Stole some code from this thread on acpi parsing (no apm here).

Code:
PS1="\[\033[01;34m\]\`/usr/bin/battery|awk '{print \$2}'\` \[\033[01;32m\]\u@\h \[\033[01;34m\]\W \$ \[\033[00m\]"


And it looks like:

Quote:
96% user@hostname portage $


The "portage" represents the current working directory, since I liked the default gentoo prompt so much. Hopefully this helps the acpi users out there. :D
_________________
#define NULL rand() /*heh heh heh */

Green Is Good
Back to top
View user's profile Send private message
bigsmoke
Tux's lil' helper
Tux's lil' helper


Joined: 09 Aug 2003
Posts: 92
Location: The city of Groningen in The Netherlands

PostPosted: Wed Mar 03, 2004 3:09 am    Post subject: My PS1 Reply with quote

I really like this thread! :D

This is one I've been using for a while:
Code:

export PS1='\[\e[1;32m\]\u@\H:\[\e[m\] \[\e[1;34m\]\w\[\e[m\]\n\
\[\e[1;33m\]hist:\! \[\e[0;33m\]cmnd:\# \[\e[1;31m\]jobs:\j \$\[\e[m\] '


It (sort of) looks like this:
bigsmoke@hostname: /home/bigsmoke
hist:501 cmnd:1 jobs:0 $

Notice that the '$' at the end actually becomes a '#' when I'm root ...

It's simple but it works.
_________________
Gentoo's kind community
has build up an immunity
for the kind of rash
that makes others bash(1)
the newer GNU/Linux user,
a man(1) that is inapt
to flawlessly adapt,
and therefore called a luser.
Back to top
View user's profile Send private message
gatiba
Guru
Guru


Joined: 01 Sep 2002
Posts: 434

PostPosted: Wed Mar 03, 2004 8:31 am    Post subject: Re: My PS1 Reply with quote

bigsmoke wrote:
I really like this thread! :D

This is one I've been using for a while:
Code:

export PS1='\[\e[1;32m\]\u@\H:\[\e[m\] \[\e[1;34m\]\w\[\e[m\]\n\
\[\e[1;33m\]hist:\! \[\e[0;33m\]cmnd:\# \[\e[1;31m\]jobs:\j \$\[\e[m\] '


It (sort of) looks like this:
bigsmoke@hostname: /home/bigsmoke
hist:501 cmnd:1 jobs:0 $

Notice that the '$' at the end actually becomes a '#' when I'm root ...

It's simple but it works.



Really nice :D
I'm using it right now !
Back to top
View user's profile Send private message
bigsmoke
Tux's lil' helper
Tux's lil' helper


Joined: 09 Aug 2003
Posts: 92
Location: The city of Groningen in The Netherlands

PostPosted: Wed Mar 03, 2004 11:07 am    Post subject: Reply with quote

ILikePi wrote:
see 'man 4 console_codes' for the rest of the codes.


Thanks for the tip. It's an extremely handy manual page. 8) I never knew that one (figured out all the codes by simply trying ;))
_________________
Gentoo's kind community
has build up an immunity
for the kind of rash
that makes others bash(1)
the newer GNU/Linux user,
a man(1) that is inapt
to flawlessly adapt,
and therefore called a luser.
Back to top
View user's profile Send private message
pagerc@ufl.edu
n00b
n00b


Joined: 02 Jan 2004
Posts: 15

PostPosted: Mon Mar 22, 2004 4:33 am    Post subject: Bash Prompt advanced Reply with quote

So I've seen all of these prompts that everyone has. I've been looking around and found Gile Orr's bash info to be most helpful. Anyways, my prompt can be found at http://fidget.homeip.net/~pagerc/profile.

My prompt does pretty much anything you want. Tells you acpi battery and temp info. Tells you tty, user, host, path is in there somewhere, history #, and color codes the \$ to the exit status of the last app. Great to have a visual that something failed. Everything can be turned on or off. Colorizing it should be pretty straight forward.

The only thing I am frustrated on is that the line truncates too soon. There's something funky with the colors, so it isn't perfect. But it's getting very close to having the best features of anything and everything.

One line version:
pts/0 root@nomad:[505]#

Two line full version:
pts/0 root@nomad:/dev [0b 0.0-0x 16.18d 646l 29bc 4p 2s]
100% 55C [526]#

Description:
tty username@hostname:pwd [(size visible files)b (# files).(#hidden files)-(#executable files) (#dirs).(#hidden dirs)d (#links)l (#devices)bc (#pipes)p (#sockets)s]
(percentage battery) (temp Celsius) history \$

It's all color coded nicely too. So that all the directory info stuff looks like it would from an ls. Username is green for users red for uid 0, pwd is yellow but can be changed easily. battery is green for >75%, yellow for >50%, brown for >25%, (red for >10%?unsure percentage here) temperature will give an audible alert if it goes above 60C and change colors too. history \$ change color from blue to red based on exit status of last command, red bad - blue good
Back to top
View user's profile Send private message
AnTiKrIsT
n00b
n00b


Joined: 15 Dec 2003
Posts: 11

PostPosted: Tue Apr 13, 2004 2:58 pm    Post subject: Reply with quote

Here the $ nerver chnages in the # when i become root
and i use the same .bashrc for them.

Code:

PS1="\[\033[01;30m\]\[\016\]l\[\017\](\[\033[00;33m\]\u@\h\[\033[01;30m\])\[\033[01;37m\]-\[\033[01;30m\](\[\033[32m\]\$\[\033[01;30m\])\[\033[01;37m\]-\[\033[01;30m\](\t \d)\[\033[01;37m\]->\n\[\033[01;30m\]\[\016\]m\[\017\]--(\[\033[00;33m\]LeViAtHaN\[\033[01;30m\])\[\033[01;37m\]-\[\033[01;30m\](\[\033[32m\]\w\[\033[01;30m\])\[\033[01;37m\]-->\[\e[m\]"


[img:74287d9a2f]http://users.pandora.be/LeV1AtHaN/prompt-error.png[/img:74287d9a2f]

and when i do export it also deosnt work
Back to top
View user's profile Send private message
meowsqueak
Veteran
Veteran


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

PostPosted: Tue Apr 13, 2004 8:13 pm    Post subject: Reply with quote

I noticed the exact same behaviour last night - and it puzzled me. It's always worked for me, and I don't understand why it would have suddenly stopped working. I think something has recently broken somewhere...
Back to top
View user's profile Send private message
Gentree
Watchman
Watchman


Joined: 01 Jul 2003
Posts: 5350
Location: France, Old Europe

PostPosted: Fri May 07, 2004 12:13 pm    Post subject: Re: Extra informative Bash prompt Reply with quote

jmglov wrote:
That is quite a bit of info, alright. For those people out there (like myself) that prefer a more minimalistic approach, try:

Code:

PS1=': \u@\h; '
PS2=': ; '


This produces a very simple prompt:

Code:

: jmglov@harp; echo 'foo
: ; bar' >~/foobar


But it has a very cool feature, which is the ability to copy the whole line and paste it into another xterm. Why? The ':' character means ignore, and the ';' character starts a new command. So when you paste a line (or several lines) into an xterm, whatever you have in your prompt between the ':' and the ';' is completely disregarded by the shell.


Ahh! this is something that has bugged me for a while . How do I cut and paste with xterm. I thought it was impossible in simple xterm and I have to use konsole every time I want to post output.

Someone pls explain.

Thx.
Back to top
View user's profile Send private message
odegard
Guru
Guru


Joined: 08 Mar 2003
Posts: 324
Location: Trondheim, NO

PostPosted: Fri May 07, 2004 9:20 pm    Post subject: Reply with quote

can't you just mark with the mouse and then middle-click where you want to paste?
Back to top
View user's profile Send private message
Gentree
Watchman
Watchman


Joined: 01 Jul 2003
Posts: 5350
Location: France, Old Europe

PostPosted: Sat May 08, 2004 1:53 am    Post subject: Reply with quote

odegard wrote:
can't you just mark with the mouse and then middle-click where you want to paste?


In a word 'no'. I dont have 3btn mouse, man xterm says I can select on copy text by highlighting with mouse.

this may be happening , but until I can paste I wont know. Is the a keyboard method to paste?

Thx.
Back to top
View user's profile Send private message
meowsqueak
Veteran
Veteran


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

PostPosted: Sat May 08, 2004 3:22 am    Post subject: Reply with quote

If you enable '3 mouse button emulation' in your XF86Config file (mouse section, check man page for exact option), you can simultaneously depress L and R mouse buttons to simulate a middle click.

You could also use 'xclip -o' to dump the contents of the clipboard to stdout. If you want to do this for general purposes, you'll have to think a bit about it - will probably need integrating with your window manager somehow...
Back to top
View user's profile Send private message
pagerc@ufl.edu
n00b
n00b


Joined: 02 Jan 2004
Posts: 15

PostPosted: Sat May 08, 2004 6:12 am    Post subject: pasting data Reply with quote

You guys make everything so complicated. shift Insert should paste into a terminal window. Before there was vga, there was console, so everything can be done on a console just as well as gui. :)

Oh, about that : ; thingy, seems that you can use a color status of \[\e[8m\] before either of those characters should make it be invisible in an xterm. I use aterm for transparencies and know that aterm does not support that code, but xterm does. So a spiffy advantage to you xterm people.
Back to top
View user's profile Send private message
meowsqueak
Veteran
Veteran


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

PostPosted: Sat May 08, 2004 7:39 am    Post subject: Re: pasting data Reply with quote

pagerc@ufl.edu wrote:
You guys make everything so complicated. shift Insert should paste into a terminal window. Before there was vga, there was console, so everything can be done on a console just as well as gui.


Curious - didn't know that one. BTW, how do you make a selection in the console?
Back to top
View user's profile Send private message
Gentree
Watchman
Watchman


Joined: 01 Jul 2003
Posts: 5350
Location: France, Old Europe

PostPosted: Sat May 08, 2004 9:32 am    Post subject: Re: pasting data Reply with quote

pagerc@ufl.edu wrote:
You guys make everything so complicated. shift Insert should paste into a terminal window. Before there was vga, there was console, so everything can be done on a console just as well as gui. :)

Oh, about that : ; thingy, seems that you can use a color status of \[\e[8m\] before either of those characters should make it be invisible in an xterm. I use aterm for transparencies and know that aterm does not support that code, but xterm does. So a spiffy advantage to you xterm people.


Thanks, I knew there would a key stroke, its just that man pages can be hard work !

I remember using Honeywell Multics about 20 years ago and the doc was _just_ the same. Incredible how everything else in technology has developed by orders of magnitude but Unix man pages are still in the age of the valve powered computer.

(Heh, that should be good for an arguement.) :twisted:

Seriously , maybe I've missed something but when I was looking for this copy/paste issue I spent half an hour in man xterm and gave up. I did find the bit on how to select text but not keystoke to paste.

Could this work off the num. pad insert key? Mine wont, with or without numlock. Is this another config I need to do? (I pull the other insert key off my kb because I find it too easy to accedentally hit when using backspace and find myself in overwrite mode without knowing. Annoying)

Thanks again for the key. 8)
Back to top
View user's profile Send private message
peterton
Tux's lil' helper
Tux's lil' helper


Joined: 20 Aug 2003
Posts: 110

PostPosted: Mon May 24, 2004 9:09 pm    Post subject: Reply with quote

shoud you not have /usr/bin/battery but do have acpi emerged, try this one:
Code:
export PS1="\`acpi | gawk '{ print \$4 }' | sed s/,//\` \[\033[01;32m\]\u@\h \[\033[01;34m\]\W \$ \[\033[00m\]"

basically it's an update of the apm one
Back to top
View user's profile Send private message
Gentree
Watchman
Watchman


Joined: 01 Jul 2003
Posts: 5350
Location: France, Old Europe

PostPosted: Mon May 24, 2004 9:22 pm    Post subject: Reply with quote

Could you run that again?

I did not quite understand your english as to what it was for and I sure cant follow the script . Could you briefly say what it does.

Dank u well. 8)
Back to top
View user's profile Send private message
peterton
Tux's lil' helper
Tux's lil' helper


Joined: 20 Aug 2003
Posts: 110

PostPosted: Mon May 24, 2004 10:19 pm    Post subject: Reply with quote

Sorry about that.
In the beginning of the thread bert wrote about the apm version:
Code:
PS1="\`apm|awk '\$5~/%/{print \$5}\$6~/%/{print \$6}'\` [\\u@\\h:\\w] \\$ "

And then dvc5 wrote an acpi one:
Code:
PS1="\[\033[01;34m\]\`/usr/bin/battery|awk '{print \$2}'\` \[\033[01;32m\]\u@\h \[\033[01;34m\]\W \$ \[\033[00m\]"

(or got it from this thread)
I changed berts version to use acpi (for which you'll need to run 'emerge acpi') instead of /usr/bin/battery
It looks like:
Code:
100% peterton@cerberos / $

All I need to fix is the fact that 100% shows as a space. I don't want it to show at all. Sounds like a simple if :wink:
edit
i fixed that now, this is the final:
Code:
export PS1="\`acpi | gawk '{ print \$4 }' | sed s/,/\ /\`\[\033[01;32m\]\u@\h \[\033[01;34m\]\W \$ \[\033[00m\]"

8)
/edit
Back to top
View user's profile Send private message
pagerc@ufl.edu
n00b
n00b


Joined: 02 Jan 2004
Posts: 15

PostPosted: Thu May 27, 2004 3:59 am    Post subject: 1 reply and 1 big update Reply with quote

Make a selection on the console? Use a mouse? Or use screen, enter copy mode. Don't use screen? Well I should hit you over the head. Do you use Konsole, MultiGnomeTerm, or any multi terminal emulator? If so, I should hit you with a cluebie bat so that you will use screen!!!

Screen is very very cool. My screenrc:
http://fidget.cns.ufl.edu/~pagerc/screenrc

Now about my bash prompt. I've updated most everything I intend to. It colorizes most everything. Does coloring of pwd based on permissions, does lots of directory analysis, does emerge finding, and it all is *fast*. I took the time to only use tools that are in /bin (except for apm/acpi). And I use sed over awk/grep to ensure fast execution. Colors hostname based on system load. Colors users vs root. Colors prompt for exit status. Colors battery percentage colors temperature. Yes, this is the prompt *you* want to use!

http://fidget.cns.ufl.edu/~pagerc/prompt
Back to top
View user's profile Send private message
meowsqueak
Veteran
Veteran


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

PostPosted: Thu May 27, 2004 11:16 pm    Post subject: Re: 1 reply and 1 big update Reply with quote

pagerc@ufl.edu wrote:
Make a selection on the console? Use a mouse? Or use screen, enter copy mode. Don't use screen? Well I should hit you over the head.


Now now, there's no need to be arrogant. Most machines that don't run X probably don't have a mouse either (e.g. headless firewalls with serial consoles). I am well aware of screen, it just didn't occur to me to use copy mode for cutting and pasting. Thanks for the bash prompt.

BTW, do you find that \$ in PS1 doesn't show # and shows $ instead for root?
Back to top
View user's profile Send private message
pagerc@ufl.edu
n00b
n00b


Joined: 02 Jan 2004
Posts: 15

PostPosted: Tue Jun 08, 2004 6:04 am    Post subject: Reply with quote

\$ is a bash interpreted escape sequence for the PS1.
It's supposed to show $/# for user/root. I consider it a feature.

I didn't mean to be arrogant, but a lot of people don't know about screen and everyone should use screen. So perhaps I'm cocky about screen and a die hard screen evangelist (there's those that love distros, but I love screen). Sorry if I ruffled your feathers, I'll try to be less head offish in the future.

I feel done with my spiffy prompt. It's here:
http://fidget.cns.ufl.edu/~pagerc/prompt

and a corresponding screen shot:
http://fidget.cns.ufl.edu/~pagerc/sweet.png

At the end of my prompt, there's all the escapes. At the beginning I list the URL for Giles Orr's webpage on Bash Prompt howto stuff.


Last edited by pagerc@ufl.edu on Sat Jun 12, 2004 8:46 am; edited 1 time in total
Back to top
View user's profile Send private message
meowsqueak
Veteran
Veteran


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

PostPosted: Tue Jun 08, 2004 6:58 am    Post subject: Reply with quote

pagerc@ufl.edu wrote:
\$ is a bash interpreted escape sequence for the PS1.
It's supposed to show #/$ for user/root. I consider it a feature.


Yup - but that's not quite what I was getting at - I use \$ too, but these days it seems to display a $ for root, rather than a #. I've tried this on my debian box, two gentoo boxes and a redhat 9 box too - each one shows $ not # for root. Not sure what I'm doing wrong here if anything at all - it used to work and it's too straightforward to stuff up!

Or are you saying root should be $ and user should be #? If so, then it used to work backwards and now doesn't work at all...
Back to top
View user's profile Send private message
pagerc@ufl.edu
n00b
n00b


Joined: 02 Jan 2004
Posts: 15

PostPosted: Sat Jun 12, 2004 8:21 am    Post subject: Reply with quote

Apparently it's a bug with something I've done or bash. Bash *does* do \$ translation to # for root users. However I've definitely broken it in a few attempts of verifying the # behavior. That's to say I can't get a hash anymore. And that's rather disturbing because I like the hash. I'll see if I can figure out what the problem is.
Back to top
View user's profile Send private message
pagerc@ufl.edu
n00b
n00b


Joined: 02 Jan 2004
Posts: 15

PostPosted: Sat Jun 12, 2004 8:32 am    Post subject: Reply with quote

ugg, I hate scripting, I never know what level of depth is being handled by what. 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 \\\$. It's gross, yes, but necessary with the escaping mechanisms in bash. The first 2 \\'s escape to a '\' the second one "\$" escapes to a '$' then this can be assigned to your PS1 variable, which will have as a string echo PS1 "\$". When PS1 is displayed, it will properly interpret this new escape sequence. The problem with my script is that the code is being interpreted by bash as a string whereas a straight assignment to PS1 is not interpreted by bash (the string isn't interpreted the same) until it is being displayed and then uses what I presume is a different escaping mechanism so you can have \W \u etc.

Anyways, my prompt should be updated with this fix for anyone who cares.
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 5 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