#!/usr/bin/perl

$host = `hostname`; chomp($host);
%hostaliases = (
		"hpesajp" => "hp",
		"pippin" => "pippin",
		);
$pwd = $ENV{PWD};

@aliases = (
	    "/tmp_mnt/auto=>",
	    "$ENV{HOME}=>~",
	    "/net/=>",
	    "/home/=>/~",
	    );

$host = $hostaliases{$host} if defined $hostaliases{$host};
foreach $alias (@aliases) {
    @alias = split(/=>/, $alias);
    if ( $alias[0] ne "" ) {
        $pwd =~ s/$alias[0]/$alias[1]/;
    }
}
if ($pwd =~ /^(~)?(.+)(\/.*?\/.*?\/.*)/) {
    @prec = split(/\//, $2);
    $pwd = "$1($#prec)$3" if $#prec;
}

while ($pwd =~ /[\/]+([^\/]{13,})/) {
    $segment = $oldseg = $1;
    $segment =~ s/^(.{4}).*?(.{5})$/$1\.\.\.$2/;
    $pwd =~ s/$oldseg/$segment/;
}
$whoami = `whoami`;
chomp( $whoami );
if ( $whoami eq "root" ) {
    $user = "\\[[41m\\]ROOT\\[[49m\\]:";
} elsif( $whoami ne "ajp" ) {
    $user = "\\[[41m\\]$whoami\\[[49m\\]@";
}

#Colors
if ( $ENV{COLOR_PROMPT} ne "no" )
{
  $host = "\\[[32m\\]$host\\[[39m\\]" if $host;
  $pwd  = "\\[[36m\\]$pwd\\[[39m\\]";
}

print "$user$host:$pwd> ";

