Skip to content

Commit e872358

Browse files
authored
feat: change shell command to spawn in the current directory (#381)
* change shell command to spawn in the current directory * simplify bash completion code
1 parent e16a230 commit e872358

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

cmd/embedded-cluster/shell.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"os"
77
"os/exec"
88
"os/signal"
9+
"path/filepath"
910
"syscall"
1011

1112
"github.com/creack/pty"
@@ -57,7 +58,14 @@ var shellCommand = &cli.Command{
5758
fmt.Printf(welcome, defaults.BinaryName())
5859
shell := exec.Command(shpath)
5960
shell.Env = os.Environ()
60-
shell.Dir = defaults.EmbeddedClusterBinsSubDir()
61+
62+
// get the current working directory
63+
var err error
64+
shell.Dir, err = os.Getwd()
65+
if err != nil {
66+
return fmt.Errorf("unable to get current working directory: %w", err)
67+
}
68+
6169
shellpty, err := pty.Start(shell)
6270
if err != nil {
6371
return fmt.Errorf("unable to start shell: %w", err)
@@ -91,7 +99,7 @@ var shellCommand = &cli.Command{
9199

92100
// if /etc/bash_completion is present enable kubectl auto completion.
93101
if _, err := os.Stat("/etc/bash_completion"); err == nil {
94-
config = "source <(kubectl completion $(basename ${SHELL}))\n"
102+
config = fmt.Sprintf("source <(kubectl completion %s)\n", filepath.Base(shpath))
95103
_, _ = shellpty.WriteString(config)
96104
_, _ = io.CopyN(io.Discard, shellpty, int64(len(config)+1))
97105

0 commit comments

Comments
 (0)