DaemonForums  

Go Back   DaemonForums > Miscellaneous > Guides

Guides All Guides and HOWTO's.

Reply
 
Thread Tools Display Modes
  #1   (View Single Post)  
Old 3rd December 2009
tetrodozombie tetrodozombie is offline
Real Name: bill slusser
Banned
 
Join Date: Dec 2009
Location: atlanta, ga
Posts: 82
Wink Color Prompt in OpenBSD.

I've worked long and hard to figure out how to make my prompts in color on OpenBSD and FreeBSD. OpenBSD rocks, so we'll forget we ever used FreeBSD from this point on. Here it is:

In your .kshrc file OR your .profile, add these two lines.

Code:
print "\033[1;34m"
PS1='| $PWD | '
THAT's ALL!

Log out and log back in or type this at the command line:
(If you put it in your .kshrc like I do) --> (don't type this)
. .kshrc
(type that above), two dots separated by a space then kshrc next to the last dot.

( If you like to put it in your .profile )
type this at the command line:
. .profile

But, a newbie would definitely log out and log back in.

Voila!

If you used [1;34m you're gonna get a real nice light blue on black that honors the work the guys do who make OpenBSD a reality for us retards.

Go blue, I'm sick of using that Matrix Neo wanna be green on black color scheme for the command line, are you? Yet?

Last edited by J65nko; 3rd December 2009 at 03:05 AM. Reason: Added code tags ;)
Reply With Quote
  #2   (View Single Post)  
Old 3rd December 2009
J65nko J65nko is offline
Administrator
 
Join Date: May 2008
Location: Budel - the Netherlands
Posts: 4,125
Default

Instead of using $PWD you can use \w
Code:
PS1="\u@\h[\w]"
export PS1
This produces the following as prompt:
Code:
j65nko@hercules[~/Snapshots]
BTW Thanks for your post, I will be moving this to the guides section
__________________
You don't need to be a genius to debug a pf.conf firewall ruleset, you just need the guts to run tcpdump
Reply With Quote
  #3   (View Single Post)  
Old 3rd December 2009
BSDfan666 BSDfan666 is offline
Real Name: N/A, this is the interweb.
Banned
 
Join Date: Apr 2008
Location: Ontario, Canada
Posts: 2,223
Default

Colour terminals are quite distracting, I can't see how they would be beneficial.. the whole thing just reeks of default GNU/Linux behaviour.

While you are free to abuse ANSI colour codes, please do so on some remote server.. preferably located in Antarctica, or near Mars.
Reply With Quote
  #4   (View Single Post)  
Old 3rd December 2009
tetrodozombie tetrodozombie is offline
Real Name: bill slusser
Banned
 
Join Date: Dec 2009
Location: atlanta, ga
Posts: 82
Default

Color terminals are distracting, but the very first computer I programmed on had an Amber Terminal (small, but lovely) back in 1982. I was in second grade, and the school had a computer lab. We got to program Logo!!! Yes. that's right. Logo! I know there are folks out there who've never heard of Logo, but it has warm memories for me. I was in shock and awe at the sight of a computer back in those days. I couldn't imagine doing anything else with my life other than sitting in front of a computer for long hours at a time programming and solving problems. But, it's even better now that we can add images and color. Life without color isn't as exciting as life with color. I'm not saying that we need to over use color. But, a teeny tiny bit of color in an otherwise gray world makes the sun come out in my eyes. Just a little color, not a whole lot.

Try that blue I'm using and see if it grows on you.
Reply With Quote
  #5   (View Single Post)  
Old 3rd December 2009
tetrodozombie tetrodozombie is offline
Real Name: bill slusser
Banned
 
Join Date: Dec 2009
Location: atlanta, ga
Posts: 82
Default

Thanks for letting me know about "[ \w ]" as an alternative to " $PWD ". I tried that once a long time ago and it didn't work on OpenBSD, but things change. Now I don't have to begin new lines so much.
Reply With Quote
  #6   (View Single Post)  
Old 3rd December 2009
J65nko J65nko is offline
Administrator
 
Join Date: May 2008
Location: Budel - the Netherlands
Posts: 4,125
Default

You can check the OpenBSD ksh man page which special characters are supported in the PS1 prompt. Search for 'PS1' to find find them.

RE: Logo
A couple of weeks I was reading Seymour Papert's book 'Mindstorms' about the idea's about Logo, and the influence of Piaget's ideas on his theory how children/humans learn.

I bought a Windows 3..1 Logo implementation for my daughter when she was young, but at that time she wasn't too interested. Now she studies electrical engineering and develops web apps in PHP as a side-line job. So you never know if it had any influence
__________________
You don't need to be a genius to debug a pf.conf firewall ruleset, you just need the guts to run tcpdump
Reply With Quote
  #7   (View Single Post)  
Old 3rd December 2009
BSDfan666 BSDfan666 is offline
Real Name: N/A, this is the interweb.
Banned
 
Join Date: Apr 2008
Location: Ontario, Canada
Posts: 2,223
Default

Quote:
Originally Posted by tetrodozombie View Post
Color terminals are distracting, but the very first computer I programmed on had an Amber Terminal (small, but lovely) back in 1982. I was in second grade, and the school had a computer lab. We got to program Logo!!! Yes. that's right. Logo! I know there are folks out there who've never heard of Logo, but it has warm memories for me. I was in shock and awe at the sight of a computer back in those days. I couldn't imagine doing anything else with my life other than sitting in front of a computer for long hours at a time programming and solving problems. But, it's even better now that we can add images and color. Life without color isn't as exciting as life with color. I'm not saying that we need to over use color. But, a teeny tiny bit of color in an otherwise gray world makes the sun come out in my eyes. Just a little color, not a whole lot.

Try that blue I'm using and see if it grows on you.
The ministry of education here in Ontario/Canada used Unisys ICON computers (..186/286, proprietary) which ran an ancient version of QNX.. they were all destroyed I hear.

It had an implementation of Logo, I remember it being taught in class (..basically, type this in and watch the fancy graphics).

Daisy chained systems, coaxial networking.. loud obnoxious internal speakers.. lots of memories.
Reply With Quote
  #8   (View Single Post)  
Old 3rd December 2009
jb_daefo jb_daefo is offline
Spam Deminer
 
Join Date: May 2008
Posts: 303
Default

(number)(user)=====(pwd)====
1... number of the command in history
2... current logged in user name
pwd... I use spacers (== or equilvalent) around it,
and set apart from the other two items.
If it is at the left
it is ( *here* )
HARDER TO READ without actually looking for it...
most of which
some posts above this one already implement.
__________________
FreeBSD 13-STABLE

Last edited by jb_daefo; 4th December 2009 at 06:45 AM.
Reply With Quote
  #9   (View Single Post)  
Old 4th December 2009
tetrodozombie tetrodozombie is offline
Real Name: bill slusser
Banned
 
Join Date: Dec 2009
Location: atlanta, ga
Posts: 82
Default

I didn't mention this earlier because I didn't want to confuse any noobs who might want to try the color prompt, but I've found on OpenBSD, if you use an ascii code for blinking you can make the pwd blink then close the blink with an ascii code and begin the code I posted above to set the color. you can even combine the blink with a red color and close both of them, before you apply the blue color. Trick is, don't close the blue color and all the text afterwards will be blue. I think I've implemented a short shell script to apply blue ( you can make simple shell scripts to apply any color ) if you lose that color for some reason. But "blinking" is kinda cool, but WAY too distracting for me.
Reply With Quote
Old 4th December 2009
TerryP's Avatar
TerryP TerryP is offline
Arp Constable
 
Join Date: May 2008
Location: USofA
Posts: 1,547
Default

I always set my prompt to 'username@hostname-$ ' where the $ is colour coded based on the shell and the host. I find it helps me remember which machine I'm typing at, and the colored dollar sign for when I'm about to pass out.


Getting colour prompts to work without getting annoyed at different ksh implementations, resulted in this in my ~/.${LOGNAME}_shrc:

Code:
 #
             # The various korn shells handle escape codes in prompts
             # rather differently from one another. This method appears
             # to work on all ksh implementations and plays nicely with
             # VT102 emulators like rxvt perfectly fine.
             #
             # Special thanks to Scotto for this technique.
             #
             PS1='^[^M${USER}@^[[1;37m${HOSTNAME}^[[0;36m$^[[0;0m '
and is only executed for the ksh family. The odd control characters being created with control+v followed with the suitable character.


OpenBSDs implementation seems to be the best for getting a colour prompt, without aggravation. My profile however.... covers most forms of Bourne shell in script.
__________________
My Journal

Thou shalt check the array bounds of all strings (indeed, all arrays), for surely where thou typest ``foo'' someone someday shall type ``supercalifragilisticexpialidocious''.
Reply With Quote
Old 5th December 2009
tetrodozombie tetrodozombie is offline
Real Name: bill slusser
Banned
 
Join Date: Dec 2009
Location: atlanta, ga
Posts: 82
Default

set a function before you set the prompt like this:

showblu()
{
print "\033[01;34m"
}

PS1='$(showblu)|\w| '

That will keep you from losing color if you compile source from the ports collection.
But, still, you lose color in Vim and Vi. That's where you need colorschemes like pablo and murphy.

Hope this helps somebody who's a stickler for color text like me. I found a way easy way to do it in FreeBSD about a year ago, on the command line, type: vidcontrol -fg green.

I think it's like that. Can't remember, but if you man vidcontrol, it's right there. Put that vidcontrol line in a .profile or .sh script and you've got color. Also, in FreeBSD, vidcontrol can give you and underlined color cursor if you set vidcontrol to desctructive. You also have the option of using vidcontrol to set the reverse bg and fg colors, so when you use a man page you get a really really wicked looking man page.
Reply With Quote
Old 5th December 2009
indienick indienick is offline
Lisp Junkie
 
Join Date: Apr 2009
Location: London, ON, Canada
Posts: 27
Default

Quote:
Originally Posted by BSDfan666 View Post
The ministry of education here in Ontario/Canada used Unisys ICON computers (..186/286, proprietary) which ran an ancient version of QNX.. they were all destroyed I hear.
*sniffle* The memories...

Thanks for the colourization note; I always wanted to spruce up my OpenBSD console, but never had the time (or inclination) to delve to deeply into it (read: work).

I am going to see if I can find the codes for a nice orangey-yellow. Not quite amber, but not quite the yellow on Puffy, either.
Reply With Quote
Old 5th December 2009
TerryP's Avatar
TerryP TerryP is offline
Arp Constable
 
Join Date: May 2008
Location: USofA
Posts: 1,547
Default

Quote:
Originally Posted by tetrodozombie View Post
set a function before you set the prompt like this:

showblu()
{
print "\033[01;34m"
}

PS1='$(showblu)|\w| '

That will keep you from losing color if you compile source from the ports collection.
But, still, you lose color in Vim and Vi. That's where you need colorschemes like pablo and murphy.

Hope this helps somebody who's a stickler for color text like me. I found a way easy way to do it in FreeBSD about a year ago, on the command line, type: vidcontrol -fg green.
If you want all the text one colour, set it that way.

For sane people, they would want a prompt to turn the colour change off afterwards.
__________________
My Journal

Thou shalt check the array bounds of all strings (indeed, all arrays), for surely where thou typest ``foo'' someone someday shall type ``supercalifragilisticexpialidocious''.
Reply With Quote
Old 6th December 2009
marcolino's Avatar
marcolino marcolino is offline
Real Name: Mark
Custom Title Maker
 
Join Date: May 2008
Location: At the Mountains of Madness
Posts: 128
Default

Since we're sharing PS1 definitions, here's my most recent:
Code:
export PS1='\[^[[1;36m\]\u\[^[[1;37m\]@\[^[[1;32m\]\h\[^[[0;34m\]\
(\l)\[^[[0m\]:\[^[[0;31m\]\w\[^[[0m\]\$ '
Taken directly from my ~/.kshrc. I can see with which account I am logged in, what server, the terminal name and the current directory.
__________________
That's nothing a couple o' pints wouldn't fix.
Reply With Quote
Old 16th February 2011
plex plex is offline
Real Name: Ronnie
New User
 
Join Date: Feb 2011
Location: Sweden
Posts: 3
Default

Nice, i only get some problems after i lauched top or vi editor. Then after quitting the programs. Then console colors are all default again :-/

Any ideas?
Reply With Quote
Old 17th February 2011
marcolino's Avatar
marcolino marcolino is offline
Real Name: Mark
Custom Title Maker
 
Join Date: May 2008
Location: At the Mountains of Madness
Posts: 128
Default

Odd. plex, what is your TERM variable?
Code:
$ echo $TERM
Also, does this happen at the console (outside of X.org), or solely in an xterm window?
__________________
That's nothing a couple o' pints wouldn't fix.
Reply With Quote
Old 18th February 2011
plex plex is offline
Real Name: Ronnie
New User
 
Join Date: Feb 2011
Location: Sweden
Posts: 3
Default

Hi marcolino
I'm using vt220 which comes as standard in openbsd 4.8, it's just the colors that resets when i want to launch vi or top for example. I've been editing the .profile to make the options above
Reply With Quote
Old 18th February 2011
plex plex is offline
Real Name: Ronnie
New User
 
Join Date: Feb 2011
Location: Sweden
Posts: 3
Default

ok I see, it functions inside of x.org and fluxbox (XTERM). It's only problems outside (VT220) so it's ok I'm satisfied to have this functioning inside of x.org with (XTERM) :-)

Thanks Marcolino!
Reply With Quote
Old 13th April 2013
LeFrettchen's Avatar
LeFrettchen LeFrettchen is offline
Marveled user
 
Join Date: Aug 2012
Location: France
Posts: 405
Default

Quote:
Originally Posted by plex View Post
Nice, i only get some problems after i lauched top or vi editor. Then after quitting the programs. Then console colors are all default again
Same problem for me.

Code:
# echo $TERM
vt220
Quote:
Originally Posted by marcolino View Post
Also, does this happen at the console (outside of X.org), or solely in an xterm window?
Quote:
Originally Posted by plex View Post
ok I see, it functions inside of x.org (...). It's only problems outside (VT220)
Idem, it works perfectly with X.org, but bugs on the main console vt220 (out of X).

Same behavior with OBSD 5.2_i386, 5.3s_i386 and 5.3s_SPARC64.
Reply With Quote
Reply

Thread Tools
Display Modes

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 On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Nicer Prompt with ksh on 5.0 nihonto NetBSD Installation and Upgrading 8 12th October 2009 08:49 PM
changing custom prompt ksh for root. bsdnewbie999 OpenBSD General 7 1st April 2009 04:53 AM
Exec command in zsh prompt? bsddaemon General software and network 2 18th October 2008 09:37 PM
what to do at mountroot prompt? Sunsawe FreeBSD General 13 5th June 2008 08:06 AM


All times are GMT. The time now is 02:41 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick