#!/bin/sh
# lpsconf.sh: Lame PS1, PS2 Configurator
#
# Usage     : Place this file to your /opt/bin (or /usr/bin) and
#             add below line to your /etc/profile (or ~/.profile)
#
#             export PROMPT_COMMAND="source /opt/bin/lpsconf"
#
# Author    : Volkan YAZICI
# URL       : http://www.students.itu.edu.tr/~yazicivo/

lastProcState=$?

# PS variable colors
colorError="\[\e[031;1m\]"
colorSuccess="\[\e[032m\]"
colorDefault="\[$(tput sgr0)\]"

# Looking last process' exit signal code and setting PID color
if [ $lastProcState -eq 0 ]
	then pidColor=$colorSuccess
	else pidColor=$colorError
fi

# Maximum directory path length which would be shown under PS1 or PS2
max_dir_len=15

# Suffix that will be printed before viewing a directory path bigger
# than max_dir_len characters in PS1 or PS2
suffix="..."

# {{{ Don't edit anything below if nothing happens strange

dir=$(pwd | sed "s#"${HOME}"#~#g")
line_len=$(tput cols)

let max_dir_len=$(( ${max_dir_len} - ${#suffix} ))

if [ ${#dir} -gt "$max_dir_len" ]
then
	will_be_deleted=$(( ${#dir} - $max_dir_len ))
	new_dir="${suffix}${dir:$will_be_deleted:${#dir}}"
else
	new_dir=$dir
fi

if [ `id -u` -eq 0 ]
	then seperator="#"
	else seperator="$"
fi

# If this script doesn't work please try to replace the PS1 line below with PS2
export PS1="\u (${new_dir}) ${pidColor}[\!${colorDefault}:${lastProcState}${pidColor}]${colorDefault}${seperator} "
# }}}

# vim: set autoindent tabstop=4 fdm=marker:

# End of file

