-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
proposal: os: add UserShell #34910
Comments
The For example, if the API returns |
What is the use case here? When do you specifically want to run the user's shell? The packages you point to seem to be looking in |
This seems too system specific. |
Handling responses:
The arguments can be supplied by the user, for example in any kind of hook ("when I do X, invoke my shell to do Y"). Interactive and/or standard input uses are also valid use cases, e.g. for any applications that provide an embedded shell.
The suggestion for putting it in the
The method used to determine the user's shell include:
In short, this is a superficially simple function that hides a lot of system-specific underlying complexity from the caller. |
Given that we need to call |
That said, it's not clear that this needs to go into the standard library. The argument that programs will use the user's shell to execute scripts seems very special purpose, as that can only be done for scripts provided by the user. Why not just have the user provide the shell at the same time? |
OK for putting it in Go's standard library provides nearly all the functionality to ready the That all said, I do realize that the use cases for needing to know the user's shell are limited and so am happy if this proposal is closed unaccepted. Thank you for considering it. |
This seems too special purpose. It can be done outside the standard library. |
Ack for decline. Thank you for considering it :) Closing this issue. |
Go has added several functions for determining the user's configuration:
os.UserCacheDir
in os: add func UserCacheDir() string #22536 (Go 1.11).os.UserHomeDir
in proposal: os: add UserHomeDir #26463 (Go 1.12).os.UserConfigDir
in proposal: os: add UserConfigDir #29960 (Go 1.13).Closely related to this is getting the user's shell, which is very OS-dependent, and surprisingly tricky to accomplish (especially if cgo is not available, for example when cross-compiling). Go's behavior of falling back to parsing local files (e.g.
/etc/passwd
) when cgo is not available has led to a number of bugs in applications (e.g. #24383, twpayne/chezmoi#65).Being able to invoke the user's shell is useful in interactive applications (e.g. VSCode's interactive terminal), command line applications (e.g. chezmoi's cd command, or any application that launches a user-specified command on the user's behalf.
There are existing packages to do this, for example:
github.com/riywo/loginshell
github.com/twpayne/go-shell
This proposal is concretely:
Add a
os.UserShell
function that returns the current user's shell.Optionally, the
os.UserShell
function could return some indication of the level of confidence in the returned result (if the current user's shell could not be determined, maybe it makes sense to fall back to an OS-dependent default shell).The text was updated successfully, but these errors were encountered: