Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions internal/stack/shellinit.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,16 @@ func helpText(shell string) string {

func getShellName(exe string) string {
shell := filepath.Base(exe)
// NOTE: remove .exe extension from executable names present in Windows
shell = strings.TrimSuffix(shell, ".exe")
cleanSuffixes := []string{
// Remove .exe extension from executable names present in Windows.
".exe",
// Remove " (deleted)", that can appear here if the shell process has been
// replaced by an upgrade in Linux while the terminal was open.
" (deleted)",
}
for _, suffix := range cleanSuffixes {
shell = strings.TrimSuffix(shell, suffix)
}
return shell
}

Expand Down
20 changes: 16 additions & 4 deletions internal/stack/shellinit_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package stack

import (
"path/filepath"
"strings"
"testing"

Expand Down Expand Up @@ -44,13 +45,24 @@ func Test_getShellName(t *testing.T) {
type args struct {
exe string
}
tests := []struct {
type testCase struct {
name string
args args
want string
}{
{"linux exec", args{exe: "bash"}, "bash"},
{"windows exec", args{exe: "cmd.exe"}, "cmd"},
}
var tests []testCase
if filepath.Separator == '\\' {
tests = []testCase{
{"windows relative path", args{exe: `cmd.exe`}, "cmd"}, // Not sure if this case is real.
{"windows exec", args{exe: `C:\Windows\System32\cmd.exe`}, "cmd"},
}
} else {
tests = []testCase{
{"linux exec", args{exe: "/usr/bin/bash"}, "bash"},
{"linux upgraded exec", args{exe: "/usr/bin/bash (deleted)"}, "bash"},
{"windows relative path", args{exe: `cmd.exe`}, "cmd"}, // Not sure if this case is real.
{"windows exec", args{exe: `C:/Windows/System32/cmd.exe`}, "cmd"},
}
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down