-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Installed scripts can't know their own name #5725
Comments
This comment has been minimized.
This comment has been minimized.
That's right @nayeemrmn, I updated the issue. |
Well if the use case is okay with everyone then a solution would be to inject it into the runtime via a hidden command line flag set by the auto-generated script: #!/bin/sh
# generated by deno install
deno "run" "--installed-path" "$0" "https://url.to/script.ts" "$@" // namespace Deno {
// installedPath: string | null;
// }
console.log(Deno.installedPath); // "/home/nayeem/.deno/bin/cmdname" EDIT: // namespace Deno {
// installedName: string | null;
// }
console.log(Deno.installedName); // "cmdname" |
It would be also nice, if there is a way to get the file name from a script which isn't installed with |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
I think it would be nice if the script name were available via |
Consideration: What are the security and privacy implications of these kinds of introspection? |
@jsejcksn one could be that if a script knows the location of its launcher it can grant itself more permissions by rewriting it (only requires Don't know how viable it is, but maybe a possible security measure could be to exclude # Can write everywhere except to path/to/.deno/bin/
$ deno run --allow-write myscript.ts
# Can write to path/to/.deno/bin/
$ deno run --allow-write=path/to/.deno/bin/ myscript.ts Or maybe a file system permission wall? Also, this may already be a concern since many cli script authors recommend an install name on their documentation so in most cases they already have all the info to infer the installation path. |
Of course, if a script can read the filesystem, it can probably find the script location (even if inefficiently) by For the CLI use case, the most valuable information would just be the installed executable name itself. I don't imagine the full path to the script would be needed most of the time. |
Actually the full path is used quite frequently for associated CLI/executable data such as config files, etc. |
There's no way for a
deno install
ed script to know its own name.This has a significant impact on CLI modules, that may need it for various reasons such as showing help messages and usage examples, registering shell completions etc.
Are there any plans to introduce this functionality somehow?
The text was updated successfully, but these errors were encountered: