Skip to content
This repository has been archived by the owner on May 10, 2023. It is now read-only.

Allow to use a different shell; shorthand for wsl genie -s possible #2

Closed
gbraad opened this issue Feb 19, 2021 · 11 comments · Fixed by #3
Closed

Allow to use a different shell; shorthand for wsl genie -s possible #2

gbraad opened this issue Feb 19, 2021 · 11 comments · Fixed by #3

Comments

@gbraad
Copy link
Contributor

gbraad commented Feb 19, 2021

It might be helpful to allow the user to change the shell used:

RunInGenie/Program.cs

Lines 118 to 119 in 5e15afb

Process ps = Process.Start (fileName: "wsl",
arguments: $"-e genie -c sh -c \"{string.Join (separator: ' ', values: param)}\"");

Here sh is forced which is really bare and doesn't load any profile. If the shell can be configured to use either bash or zsh the usage can be different.

If for instance

PS> $
The parameter is incorrect.

is used, it would now 'expect' an argument... but what if it actually opens a shell session; this would be a replacement if wsl genie -s.

At the moment I do $ zsh to drop into my session:

PS> $ zsh
$

but it would be simpler if the argument need wasn't there and any shell could be used perhaps by configuration of an .config file alongside the executable or an ini file.

@gbraad gbraad changed the title Allow to use a different shell Allow to use a different shell; shorthand for wsl genie -s possible Feb 19, 2021
@gbraad
Copy link
Contributor Author

gbraad commented Feb 19, 2021

BTW, I am looking into this and might suggest a PR at some point.


Note: the output

The parameter is incorrect.

comes from sh itself as it receives the -c option without input. When no arguments/parameters are given this should not use -c (to me this feels like a bug, but a nice side-effect ;-)

@gbraad
Copy link
Contributor Author

gbraad commented Feb 19, 2021

A bit rusty (8+ years of no C# coding), but added a ConfigurationBuilder that takes a $.json file to determine the override shell which seems to work:

   7555 pts/3    Ssl+   0:00 /usr/libexec/genie/runinwsl /mnt/c/Users/gbraad zsh -c ps ax

so will cleanup some code and determine if the -c option is needed next (a simple check).

@gbraad
Copy link
Contributor Author

gbraad commented Feb 19, 2021

image

which dropped me in a zsh session:

   8035 pts/3    Ssl    0:00 /usr/libexec/genie/runinwsl /mnt/c/Users/gbraad zsh

@gbraad
Copy link
Contributor Author

gbraad commented Feb 19, 2021

Have a PR #3, but still wanting to refactor this a little. If you create a file $.json to can set the shell with:

{
  "shell": "zsh"
}

@cerebrate
Copy link
Member

@gbraad Now I come to ship this in 0.2, a thought occurs to me concerning your comments up above --

#2 (comment)

-- insofar as $ zsh or now just $ isn't an equivalent to genie -s, because the latter starts a login shell and the former doesn't, so you don't get the .zprofile/.zlogin, just the .zshrc, etc.

Do you think it would be better to have RunInGenie detect this situation and request a login shell specifically, or treat $ consistently with $ <command> and start the non-login shell environment that commands would be handled in? I can see arguments going both ways, so would appreciate a second opinion.

@cerebrate cerebrate reopened this Feb 24, 2021
@gbraad
Copy link
Contributor Author

gbraad commented Feb 24, 2021

So what happens is that $ runs genie -c zsh and $ [command] runs genie -c zsh -c [cmd], so this will always process the specified shell for each situation the same.

@cerebrate
Copy link
Member

It does, but should it, is my question?

On the one hand, I can see the use of a quick shortcut with the above behavior for popping up a shell for a few quick commands in the current context (I'd use it fairly often for that myself);

But on the other hand, it's not a direct replacement of wsl genie -s which starts a login shell with all its associated behaviors, and if people want to use $ as an abbreviation for wsl genie -s, I should probably adjust things so that it runs genie -c zsh -l or just genie -s.

(I think I prefer the former, given that my terminal etal. all know to start the shell the long way anyway, so I'm only likely to use $ when I want to rattle off a few WSL commands in sequence in the current context, but...)

@gbraad
Copy link
Contributor Author

gbraad commented Feb 25, 2021

it's not a direct replacement of wsl genie -s

Right. I do not have this particular need. Using just $ works for me. BUT. if someone needs this, it would be possible to add an override to toggle this behaviour by configuration.

Also, let's see if the commandline extensions can be added 'soonish' to allow the use of -d [distro], as it can possibly also pick up -h shorthand for help... and perhaps a -l shorthand option?

@cerebrate
Copy link
Member

Makes sense to me. I'll put -l and its option on the list for 0.3.

(-d [distro] is added in 0.2.)

@gbraad
Copy link
Contributor Author

gbraad commented Feb 28, 2021

(-d [distro] is added in 0.2.)

Not added as per comment on PR #5 (comment) and the 'soonish'-remark here #2 (comment). Created a new issue for this #3. Didn't get around this due to the CNY celebrations and helping the kids as school didn't open yet.

Also the, extensions.commandline library does not allow empty shorthand/options so --login/-l might not work with this.

@cerebrate
Copy link
Member

Yep. I added it myself in the 0.2 release after merging the PR. 😁

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants