cat <<"EOF" >> "$HOME/.bash_functions"
handle64()
{
[ -z "$1" ] && return
path="$1"
# Convert beginning of Linux style path to windows drive letter
# "/c/" -> "c:/"
[[ $path =~ /[a-zA-Z]/ ]] && path="${path:1:1}:${path:2}"
drive="${path:0:1}"
path=${path:1}
# Convert slashes "/" -> "\"
path=${path//\//\\}
# Remove trailing backslash
path=${path%%\\}
# Fold consecutive "\"
while [[ $path =~ \\\\ ]]
do
path=${path//\\\\/\\}
done
# Double "\" for the regex to be used
path=${path//\\/\\\\}
path="[${drive^}${drive,}]$path"
"$PROGRAMFILES/SysinternalsSuite/handle64.exe" |
awk '/pid:/ { process = $0 } /'"$path"'\r/ { print process "\n" $0 }'
}
EOF