Skip to content
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

Support defaulting launch & proc-run to use $SHELL with option for --no-shell otherwise #28

Closed
chipsenkbeil opened this issue Aug 16, 2021 · 6 comments
Labels
breaking Would require breaking changes enhancement New feature or request

Comments

@chipsenkbeil
Copy link
Owner

At least for launch (proc-run may not be necessary), being able to take advantage of the path assigned to a user would be handy.

Testing with ssh <host> echo '$SHELL' resulted in the right shell being printed, so that environment variable is available. It looks like the majority of shells support <shell> -l for login and <shell> -c <command> to run a command as non-login. Doesn't look like you can run a login shell and execute a command, but I don't think a login shell is necessary to get the path configured for the specific user as non-login will still source files like ~/.bashrc and others.

Anyway, idea here is to default to attempting to run distant over ssh using $SHELL -c distant ... to have appropriate environment variables established. If --no-shell is provided, then we wouldn't wrap in a $SHELL call.

Doing this for proc-run may not make sense as any environment given to the distant binary is passed on to its children; so, just providing launch with $SHELL should pass on the results to the children as well.

@chipsenkbeil chipsenkbeil added enhancement New feature or request breaking Would require breaking changes labels Aug 16, 2021
@chipsenkbeil chipsenkbeil added this to the 1.0 milestone Aug 16, 2021
@chipsenkbeil
Copy link
Owner Author

It looks like we may actually need the login shell option. Bash, ksh, fish, and zsh support providing a login shell and command option together <shell> -l -c env. The shells csh and tcsh do not, but the recommendation is to do something like echo ls | tcsh -l.

So idea would be to do something like echo 'distant ...' | $SHELL -l

@chipsenkbeil
Copy link
Owner Author

Resolved by 160631b

@wez
Copy link

wez commented Aug 16, 2021

If you integrate libssh or libssh2, you can have the sshd give you a login shell by requesting a shell explicitly, and then you can send your commands on stdin, which is sort of in alignment with your comment above, but you shouldn't need to play around with $SHELL or figuring out how to spawn a login shell.

Also note that if you were in control of the spawning directly (which I know you're not in this case), spawning a login shell can be done this way in rust:

            let shell = Self::get_shell()?;
            let mut cmd = std::process::Command::new(&shell);
            // Run the shell as a login shell by prefixing the shell's
            // basename with `-` and setting that as argv0
            let basename = shell.rsplit('/').next().unwrap_or(&shell);
            cmd.arg0(&format!("-{}", basename));

https://github.com/wez/wezterm/blob/main/pty/src/cmdbuilder.rs#L190-L197

@wez
Copy link

wez commented Aug 16, 2021

FWIW, the $SHELL -l thing doesn't work with fish; I know because that's the technique I used to use in wezterm!

@chipsenkbeil
Copy link
Owner Author

chipsenkbeil commented Aug 16, 2021 via email

@chipsenkbeil chipsenkbeil modified the milestones: 1.0, 0.17 and earlier Aug 18, 2022
@github-actions
Copy link

github-actions bot commented Jul 7, 2023

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 7, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
breaking Would require breaking changes enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants