Skip to content

Commit

Permalink
feat: use SHELL
Browse files Browse the repository at this point in the history
  • Loading branch information
cfoust committed Nov 22, 2023
1 parent ea567e2 commit 787945d
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 3 deletions.
1 change: 1 addition & 0 deletions cmd/cy/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 14 additions & 1 deletion pkg/cy/api/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions pkg/cy/api/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions pkg/cy/cy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
1 change: 1 addition & 0 deletions pkg/cy/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions pkg/cy/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions pkg/cy/params/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

0 comments on commit 787945d

Please sign in to comment.