This is an external command for Homebrew that will remove packages and all of their dependencies recursively.
It only removes packages that are not depended on by other unrelated packages.
brew tap exuanbo/auto-remove
brew auto-remove pkg_1 pkg_2
MIT License © 2020 Exuanbo