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
Bangz
Tux's lil' helper
Tux's lil' helper


Joined: 23 Jan 2003
Posts: 148
Location: Brisbane/Austrralia

PostPosted: Thu Jun 05, 2003 12:17 pm    Post subject: Reply with quote

Cheers Buddy!

As I said, I'm not much of a bash scripter :)
Back to top
View user's profile Send private message
theine
n00b
n00b


Joined: 08 Jun 2003
Posts: 7

PostPosted: Wed Jun 11, 2003 12:57 pm    Post subject: Reply with quote

to run all shells in xterm as login shells you can also put this into your ~/.Xresources file:
Code:

XTerm*loginShell: true
Back to top
View user's profile Send private message
carrett
Apprentice
Apprentice


Joined: 22 Mar 2003
Posts: 273

PostPosted: Mon Jul 07, 2003 12:32 am    Post subject: Reply with quote

mine:

Code:
PS1="\[\033[0;31m\][\h]\[\033[1;32m\][\w]$\[\033[0m\] "


i loves it.

it makes stuff like:

[duder][/usr/portage/distfiles]$
_________________
I'm against picketing, but I don't know how to show it.
Back to top
View user's profile Send private message
brettlpb
Apprentice
Apprentice


Joined: 27 May 2003
Posts: 197

PostPosted: Wed Jul 09, 2003 4:34 am    Post subject: ... Reply with quote

Can anyone help me combine two prompts? I'm a newbie at this... I looked over some bash scripting guides... which help with loops, and variables... but these prompts seem to use numbers that indicate something I can't quite figure out.

I want to use this one:

