I know you can determine the owner of directory by doing:
ls -ld ~/foo | awk '{ print $3 }'
You could then compare it to the current user by doing this:
if [[ $(ls -ld ~/foo | awk '{ print $3 }') == "$USER" ]] # or $(id -u -n ) instead of $USER
then
echo "You are the owner"
else
echo "You are NOT the owner"
fi
But you can have permissions to write without being the owner. How do you determine this?