mbl-35 / wslctl

Provide a single command wslctl to create, backup and manage WSL (Windows Subsystem for Linux) instances on a windows host
0 stars 1 forks source link

EVOL: allows fish as defaut wsl shell #28

Open mbl-35 opened 1 year ago

mbl-35 commented 1 year ago

When the default user shell is fish, wslctl exec {{wsl-name}} returns the following error and hangs:

PS C:\Users\me> wslctl exec test-fish
Connect to test-fish...
fish: Missing end to balance this if statement
if [ -x /bin/zsh ]; then /bin/zsh --login; else if [ -x /bin/bash ]; then /bin/bash --login; else if [ -x /bin/sh ]; then /bin/sh --login; fi; fi; fi; exit $?
^^
PS C:\Users\me>

should be good to get the default user shell from /etc/passwd file ... Somethings like: getent passwd {{username}} | awk -F: '{print $NF}'

mbl-35 commented 1 year ago

Change the connect method from :

    [Int32] connect([string]$name) {
        $shellArray = @('/bin/zsh', '/bin/bash', '/bin/sh')
        $cmdTxt = (( $shellArray | ForEach-Object { "if [ -x $_ ]; then $_ --login;" } ) -Join " else ") + (" fi;" * $shellArray.Length) + ' exit $?'
        return $this.exec($name, @("$($cmdTxt)"))
    }

to :

    [Int32] connect([string]$name) {
        $userShell = & $this.Binary --user root --distribution $name getent passwd $env:USERNAME
        $userShell = $userShell.Split(":")[-1]
        return $this.exec($name, @("$userShell","--login"))
    }

Slower but more flexible...