Code:
PS1='\n\[\033[32m\]\w\n\[\033[0m\][\[\033[1;31m\]\u@\h \[\033[1;34m\]$(/usr/bin/tty | /bin/sed -e '\''s:/dev/::'\'')\[\033[0m\]] \[\033[0m\]'


Which is this:

Quote:
/usr/portage
[user@hostname pty/s0]


But then I want to use the APM Battery one (I'm on a laptop)

Code:
PS1="\[\033[01;3\`apm|awk '\$2~/on-line/{print "2"; exit}\$5~/high/{print "3"}\$5~/low/{print "1"}'\`m\]\`apm|awk '\$5~/%/{print \$5}\$6~/%/{print \$6}'\` \[\033[01;31m\]\u@\h \[\033[01;34m\]\W \$ \[\033[00m\]"


Which is this:

Quote:
100% user@hostname directory $


...

What I would like to do is make it like this:

Quote:
/usr/portage
100% user@hostname pty/s0


Thanks in advance!
Back to top
View user's profile Send private message
razamatan
Apprentice
Apprentice


Joined: 28 Feb 2003
Posts: 160

PostPosted: Wed Jul 09, 2003 6:18 am    Post subject: Reply with quote

why are ppl using \033 for the escape sequence character, when they can simply do a \e???

Code:
\h[\! \W]\$

yields
Code:
mycpu[32 dir]$


is the general setup stripped of all colors.... the hostname is green for users and red for root. the []'s are dark red... and yeah.. i use \e instead of \033 when i start my color codes... hehe...

btw.. is there a reason why i should do \033 instead of \e???
_________________
a razamatan doth speaketh,
"Never attribute to malice, that which can be adequately explained by stupidity"
Back to top
View user's profile Send private message
Swishy
Guru
Guru


Joined: 06 Jun 2002
Posts: 491
Location: NZ

PostPosted: Sun Aug 24, 2003 3:18 am    Post subject: Proc Stuff ?? Reply with quote

Any way to pull /proc info and add it to the bash prompt ???

Cheers
Dale.
_________________
Theres no substitute for C.I.
Back to top
View user's profile Send private message
christsong84
Veteran
Veteran


Joined: 06 Apr 2003
Posts: 1003
Location: GMT-8 (Spokane)

PostPosted: Sun Sep 21, 2003 9:16 pm    Post subject: Reply with quote

Code:
export PS1="\[\033[01:32m\][\e7\e[0;71H\@\e8\]\[\033[01;3\`apm|awk '\$2~/on-line/{print "2"; exit}\$5~/high/{print "3"}\$5~/low/{print "1"}'\`m\]\`apm|awk '\$5~/%/{print \$5}\$6~/%/{print \$6}'\` \[\033[01;31m\]\u@\h \[\033[01;34m\]\W \$ \[\033[00m\]"


The above is my code for my root user. It gives the time in thetop right corner and the prompt itself looks like

Quote:

[100%root@psalmsswells $


I was wondering...how do I either add a closing ] to the power indicator (yes it's a lappie) or remove the initial one?

I'm not hugely experienced in shell scripting...what I have there was pasted together from a few of the ones previously.

Thanks!
_________________
while(true) {self.input(sugar);} :twisted:
Back to top
View user's profile Send private message
st589
Tux's lil' helper
Tux's lil' helper


Joined: 20 Sep 2003
Posts: 83

PostPosted: Sun Sep 28, 2003 3:17 am    Post subject: Reply with quote

I wanted to try out some of these, but I don't see where in the ~/.bashrc file to put the text. My file doesn't have "export PS1=" anywhere in it. Should I just add it to the bottom?
Back to top
View user's profile Send private message
duff
Guru
Guru


Joined: 19 Jun 2002
Posts: 466
Location: Clemson, SC

PostPosted: Sun Sep 28, 2003 11:40 pm    Post subject: Re: Proc Stuff ?? Reply with quote

Swishy wrote:
Any way to pull /proc info and add it to the bash prompt ???
Sure, you can use the normal grep/sed/cat/awk/etc tools on any of the files or directories in the /proc filesystem. fx; if you want the prompt to show the number of running processes and the amount of memory available, you could set PS1 to:
Code:
export PS1="[$(find /proc -type d -regex '/proc/[0-9]+' -maxdepth 1 | wc | awk '{print $2}'):$(grep 'MemTotal' /proc/meminfo | awk '{print $2}')Kb] \$"

Not a particularly useful prompt, but it should get the point across. On my system it shows:
Code:
[84:8280Kb] $
For 84 active processes, and almost 8Mb free (damn :()

christsong84 wrote:
Code:
export PS1="\[\033[01:32m\][\e7\e[0;71H\@\e8\]\[\033[01;3\`apm|awk '\$2~/on-line/{print "2"; exit}\$5~/high/{print "3"}\$5~/low/{print "1"}'\`m\]\`apm|awk '\$5~/%/{print \$5}\$6~/%/{print \$6}'\` \[\033[01;31m\]\u@\h \[\033[01;34m\]\W \$ \[\033[00m\]"


I was wondering...how do I either add a closing ] to the power indicator (yes it's a lappie) or remove the initial one?


Nice clock code! Filing that one away. You can add a close ] after the power meter by adding one after the final call to apm/awk...right after "{print \$6}'\`" should do it. If you want the remove the opening bracket, I'm guessing it the one right before the "\e7".

st12af wrote:
I wanted to try out some of these, but I don't see where in the ~/.bashrc file to put the text. My file doesn't have "export PS1=" anywhere in it. Should I just add it to the bottom?
Yep...anywhere in there will do.
Back to top
View user's profile Send private message
Slinger
Apprentice
Apprentice


Joined: 14 Dec 2002
Posts: 230

PostPosted: Mon Oct 20, 2003 11:03 am    Post subject: Reply with quote

tag
Back to top
View user's profile Send private message
Qweasda
Apprentice
Apprentice


Joined: 04 Feb 2003
Posts: 152

PostPosted: Mon Oct 20, 2003 3:56 pm    Post subject: Reply with quote

Nice thread.
How do I get the CWD to be just the directory your in without the leading path. i.e. /usr/src/linux shows only linux. (default prompt)?

Thanks.

Here's mine:
qweasda@~$
Back to top
View user's profile Send private message
dub.wav
Tux's lil' helper
Tux's lil' helper


Joined: 09 Apr 2003
Posts: 149
Location: Norway

PostPosted: Mon Oct 20, 2003 4:31 pm    Post subject: Reply with quote

Here's my RGB (red green blue) bash prompt.

Code:

#!/bin/bash
#you need a vga font to use this bash prompt
if [ "$UID" -ne "0" ];then
   U=$
else
   U=#
fi

function rgb {
local CLEAR="\[\033[0m\]"
local RED="\[\033[00;30;41m\]"
local GREEN="\[\033[00;30;42m\]"
local BLUE="\[\033[00;30;44m\]"
local GRAD1="\[\333\262\261\260\]"
local GRAD2="\[\260\261\262\333\]"
local EXIT='echo $?'

PS1="$RED$GRAD1[User: \u@\h]$GRAD2$GREEN$GRAD1[ExitStatus: `$EXIT`]$GRAD2$BLUE$GRAD1[Time: \$(date +%H%M)]$GRAD2$CLEAR\n\W $U> "
}

Here's how to use it: source rgb.sh && rgb. It's basically three gradient separated "boxes" (first one is red, second green, third blue) with user@hostname, ExitStatus and time. You need a vga font (for the gradient): http://home.earthlink.net/~us5zahns/enl/ansifont.html
Back to top
View user's profile Send private message
meowsqueak
Veteran
Veteran


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

PostPosted: Wed Oct 22, 2003 10:57 pm    Post subject: Reply with quote

My prompt looks like this:

Quote:
localhost:../linux/Documentation $


Notice the path has been truncated from the front? This stops it taking up more of the command line than I'd like when I'm deep inside a directory tree.
Here's the bit of magic in my .bashrc that does this:


Code:
function shorten_pwd
{
    # change this to suit your taste
    pwd_length=20
    DIR=`pwd`

    echo $DIR | /bin/grep "^$HOME" >> /dev/null

    if [ $? -eq 0 ]
    then
        CURRDIR=`echo $DIR | awk -F$HOME '{print $2}'`
        newPWD="~$CURRDIR"

    if [ $(echo -n $newPWD | wc -c | tr -d " ") -gt $pwd_length ]
    then
        newPWD="~/..$(echo -n $PWD | sed -e "s/.*\(.\{$pwd_length\}\)/\1/")"
    fi
    elif [ "$DIR" = "$HOME" ]
    then
        newPWD="~"
    elif [ $(echo -n $PWD | wc -c | tr -d " ") -gt $pwd_length ]
    then
        newPWD="..$(echo -n $PWD | sed -e "s/.*\(.\{$pwd_length\}\)/\1/")"
    else
        newPWD="$(echo -n $PWD)"
    fi

        make_prompt

        echo $PWD > ~/.pwd
}

PROMPT_COMMAND=shorten_pwd


Then elsewhere in PS1 I just use $newPWD rather than the working directory switch.

Full credit to whoever gave me this - I do not recall the source.
Back to top
View user's profile Send private message
gdoubleu
Tux's lil' helper
Tux's lil' helper


Joined: 07 May 2003
Posts: 80

PostPosted: Fri Nov 07, 2003 8:40 pm    Post subject: Reply with quote

ok, i wrote another method for shortening the pwd that seems simpler to me than the method above and can be put directly into the PS1 assignment.

put this where you want the pwd to appear:
Code:
\$(pwd | sed 's=\(.*\)\(.\{25\}\)$=\1...\2=' | sed 's=^\.\.\.\|.*\(\.\.\.\)=\1=')


the first sed inserts a '...' at the number of characters from the end that you specify. here i have used the value 25, you can change that to whatever you like.

the second sed either removes the '...' if they occur at the beginning of the string (meaning that the pwd is already shorter than then number of characters you specified, so take out the '...'), or it removes everything before the '...' in the case where the pwd is longer than the number of characters you specified.
(please let me know if you find any error in the code above, or have a better way to do the same thing)

here are my prompts, using a few of the colors and tips mentioned on the first page of this thread and the code from above (i use green on a black background):
Code:
PS1="\n$PRPL\d, \@: $NONE\$(pwd | sed 's=\(.*\)\(.\{25\}\)$=\1...\2=' | sed 's=^\.\.\.\|.*\(\.\.\.\)=\1='): \[\033[1;36m\]\$(/bin/ls -1 | /usr/bin/wc -l | /bin/sed 's: ::g') files, $YEL\$(/bin/ls -lah | /bin/grep -m 1 total | /bin/sed 's/total //')b\n$HBLU\u$WHT@$HBLU\h$NONE $HBLU#$NONE "

PS2="$HBLU\u$WHT@$HBLU\h$NONE $HBLU>$NONE "


which look something like this:
Quote:
Fri Nov 07, 02:20 PM: /home/gdub/websites: 19 files, 107Kb
gdub@nebuchadnezzar # if
gdub@nebuchadnezzar >

note: the '@' is white

and when the pwd is longer than what you specify:
Quote:
Fri Nov 07, 02:20 PM: ...bsites/images/backgrounds: 19 files, 107Kb
gdub@nebuchadnezzar #


i think next i will write something where it will trucate the pwd in the middle instead of at the beginning
Back to top
View user's profile Send private message
gdoubleu
Tux's lil' helper
Tux's lil' helper


Joined: 07 May 2003
Posts: 80

PostPosted: Fri Nov 07, 2003 9:09 pm    Post subject: Reply with quote

brettlpb wrote:
What I would like to do is make it like this:

/usr/portage
100% user@hostname pty/s0

for the pwd and newline:
Code:
\$(pwd)\n

for the next line:
Code:
\[\033[01;3\`apm|awk '\$2~/on-line/{print "2"; exit}\$5~/high/{print "3"}\$5~/low/{print "1"}'\`m\]\`apm|awk '\$5~/%/{print \$5}\$6~/%/{print \$6}'\` \u@\h \$(tty | sed 's:/dev/::')



Qweasda wrote:
Nice thread.
How do I get the CWD to be just the directory your in without the leading path. i.e. /usr/src/linux shows only linux. (default prompt)?

just put
Code:
\W
where you want it to show up
Back to top
View user's profile Send private message
gdoubleu
Tux's lil' helper
Tux's lil' helper


Joined: 07 May 2003
Posts: 80

PostPosted: Fri Nov 07, 2003 9:55 pm    Post subject: Reply with quote

try this on for size, this will truncate the pwd in the middle, just specify how many characters you want to see in the front and how many you want to see at the back. if the pwd is shorter than the sum, then the entire pwd is printed:
Code:
\$(pwd | sed 's=^\(.\{5\}\)\(.*\)\(.\{15\}\)$=\1...\2...\3=' | sed 's=\.\.\.\.\.\.==' | sed 's=\(.*\)\.\.\..*\.\.\.\(.*\)=\1...\2=')
in this case it would display 5 characters in the front and 15 in the back.

with the pwd being
Code:
/home/gdub/websites/images/backgrounds
here are some examples of what it would look like:

with 5 in front and 15 in back:
Code:
/home...ges/backgrounds

with 20 in front and 10 in back:
Code:
/home/gdub/websites/...ackgrounds

with 0 in front and 8 in back:
Code:
...kgrounds

and finally, with 20 in front and 20 in back:
Code:
/home/gdub/websites/images/backgrounds
Back to top
View user's profile Send private message
gdoubleu
Tux's lil' helper
Tux's lil' helper


Joined: 07 May 2003
Posts: 80

PostPosted: Fri Nov 07, 2003 10:00 pm    Post subject: Reply with quote

another nifty trick for the codes above, if you would like to have your home directory displayed as ~ instead, you can pipe this between the pwd and the first sed
Code:
sed "s=`echo $HOME | sed 's:\/:\\\/:g'`=~="

for a final command of
Code:
\$(pwd | sed "s=`echo $HOME | sed 's:\/:\\\/:g'`=~=" | sed 's=^\(.\{5\}\)\(.*\)\(.\{15\}\)$=\1...\2...\3=' | sed 's=\.\.\.\.\.\.==' | sed 's=\(.*\)\.\.\..*\.\.\.\(.*\)=\1...\2=')


this will turn the above into something like this
Code:
~/web...ges/backgrounds
Back to top
View user's profile Send private message
meowsqueak
Veteran
Veteran


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

PostPosted: Sun Nov 09, 2003 8:11 am    Post subject: Reply with quote

gdoubleu: thanks for those - much more compact than the code I was using. I'm going to start using them and see how they go.
Back to top
View user's profile Send private message
Jeedo
Apprentice
Apprentice


Joined: 02 May 2003
Posts: 202
Location: Akureyri, Iceland

PostPosted: Sun Nov 09, 2003 4:30 pm    Post subject: Reply with quote

bert wrote:
Here's a bash prompt that shows battery status on a laptop. Needs apm tools / kernel support available (and awk).

Code:
PS1="\`apm|awk '\$5~/%/{print \$5}\$6~/%/{print \$6}'\` [\\u@\\h:\\w] \\$ "


.. and this is what it looks like

Quote:
100% [bert@brahms:~/movies] $
99% [bert@brahms:~/movies] $


I edited it for my laptop (iBook) so that it needs no apm tools, just cat's the /proc/apm file
Code:

PS1="\[\033[01;34m\]\`cat /proc/apm|awk '{print \$7}'\` \[\033[01;32m\]\u@\h \[\033[01;34m\]\w \$ \[\033[00m\]"

Quote:

98% jeedo@Rancorwe ~ $
Back to top
View user's profile Send private message
odegard
Guru
Guru


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

PostPosted: Mon Nov 10, 2003 8:04 am    Post subject: Reply with quote

This is mine

Code:

PS1="\[\033[0;37m\]\t\[\033[0m\] \[\033[0;31m\]\u\[\033[0;0m\] \w # "


and of course, I start my xterm with

Code:

xterm -bg black -fg Limegreen


which will produce this sexy and informative prompt
[img:5fc503f7ef]http://www.theodegards.com/agnar/bash.png[/img:5fc503f7ef]
Back to top
View user's profile Send private message
grosquick
n00b
n00b


Joined: 26 Nov 2003
Posts: 2

PostPosted: Mon Dec 22, 2003 5:25 pm    Post subject: Reply with quote

Oh great.. nice one...simple and informative..the way bash should be imho

Is there a way to blink some text ??
Imagine a battery status 5% => prompt blinking.. 1% beep :)
Back to top
View user's profile Send private message
ILikePi
n00b
n00b


Joined: 29 Nov 2003
Posts: 22
Location: Rhode Island, USA

PostPosted: Tue Dec 23, 2003 1:04 am    Post subject: Reply with quote

blink is supposed to be:

set on: \033[5m
set off: \033[25m

but on my box it doesn't work...it just makes the background color medium grey. suck! see 'man 4 console_codes' for the rest of the codes.
_________________
Keyboard not found.
Press F1 to continue.
Back to top
View user's profile Send private message
khazad-dum
Tux's lil' helper
Tux's lil' helper


Joined: 26 May 2003
Posts: 148
Location: Moria

PostPosted: Fri Dec 26, 2003 6:32 pm    Post subject: Reply with quote

How to replicate this prompt?

http://www.vlaadworld.net/screens/shot20030102.jpg

Thx in advance
Back to top
View user's profile Send private message
dalek
Veteran
Veteran


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

PostPosted: Wed Jan 14, 2004 4:25 am    Post subject: Reply with quote

NEWBIE ALERT!

I would like to change my prompt. I have read some of this thread but does not change when I change the .bashrc file. This is the one that is in /home/dale. It is the only one I could find. There is none in /root. This is the file.

Code:
# /etc/skel/.bashrc:
# $Header: /home/cvsroot/gentoo-src/rc-scripts/etc/skel/.bashrc,v 1.8 2003/02/28 15:45:35 azarah Exp $

# This file is sourced by all *interactive* bash shells on startup.  This
# file *should generate no output* or it will break the scp and rcp commands.

# colors for ls, etc.
eval `dircolors -b /etc/DIR_COLORS`
alias d="ls --color"
alias ls="ls --color=auto"
alias ll="ls --color -l"

PS1="\n\[\033[35m\]\$(/bin/date)\n\[\033[32m\]\w\n\[\033[1;31m\]\u@\h: \[\033[1;34m\]\$(/usr/bin/tty | /bin/sed -e 's:/dev/::'): \[\033[1;36m\]\$(/bin/ls -1 | /usr/bin/wc -l | /bin/sed 's: ::g') files \[\033[1;33m\]\$(/bin/ls -lah | /bin/grep -m 1 total | /bin/sed 's/total //')b\[\033[0m\] -> \[\033[0m\]"


# Change the window title of X terminals
case $TERM in
   xterm*|rxvt|Eterm|eterm)
      PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/$HOME/~}\007"'
      ;;
   screen)
      PROMPT_COMMAND='echo -ne "\033_${USER}@${HOSTNAME%%.*}:${PWD/$HOME/~}\033\\"'
      ;;
esac

##uncomment the following to activate bash-completion:
[ -f /etc/profile.d/bash-completion ] && source /etc/profile.d/bash-completion



I pasted the PS1 line in there but there is no change. I thought that one was kind of neat.

What am I doing wrong, wrong file maybe? I am trying to change the Konsole that I use in KDE. Will this also change the normal command line prompt, one that is not inside a GUI? Ya know like the one that you get when you are installing Gentoo.

Thanks in advance for the help.

8O 8O :? :? :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
Brother Dysk
Tux's lil' helper
Tux's lil' helper


Joined: 29 Sep 2003
Posts: 131
Location: Hong Kong SAR PRC

PostPosted: Wed Jan 21, 2004 8:27 am    Post subject: Reply with quote

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:\*)
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 4 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