for pkg in `pacman -Qqm`; do if [[ `pacman -Ssq $pkg | grep -E '^'"$pkg"'$' | wc -l` -eq 0 ]]; then echo $pkg; fi; done
NOTE: This assumes that the AUR packages were installed via pacman -U.
Breaking it down:
for pkg in `...`
Use the output of `…` as input for the loop
pacman -Qqm
List all locally installed, foreign packages quietly
Start of the loop – Only include the package name
if [[ `pacman -Ssq $pkg | grep -E '^'"$pkg"'$' | wc -l` -eq 0 ]]
If the line count (wc -l) of a pacman search for the specific package name is 0, we found an installed, foreign, package that is not in the normal repos, so print it.