From 707f799d9558c9964b7719001ae0f7c55264d535 Mon Sep 17 00:00:00 2001 From: JrCs <90z7oey02@sneakemail.com> Date: Tue, 11 Jun 2019 16:56:13 +0200 Subject: [PATCH] Use the best shell Try to use bash as default shell in container and if not found use sh. Close #226 --- internal/views/exec.go | 10 ---------- internal/views/pod.go | 2 +- internal/views/pod_test.go | 8 ++++---- 3 files changed, 5 insertions(+), 15 deletions(-) diff --git a/internal/views/exec.go b/internal/views/exec.go index 06427a48..cf0756e9 100644 --- a/internal/views/exec.go +++ b/internal/views/exec.go @@ -20,16 +20,6 @@ func runK(clear bool, app *appView, args ...string) bool { return false } - last := len(args) - 1 - if args[last] == "sh" { - args[last] = "bash" - if !run(clear, app, bin, args...) { - args[last] = "sh" - } else { - return true - } - } - return run(clear, app, bin, args...) } diff --git a/internal/views/pod.go b/internal/views/pod.go index 4a1e323d..140f835a 100644 --- a/internal/views/pod.go +++ b/internal/views/pod.go @@ -241,5 +241,5 @@ func computeShellArgs(path, co, context string, kcfg *string) []string { args = append(args, "-c", co) } - return append(args, "--", "sh") + return append(args, "--", "sh", "-c", "command -v bash >/dev/null && exec bash || exec sh") } diff --git a/internal/views/pod_test.go b/internal/views/pod_test.go index 39c41b06..2957e23d 100644 --- a/internal/views/pod_test.go +++ b/internal/views/pod_test.go @@ -19,28 +19,28 @@ func TestComputeShellArgs(t *testing.T) { "c1", "ctx1", &config, - "exec -it --context ctx1 -n fred blee --kubeconfig coolConfig -c c1 -- sh", + "exec -it --context ctx1 -n fred blee --kubeconfig coolConfig -c c1 -- sh -c command -v bash >/dev/null && exec bash || exec sh", }, "noconfig": { "fred/blee", "c1", "ctx1", nil, - "exec -it --context ctx1 -n fred blee -c c1 -- sh", + "exec -it --context ctx1 -n fred blee -c c1 -- sh -c command -v bash >/dev/null && exec bash || exec sh", }, "emptyConfig": { "fred/blee", "c1", "ctx1", &empty, - "exec -it --context ctx1 -n fred blee -c c1 -- sh", + "exec -it --context ctx1 -n fred blee -c c1 -- sh -c command -v bash >/dev/null && exec bash || exec sh", }, "singleContainer": { "fred/blee", "", "ctx1", &empty, - "exec -it --context ctx1 -n fred blee -- sh", + "exec -it --context ctx1 -n fred blee -- sh -c command -v bash >/dev/null && exec bash || exec sh", }, }