To give you a bit of a background knowledge from my understanding, the number of entries in i.e. AMENT_PREFIX_PATH are the number of packages you have successfully build and sourced from either your workspace or also packages that you have installed through apt packaging managers. This is used afaik for checking if a package is installed and where to find the include-folder/headers for building on top of those.
Is your workflow that you have n-workspaces and by that want to check if your shell is ready to go to ros2 run <package> ? Would probably more fun to dynamically check the package.xml for the run_depend of your desired package and see if everything is already included in the AMENT_PREFIX_PATH. Or make some traffic ligth that checks if the packages you want to use (based on a file in Home..) are already included..?