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

case ${1} in
	-h | --help)
		bsng-help -a "Christopher Roy Bratusek" -e "nano@jpberlin.de" -h "http://www.nanolx.org/"\
			-l "GNU GPL v3" -n "truncpwd" -s "pretty print current directory" -v "${BSNG_VERSION}" -y "${BSNG_YEAR}"\
			-o "none:|--"
	;;

	* )

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

		if [[ ${enable_colors} == True && ${truncpwd_supported} == True ]];  then
			if [[ ${pwdmaxlen} != 0 && ${#PWD} -gt ${pwdmaxlen} ]]; then
				pwdoffset=$(( ${#PWD} - ${pwdmaxlen} ))
				xPWD="${epscolor}${trunc_symbol}${PWD:${pwdoffset}:${pwdmaxlen}}"
				newPWD="${xPWD//\//${esepacolor}${dirchar}${ewdircolor}}"
			else
				newPWD="${PWD//\//${esepacolor}${dirchar}${ewdircolor}}"
			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
