def find_script(bash_source)
      script = @pwd_stack.reverse.map { |wd| wd + bash_source }.find(&:file?)

      return bash_source.cleanpath if script.nil?

      begin
        script.realpath
      rescue Errno::ENOENT # catch race condition if the file has been deleted
        bash_source.cleanpath
      end
    end
def find_script(bash_source)
      script = @pwd_stack.reverse.map { |wd| wd + bash_source }.find(&:file?)

      return bash_source.cleanpath if script.nil?

      begin
        script.realpath
      rescue Errno::ENOENT # catch race condition if the file has been deleted
        bash_source.cleanpath
      end
    end
Scans entries in the +PWD+ stack, checking whether +entry/$BASH_SOURCE+
 refers to an existing file. Scans the stack in reverse on the assumption
 that more-recent entries are more plausible candidates for base
 directories from which +BASH_SOURCE+ can be reached.
 @param [Pathname] bash_source expanded +BASH_SOURCE+
 @return [Pathname] the resolved path to +bash_source+, if it exists;
   otherwise, +bash_source+ cleaned of redundant slashes and dots