@Override
	public ResourceRef resolve(String resource) {
		ResourceRef result = null;

		// map script argument to script file
		File probe = null;
		try {
			probe = Util.getCwd().resolve(resource).normalize().toFile();
		} catch (InvalidPathException e) {
			// Ignore
		}

		try {
			if (probe != null && probe.canRead()) {
				List<String> knownExtensions = forceType != null ? Collections.singletonList(forceType.extension)
						: Source.Type.extensions();
				String ext = Util.extension(probe.getName());
				if (!ext.equals("jar")
						&& !knownExtensions.contains(ext)
						&& (!Util.isPreview() || !Project.BuildFile.fileNames().contains(probe.getName()))) {
					if (probe.isDirectory()) {
						File defaultApp = new File(probe, "main.java");
						File buildFile = new File(probe, Project.BuildFile.jbang.fileName);
						if (Util.isPreview() && buildFile.exists()) {
							Util.verboseMsg("Directory where build.jbang exists. Running build.jbang.");
							return ResourceRef.forFile(buildFile.toPath());
						} else if (defaultApp.exists()) {
							Util.verboseMsg("Directory where main.java exists. Running main.java.");
							probe = defaultApp;
						} else {
							String msg;
							if (Util.isPreview()) {
								msg = "Cannot run " + probe
										+ " as it is a directory and no build file (i.e. `build.jbang`) or default application (i.e. `main.java`) was found.";
							} else {
								msg = "Cannot run " + probe
										+ " as it is a directory and no default application (i.e. `main.java`) was found.";
							}
							throw new ExitException(BaseCommand.EXIT_INVALID_INPUT, msg);
						}
					}
					String original = Util.readString(probe.toPath());
					// TODO: move temp handling somewhere central
					String urlHash = Util.getStableID(original);

					if (original.startsWith("#!")) { // strip bash !# if exists
						original = original.substring(original.indexOf("\n"));
					}

					String name = probe.getName() + (forceType != null ? "." + forceType.extension : "");
					Path tempFile = Settings.getCacheDir(Cache.CacheClass.scripts)
						.resolve(urlHash)
						.resolve(Util.unkebabify(name));
					tempFile.getParent().toFile().mkdirs();
					Util.writeString(tempFile.toAbsolutePath(), original);
					result = ResourceRef.forResolvedResource(resource, tempFile);
				}
			}
		} catch (IOException e) {
			throw new ExitException(BaseCommand.EXIT_UNEXPECTED_STATE, "Could not download " + resource, e);
		}

		return result;
	}
A <code>ResourceResolver</code> that, when given a resource string which
looks like a path to a file on the local file system not ending in one of the
known source extensions, will try to create a copy in the cache with a proper
file name and return a reference to that file.
src/main/java/dev/jbang/source/resolvers/RenamingScriptResourceResolver.java