View previous topic :: View next topic |
Author |
Message |
Bangz Tux's lil' helper
Joined: 23 Jan 2003 Posts: 148 Location: Brisbane/Austrralia
|
Posted: Thu Jun 05, 2003 12:17 pm Post subject: |
|
|
Cheers Buddy!
As I said, I'm not much of a bash scripter |
|
Back to top |
|
|
theine n00b
Joined: 08 Jun 2003 Posts: 7
|
Posted: Wed Jun 11, 2003 12:57 pm Post subject: |
|
|
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 |
|
|
carrett Apprentice
Joined: 22 Mar 2003 Posts: 273
|
Posted: Mon Jul 07, 2003 12:32 am Post subject: |
|
|
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 |
|
|
brettlpb Apprentice
Joined: 27 May 2003 Posts: 197
|
Posted: Wed Jul 09, 2003 4:34 am Post subject: ... |
|
|
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 |
|
|
razamatan Apprentice
Joined: 28 Feb 2003 Posts: 160
|
Posted: Wed Jul 09, 2003 6:18 am Post subject: |
|
|
why are ppl using \033 for the escape sequence character, when they can simply do a \e???
yields
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 |
|
|
Swishy Guru
Joined: 06 Jun 2002 Posts: 491 Location: NZ
|
Posted: Sun Aug 24, 2003 3:18 am Post subject: Proc Stuff ?? |
|
|
Any way to pull /proc info and add it to the bash prompt ???
Cheers
Dale. _________________ Theres no substitute for C.I. |
|
Back to top |
|
|
christsong84 Veteran
Joined: 06 Apr 2003 Posts: 1003 Location: GMT-8 (Spokane)
|
Posted: Sun Sep 21, 2003 9:16 pm Post subject: |
|
|
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);} |
|
Back to top |
|
|
st589 Tux's lil' helper
Joined: 20 Sep 2003 Posts: 83
|
Posted: Sun Sep 28, 2003 3:17 am Post subject: |
|
|
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 |
|
|
duff Guru
Joined: 19 Jun 2002 Posts: 466 Location: Clemson, SC
|
Posted: Sun Sep 28, 2003 11:40 pm Post subject: Re: Proc Stuff ?? |
|
|
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:
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 |
|
|
Slinger Apprentice
Joined: 14 Dec 2002 Posts: 230
|
Posted: Mon Oct 20, 2003 11:03 am Post subject: |
|
|
tag |
|
Back to top |
|
|
Qweasda Apprentice
Joined: 04 Feb 2003 Posts: 152
|
Posted: Mon Oct 20, 2003 3:56 pm Post subject: |
|
|
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 |
|
|
dub.wav Tux's lil' helper
Joined: 09 Apr 2003 Posts: 149 Location: Norway
|
Posted: Mon Oct 20, 2003 4:31 pm Post subject: |
|
|
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 |
|
|
meowsqueak Veteran
Joined: 26 Aug 2003 Posts: 1549 Location: New Zealand
|
Posted: Wed Oct 22, 2003 10:57 pm Post subject: |
|
|
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 |
|
|
gdoubleu Tux's lil' helper
Joined: 07 May 2003 Posts: 80
|
Posted: Fri Nov 07, 2003 8:40 pm Post subject: |
|
|
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 |
|
|
gdoubleu Tux's lil' helper
Joined: 07 May 2003 Posts: 80
|
Posted: Fri Nov 07, 2003 9:09 pm Post subject: |
|
|
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:
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 where you want it to show up |
|
Back to top |
|
|
gdoubleu Tux's lil' helper
Joined: 07 May 2003 Posts: 80
|
Posted: Fri Nov 07, 2003 9:55 pm Post subject: |
|
|
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:
and finally, with 20 in front and 20 in back: Code: | /home/gdub/websites/images/backgrounds |
|
|
Back to top |
|
|
gdoubleu Tux's lil' helper
Joined: 07 May 2003 Posts: 80
|
Posted: Fri Nov 07, 2003 10:00 pm Post subject: |
|
|
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 |
|
|
meowsqueak Veteran
Joined: 26 Aug 2003 Posts: 1549 Location: New Zealand
|
Posted: Sun Nov 09, 2003 8:11 am Post subject: |
|
|
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 |
|
|
Jeedo Apprentice
Joined: 02 May 2003 Posts: 202 Location: Akureyri, Iceland
|
Posted: Sun Nov 09, 2003 4:30 pm Post subject: |
|
|
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 |
|
|
odegard Guru
Joined: 08 Mar 2003 Posts: 324 Location: Trondheim, NO
|
Posted: Mon Nov 10, 2003 8:04 am Post subject: |
|
|
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 |
|
|
grosquick n00b
Joined: 26 Nov 2003 Posts: 2
|
Posted: Mon Dec 22, 2003 5:25 pm Post subject: |
|
|
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 |
|
|
ILikePi n00b
Joined: 29 Nov 2003 Posts: 22 Location: Rhode Island, USA
|
Posted: Tue Dec 23, 2003 1:04 am Post subject: |
|
|
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 |
|
|
khazad-dum Tux's lil' helper
Joined: 26 May 2003 Posts: 148 Location: Moria
|
|
Back to top |
|
|
dalek Veteran
Joined: 19 Sep 2003 Posts: 1353 Location: Mississippi USA
|
Posted: Wed Jan 14, 2004 4:25 am Post subject: |
|
|
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.
_________________ 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 |
|
|
Brother Dysk Tux's lil' helper
Joined: 29 Sep 2003 Posts: 131 Location: Hong Kong SAR PRC
|
Posted: Wed Jan 21, 2004 8:27 am Post subject: |
|
|
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 |
|
|
|