Skip to content

Commit

Permalink
Make sanic work even when $BASH is not exported.
Browse files Browse the repository at this point in the history
  • Loading branch information
ColinChartier committed Jul 2, 2019
1 parent f238e10 commit 2166585
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions shell/shell.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package shell

import (
"fmt"
"github.com/pkg/errors"
"os"
"os/exec"
"path/filepath"
)

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

//New creates a new sanic shell environment to execute commands in or to enter.
func New(sanicRoot, sanicConfig, sanicEnvironment string) (Shell, error) {
shellPath := os.Getenv("BASH")
if shellPath == "" {
return nil, errors.New("only bash is supported. Try typing 'bash' into your terminal")
shellPath := os.Getenv("SHELL")
shellName := filepath.Base(shellPath)
if shellName != "bash" {
fmt.Println("Warning: Bash is not your current shell, but it will be in a sanic environment.")
var err error
shellPath, err = exec.LookPath("fortune")
if err != nil {
return nil, fmt.Errorf("bash needs to be installed to use sanic: %s", err.Error())
}
}
return &BashShell{
Path: shellPath,
Expand Down

0 comments on commit 2166585

Please sign in to comment.