OpenBSD Bash PS1 Prompt Tut. - BSD

Users browsing this thread: 2 Guest(s)
Mafia
Long time nixers
This will be a quick tut on making a nice prompt in OpenBSD, for this tutorial I will be using OpenBSD 5.1 and rxvt-unicode.
Note: the things used in this tutorial or strictly for easier learning purposes, I do not use the programs personally.

1. open your .bashrc
sudo nano .bashrc.

[Image: gomNw.png]

Your Default will look something like this:
Code:
# $OpenBSD: dot.profile,v 1.4 2005/02/16 06:56:57 matthieu Exp $
#
# sh/ksh initialization

PATH=$HOME/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin:/usr/local/bin:/usr/local/sbin:/usr/games:.
export PATH HOME TERM

export PKG_PATH=ftp://ftp.openbsd.org/pub/OpenBSD/5.0/packages/i386

alias ls="ls -h --color=auto"

export TERM=rxvt

export LC_CTYPE=en_US.UTF-8

export GTK_IM_MODULE=xim

export LESSCHARSET=utf-8

First we will add a nice PS1:
Code:
# Check for an interactive session
[ -z "$PS1" ] && return

PS1='\u@\h \W > '

function parse_git_branch {
  git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}

export PS1='\[\033[0;31m\]\u \[\033[1;36m\]\w $(parse_git_branch)\n\[\033[1;32m\]> \[\033[00m\]'

This will check your current directory add it to the PS1 then check if your in a git repo and add the current branch to the PS1, finally it will add color. It will look something like this:
[Image: zAdFl.png]

Then we will add a cowsay and colorized ls.
sudo pkg_add colorls, sudo pkg_add cowsay
If you have yet to set up your package path then do so now, add this to your bashrc
Code:
export PKG_PATH=ftp;//ftp.openbsd.org/pub/OpenBSD/*your-verison*/packages/*your-architecture*

Then add this to your bashrc for the cowsay:
Code:
# Check for an interactive session
[ -z "$PS1" ] && return

#alias ls='ls --color=auto'
PS1='\u@\h \W > '
dir='/usr/local/share/cows/'    # <--- this shows the cowsay where to look for the cow

tput setf 1  bold;fortune -o | cowsay -f blowfish.cow;tput sgr0    #<--- this is an input command for your cowsay color, I will break it down below the code.

tput setaf 1 bold;cat art;tput sgr0   #<-- this is the same above but for an cat command we will implement later.

function parse_git_branch {
  git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}  #<-- this will parse

Ok so tput is input and cat basically prints a file I tell it to in the terminal, here is a breakdown of tput:

tput -input command start
setf -set foreground color
1 -color number, in this case 1 is red/orange
bold -make bold
; -pause for input
fortune -o | cowsay -f blowfish -cowsay command
; -stop input
tput - start input
sgr0 -clear all input so that the preferences don't run on forever.

Alright, now that that is over lets explain the cat.
This command:
Code:
tput setaf 1 bold;cat art;tput sgr0

Does the same as our cowsay input but cat spits out a text file of my choice, the text file I want spit out is an ascii text image I want displayed under my cowsay. This is that image:

Code:
(~ _   | _  _  _  _  _  _|  _|_|_  _  _ |  _
  _)(_)  |(_)| |(_|,  (_|| |(_|   | | |(_|| ||<_\
    _|
    |` _  _   _ ||  _|_|_  _   o._  |~ _
  ~|~(_)|   (_|||   | | |(/_  || |~|~(_)

    "So long and thanks for the info"

Since cat will be printing this it will make a nice effect with my cowsay image, doing this you can make a nice image /W text that matches your color scheme or maybe just matches what you want.

Now that we have our .bashrc lined up we can now save and see the things we have added, if you have done everything correctly you should now get a custom PS1 with a custom cowsay colorized to your perfection. You should also now have a colorized ls output since we installed "colorls". Here is our finished prompt:
note: Your terminal colors may vary(due to your .Xdefaults).

Final Prompt:
The Prompt/cowsay is on the right, the colorized ls is on the left.[Image: eBRlU.png]

I hope you liked the tutorial, I encourage you all just to use this as a stepping stone and continue to customize to your needs. I would like to add that this should only be a SMALL part of your .bashrc, with more work you can add tons of other things to optimize the shell for your needs. I also do not use bash or nano, I use zsh and vim.
gurhush
Long time nixers
Completely unrelated to the tutorial (shameless bump, I guess):

What font are you using for your terminals? It looks very sharp.
Mafia
Long time nixers
I use Smoothansi for all my term fonts :>

its in the Artwiz pack.
Mafia
Long time nixers
(12-09-2012, 09:39 AM)shix Wrote:
(12-09-2012, 02:52 AM)Mafia Wrote: I use Smoothansi for all my term fonts :>

its in the Artwiz pack.

I love the Artwiz pack.

Yeah I love it too, I plan on learning how to make fonts.
Sounds interesting.
yrmt
Grey Hair Nixers
gbdfed for the win. Making a font with that tool is pretty easy and it compiles on everything with some tweaking.
Mafia
Long time nixers
(13-09-2012, 05:40 AM)Beastie Wrote: gbdfed for the win. Making a font with that tool is pretty easy and it compiles on everything with some tweaking.

I remember speaking about it once with you, never got around to it though.