Wednesday, July 29, 2009

Colorful (and userul) prompt.

Many times, I have felt irritated with default command prompt.

It normally includes PWD (Present working Directory) path in each command. When
you are working in directories with descriptive names and depth of 6 to 10,
command prompt takes lot of screen-space. When you are dealing with long commands
which are inherently complicated, this stupid prompt causes them to overflow into another line..!!! It is *really* annoying situation.

Finally, I decided to waste few hours for cleanup of my prompt.

It's not very complicated work. It needs editing few lines in ~/.bashrc file.
The $PS1 is the variable which controls the behavior of the prompt.

The PWD path information is undoubtedly useful and should be accessible, but we don't need
it embedded in prompt for each command. The username, machine name and whole path is always visible on the Title bar of terminal window, and is updated automatically with each directory change. So, lets drop this information.

I still add '\W' option, which gives the name (and not whole path) for working directory.
It gives the context of each command without wasting any screen space.

Other options added are
'\t' - tells time of command execution
'\${?}' - tells the success or failure of last command. (0 represents success)

So, my $PS1 variable looks like this.

PS1='[\t][${?}][\W]\$ '


After some googling, I came across how to add colours in prompt. And after adding
colours, My PS1 variable became

PS1='\[\033[01;32m\][\t]\[\033[01;34m\][${?}]\[\033[01;32m\][\W]\[\033[01;34m\]\$\[\033[00m\] '

Another improvement was done by modifying the root prompt in similar way but to use RED color
which will warn user to be careful. Following will generate similar (but reddish) prompt for root.

PS1='\[\033[01;31m\][\t]\[\033[01;34m\][${?}]\[\033[01;32m\][\W]\[\033[01;31m\]# \[\033[00m\]'


Here is my new prompt in action !!

PWD is having depth more than 10 which can be seen from the title bar,
but still the command prompt is clean.
It also includes the color switch when logged in as root.
Also, one wrong command is executed whose return status can be seen on the prompt afterwards.


Here is the link which will give information about other possibilities with prompt.

The various possible color codes that can be used are given here.

Here is my ~/.bashrc file with important line highlighed.

Thursday, February 26, 2009

Endavour of Minix networking

If you want networking to work in minix3, you have to do some homework before you start installing Minix3. You need to know which network card you are having. Minix3 currently supports few network cards, the list is

0. No Ethernet card (no networking)
1. Intel Pro/100
2. 3Com 501 or 3Com 509 based card
3. Realtek 8139 based card
4. Realtek 8029 based card (also emulated by Qemu)
5. NE2000, 3com 503 ro WD based card (also emulated by Bochs)
6. AMD LANCE (also emulated by VMWare)
7. Different Ethernet Card (no networking)

You can find out your network card type by using following command in linux
`lspci`. If your network card is not in list, then you have following options
1. Add another network card.
2. Wait till support for your network card is added.
3. Don't use networking
4. Write network driver yourself for your network card ;-)

If you have supported network card, then you can choose the proper network card in installation process, and then it should go fine. You are lucky if you have dhcp server running, In that case, minix3 should pickup the networking configuration automatically, reducing your work ;-)
Most of the work is done by `dhcpd` daemon which can work both as client and server. I personally do not not much about how exactly it works, you can find out at it's man page
and http://www.minix3.org/manpages/man5/dhcp.conf.5.html

If you don't have dhcp available, then you need to setup the static network ip by using `ifconfig` command, which is used to provide the ip address to the network interface.
manpage for ifconfig


There are two interfaces which are available
`/dev/ip` and `\dev\ip0`. The ifconfig command is something like following
ifconfig -I /dev/ip -h 192.168.0.2 -n 255.255.255.0


I had confusion that which device should I specify, `/dev/ip` or `/dev/ip0`
But it seems, ifconfig command is smart enough to find out which device to use.
So, you can get away by just giving command
ifconfig -h 192.168.0.2 -n 255.255.255.0
and minix3 will choose best device.

I still don't know what /dev/ip represents and why there are two devices,
This is just a temporary way around the confusion.

Other than this, another useful command is `add_route`.
man page for add_route
and example use of this command is
add_route -g 192.168.0.1
which will set 192.168.0.1 as your default gateway.

Another useful command is `pr_routes` which displays the routing table.


For setting up DNS, you can edit the file `/etc/resolve.conf`,
manpage for resolve.conf
Typical resolv.conf should look something like
nameserver 192.168.1.254

The best way to find out, whether you are in business or not is by pinging your gateway.
so, cross your fingers and give the command
ping 192.168.0.1
and Hope that Minix will say
192.168.0.1 is alive