Get rid of logic duplicated in plugin_dirs()