#!/bin/bash
#########################################################
# 							#
# This is BashStyle-NG					#
#							#
# Licensed under GNU GENERAL PUBLIC LICENSE v3    	#
#							#
# Copyright 2007 - 2014 Christopher Bratusek		#
#							#
#########################################################

case $1 in
	*help )
		echo -e "\n${ewhite}Usage:\n"
		echo -e "${eorange}truncpwd ${ewhite}|${egreen} ! no options !\n"
		tput sgr0
	;;

	* )
		newsepacolor=$(echo $sepacolor | sed -e 's/\\\[//g' -e 's/\\\]//g')
		newwdircolor=$(echo $wdircolor | sed -e 's/\\\[//g' -e 's/\\\]//g')
		newpscolor=$(echo $pscolor | sed -e 's/\\\[//g' -e 's/\\\]//g')

		[[ ! ${dirchar} ]] && dirchar="/"
		[[ ! ${trunc_symbol} ]] && trunc_symbol="«"
		[[ ! ${trunc_length} ]] && trunc_length=25

		if [[ ${enabcol} == "True" && ${pstyle_supported} == "True" ]];  then
			if [[ $pwdmaxlen != 0 && ${#PWD} -gt $pwdmaxlen ]]; then
				pwdoffset=$(( ${#PWD} - $pwdmaxlen ))
				xPWD="$newpscolor${trunc_symbol}${PWD:$pwdoffset:$pwdmaxlen}"
				newPWD="${xPWD//\//$newsepacolor$dirchar$newwdircolor}"
			else
				newPWD="${PWD//\//$newsepacolor$dirchar$newwdircolor}"
			fi
		else
			if [[ $pwdmaxlen != 0 && ${#PWD} -gt $pwdmaxlen ]]; then
				pwdoffset=$(( ${#PWD} - $pwdmaxlen ))
				xPWD="${trunc_symbol}${PWD:$pwdoffset:$pwdmaxlen}"
				newPWD="${xPWD//\//$dirchar}"
			else
				newPWD="${PWD//\//$dirchar}"
			fi
		fi

		echo -e $newPWD
	;;
esac
