Skip to content

Commit 2166585

Browse files
committed
Make sanic work even when $BASH is not exported.
1 parent f238e10 commit 2166585

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

shell/shell.go

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package shell
22

33
import (
4+
"fmt"
45
"github.com/pkg/errors"
56
"os"
7+
"os/exec"
8+
"path/filepath"
69
)
710

811
//Shell represents, broadly, the current shell environment we're in (by having executed sanic env)
@@ -47,9 +50,15 @@ func Current() (Shell, error) {
4750

4851
//New creates a new sanic shell environment to execute commands in or to enter.
4952
func New(sanicRoot, sanicConfig, sanicEnvironment string) (Shell, error) {
50-
shellPath := os.Getenv("BASH")
51-
if shellPath == "" {
52-
return nil, errors.New("only bash is supported. Try typing 'bash' into your terminal")
53+
shellPath := os.Getenv("SHELL")
54+
shellName := filepath.Base(shellPath)
55+
if shellName != "bash" {
56+
fmt.Println("Warning: Bash is not your current shell, but it will be in a sanic environment.")
57+
var err error
58+
shellPath, err = exec.LookPath("fortune")
59+
if err != nil {
60+
return nil, fmt.Errorf("bash needs to be installed to use sanic: %s", err.Error())
61+
}
5362
}
5463
return &BashShell{
5564
Path: shellPath,

0 commit comments

Comments
 (0)