From 787945d7f86a4207669167edaf8b0bbcafa2f910 Mon Sep 17 00:00:00 2001 From: Caleb Foust Date: Wed, 22 Nov 2023 08:06:38 -0500 Subject: [PATCH] feat: use SHELL --- cmd/cy/server.go | 1 + pkg/cy/api/cmd.go | 15 ++++++++++++++- pkg/cy/api/input.go | 3 +-- pkg/cy/cy_test.go | 1 + pkg/cy/defaults.go | 1 + pkg/cy/module.go | 2 ++ pkg/cy/params/constants.go | 3 +++ 7 files changed, 23 insertions(+), 3 deletions(-) diff --git a/cmd/cy/server.go b/cmd/cy/server.go index 9f25737b..d035a114 100644 --- a/cmd/cy/server.go +++ b/cmd/cy/server.go @@ -38,6 +38,7 @@ func serve(path string) error { cy, err := cy.Start(context.Background(), cy.Options{ Config: findConfig(), DataDir: findDataDir(), + Shell: getShell(), }) if err != nil { return err diff --git a/pkg/cy/api/cmd.go b/pkg/cy/api/cmd.go index 211e6145..74d69fda 100644 --- a/pkg/cy/api/cmd.go +++ b/pkg/cy/api/cmd.go @@ -6,6 +6,7 @@ import ( "github.com/cfoust/cy/pkg/bind" "github.com/cfoust/cy/pkg/cy/cmd" "github.com/cfoust/cy/pkg/cy/params" + cyParams "github.com/cfoust/cy/pkg/cy/params" "github.com/cfoust/cy/pkg/janet" "github.com/cfoust/cy/pkg/mux/screen/replayable" "github.com/cfoust/cy/pkg/mux/screen/tree" @@ -26,12 +27,24 @@ type Cmd struct { } func (c *Cmd) New( + user interface{}, groupId tree.NodeID, path string, cmdParams *janet.Named[CmdParams], ) (tree.NodeID, error) { + client, ok := user.(Client) + if !ok { + return 0, fmt.Errorf("missing client context") + } + + shell := "/bin/bash" + defaultShell, ok := client.Params().Get(cyParams.ParamDefaultShell) + if value, ok := defaultShell.(string); ok { + shell = value + } + values := cmdParams.WithDefault(CmdParams{ - Command: "/bin/bash", + Command: shell, }) group, ok := c.Tree.GroupById(groupId) diff --git a/pkg/cy/api/input.go b/pkg/cy/api/input.go index 6d095d48..1a2026b7 100644 --- a/pkg/cy/api/input.go +++ b/pkg/cy/api/input.go @@ -48,8 +48,7 @@ func (i *InputModule) Find( } shouldAnimate := true - clientParams := client.Params() - animated, ok := clientParams.Get(cyParams.ParamAnimate) + animated, ok := client.Params().Get(cyParams.ParamAnimate) if value, ok := animated.(bool); ok { shouldAnimate = value } diff --git a/pkg/cy/cy_test.go b/pkg/cy/cy_test.go index 53594424..df1b5220 100644 --- a/pkg/cy/cy_test.go +++ b/pkg/cy/cy_test.go @@ -76,6 +76,7 @@ func setupServer(t *testing.T) *TestServer { cy, err := Start(context.Background(), Options{ DataDir: filepath.Join(t.TempDir(), "data"), + Shell: "/bin/bash", }) require.NoError(t, err) diff --git a/pkg/cy/defaults.go b/pkg/cy/defaults.go index 51446531..bab1098d 100644 --- a/pkg/cy/defaults.go +++ b/pkg/cy/defaults.go @@ -8,6 +8,7 @@ func (c *Cy) setDefaults(options Options) error { defaults := map[string]interface{}{ params.ParamDataDirectory: options.DataDir, params.ParamAnimate: true, + params.ParamDefaultShell: options.Shell, } for key, value := range defaults { diff --git a/pkg/cy/module.go b/pkg/cy/module.go index 35b329ac..ca05e855 100644 --- a/pkg/cy/module.go +++ b/pkg/cy/module.go @@ -31,6 +31,8 @@ type Options struct { Config string // The default directory in which to store data (e.g. recorded sessions). DataDir string + // The default shell + Shell string } type historyEvent struct { diff --git a/pkg/cy/params/constants.go b/pkg/cy/params/constants.go index 3dc2ab7b..68e62824 100644 --- a/pkg/cy/params/constants.go +++ b/pkg/cy/params/constants.go @@ -7,4 +7,7 @@ const ( // Whether to enable animation. // boolean, default: true ParamAnimate = "animate" + // The default shell with which to start panes. + // string, default: /bin/bash, but also $SHELL + ParamDefaultShell = "default-shell" )