#!/bin/bash

LENGTH="50"
HALF="$(($LENGTH/2))"

if [ ${#PWD} -gt $(($LENGTH)) ]; then
echo "${PWD:0:$(($HALF-3))}...${PWD:$((${#PWD}-$HALF)):$HALF}" | \
sed s/\\/home\\/$USER/~/
else
echo "$PWD" | sed s/\\/home\\/$USER/~/
fi