Skip to content

Commit

Permalink
Merge pull request #312 from scop/improve-autodetect
Browse files Browse the repository at this point in the history
Improve shell detection
  • Loading branch information
justjanne committed Oct 11, 2021
2 parents cc85264 + d169fe2 commit 4cbdaf1
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions powerline.go
Expand Up @@ -12,6 +12,7 @@ import (

pwl "github.com/justjanne/powerline-go/powerline"
"github.com/mattn/go-runewidth"
"github.com/shirou/gopsutil/process"
"golang.org/x/crypto/ssh/terminal"
"golang.org/x/text/width"
)
Expand Down Expand Up @@ -81,7 +82,15 @@ func newPowerline(cfg Config, cwd string, align alignment) *powerline {

p.theme = cfg.Themes[cfg.Theme]
if cfg.Shell == "autodetect" {
cfg.Shell = detectShell(os.Getenv("SHELL"))
var shellExe string
proc, err := process.NewProcess(int32(os.Getppid()))
if err == nil {
shellExe, _ = proc.Exe()
}
if shellExe == "" {
shellExe = os.Getenv("SHELL")
}
cfg.Shell = detectShell(shellExe)
}
p.shell = cfg.Shells[cfg.Shell]
p.reset = fmt.Sprintf(p.shell.ColorTemplate, "[0m")
Expand Down Expand Up @@ -117,12 +126,12 @@ func newPowerline(cfg Config, cwd string, align alignment) *powerline {
return p
}

func detectShell(envShell string) string {
func detectShell(shellExe string) string {
var shell string
envShell = path.Base(envShell)
if strings.Contains(envShell, "bash") {
shellExe = path.Base(shellExe)
if strings.Contains(shellExe, "bash") {
shell = "bash"
} else if strings.Contains(envShell, "zsh") {
} else if strings.Contains(shellExe, "zsh") {
shell = "zsh"
} else {
shell = "bare"
Expand Down Expand Up @@ -460,4 +469,3 @@ func (p *powerline) supportsRightModules() bool {
func (p *powerline) isRightPrompt() bool {
return p.align == alignRight && p.supportsRightModules()
}

0 comments on commit 4cbdaf1

Please sign in to comment.