#!/bin/bash
# http://redsymbol.net/articles/unofficial-bash-strict-mode/

# counts files in current directory owned by current user

set -eu
set -o pipefail

ownername () {
    owner=$(ls -od $1 |cut -d' ' -f3)
    echo $owner
}

NUMFILES=0
ME=$(whoami)

for file in *
do
    OWNER=$(ownername $file)
    if test $OWNER == $ME
    then
        NUMFILES=$(($NUMFILES + 1))
        echo "$file is owned by $ME"
    fi
done

echo $NUMFILES
