crc-org / crc

CRC is a tool to help you run containers. It manages a local OpenShift 4.x cluster, Microshift or a Podman VM optimized for testing and development purposes
https://crc.dev
Apache License 2.0
1.25k stars 237 forks source link

improve shell detection for crc.exe running in WSL #3797

Open anjannath opened 1 year ago

anjannath commented 1 year ago

General information

Currently when running crc.exe podman-env or crc.exe oc-env from a WSL terminal, it detects the shell as cmd

annant@DESKTOP-J8H86J0:~$ uname -a
Linux DESKTOP-J8H86J0 5.15.90.1-microsoft-standard-WSL2 #1 SMP Fri Jan 27 02:56:13 UTC 2023 x86_64 GNU/Linux
annant@DESKTOP-J8H86J0:~$ crc.exe podman-env
SET PATH=C:\Users\anath\.crc\bin\oc;%PATH%
SET CONTAINER_SSHKEY=C:\Users\anath\.crc\machines\crc\id_ecdsa
SET CONTAINER_HOST=ssh://core@127.0.0.1:2222/run/user/1000/podman/podman.sock
SET DOCKER_HOST=npipe:////./pipe/crc-podman
REM Run this command to configure your shell:
REM @FOR /f "tokens=*" %i IN ('crc podman-env') DO @call %i

we can override the detection to force a specific shell with the --shell flag (currently it doesn't include bash, zsh, fish as supported shells for windows) but it'd be good to auto-detect without having to use the "force-shell" flag

adrianriobo commented 1 year ago

:thinking: that would be similar to use the env var SHELL no? , or you mean you can specify any shell even the not supported ones?

anjannath commented 1 year ago

I mean crc should detect the shell correctly as bash or zsh, etc. when running in a WSL terminal and not detect is as cmd

that would be similar to use the env var SHELL no?

it doesn't work on WSL, there's a $SHELL env variable already set but crc is not using it, probably because the env variables are being fetched from the host when we are using os.Getenv

gbraad commented 1 year ago

the issue here is kinda that while we detect zsh/bash, we might not be able to properly set this up, unless we can guarantee the communication works from crc.exe and WSL, as it should also run in that case oc.exe or the linux binary oc ? and in that case, we might end up with another issue; people expecting that crc.exe start will work properly; this might be the case, but what if a side-effect occurs, and what if they expect crc status to work due to this? I am not sure how far we should go with this.

anjannath commented 1 year ago

also the paths have to be translated for WSL, currently after adding bash, zsh to the supported shells list in https://github.com/crc-org/crc/blob/97705a008eda801ba291fe3b9982af464d4759e0/pkg/os/shell/shell_windows.go#L12

it gives us windows style paths:

annant@DESKTOP-J8H86J0:/mnt/c/Users/anath/go/bin$ ./crc.exe podman-env --shell bash
export PATH="C:\Users\anath\.crc\bin\oc:$PATH"
export CONTAINER_SSHKEY="C:\Users\anath\.crc\machines\crc\id_ecdsa"
export CONTAINER_HOST="ssh://core@172.28.208.1:2222/run/user/1000/podman/podman.sock"
export DOCKER_HOST="npipe:////./pipe/crc-podman"
# Run this command to configure your shell:
# eval $(crc podman-env)