This works for me, in that it excludes the "foo" directory from the root directory of the search:
grep -rn --exclude-dir=foo 'custom'
However this doesn't work:
grep -rn --exclude-dir=foo/bar 'custom'
But the "foo/bar" directory is still searched. I also tried it with quotes:
grep -rn --exclude-dir='foo/bar' 'custom'
I'm using Ubuntu 20.
Update
Although not perfect, I used this workaround instead:
grep -rn 'custom'|grep -v 'foo/bar'
This will fail to find lines that contain both "foo/bar" and "custom".