Skip to content

Commit

Permalink
remove sunbeam shell command
Browse files Browse the repository at this point in the history
  • Loading branch information
pomdtr committed Dec 22, 2023
1 parent 3014706 commit b9e3bb3
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 114 deletions.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ require (
golang.org/x/text v0.14.0 // indirect
gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
mvdan.cc/sh/v3 v3.7.0 // indirect
)

require (
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,3 @@ gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
mvdan.cc/sh/v3 v3.7.0 h1:lSTjdP/1xsddtaKfGg7Myu7DnlHItd3/M2tomOcNNBg=
mvdan.cc/sh/v3 v3.7.0/go.mod h1:K2gwkaesF/D7av7Kxl0HbF5kGOd2ArupNTX3X44+8l8=
36 changes: 16 additions & 20 deletions internal/cli/edit.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
package cli

import (
"context"
"fmt"
"io"
"os"
"strings"
"os/exec"

"github.com/mattn/go-isatty"
"github.com/pomdtr/sunbeam/internal/config"
"github.com/pomdtr/sunbeam/internal/utils"
"github.com/spf13/cobra"
"mvdan.cc/sh/v3/interp"
"mvdan.cc/sh/v3/syntax"
)

func NewCmdEdit() *cobra.Command {
Expand All @@ -38,11 +35,19 @@ func NewCmdEdit() *cobra.Command {
},
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) == 1 {
return utils.RunCommand(fmt.Sprintf("%s %s", utils.FindEditor(), args[0]), "")
editCmd := exec.Command("sh", "-c", fmt.Sprintf("%s %s", utils.FindEditor(), args[0]))
editCmd.Stdin = os.Stdin
editCmd.Stdout = os.Stdout
editCmd.Stderr = os.Stderr
return editCmd.Run()
}

if flags.config {
return utils.RunCommand(fmt.Sprintf("%s %s", utils.FindEditor(), config.Path), "")
editCmd := exec.Command("sh", "-c", fmt.Sprintf("%s %s", utils.FindEditor(), config.Path))
editCmd.Stdin = os.Stdin
editCmd.Stdout = os.Stdout
editCmd.Stderr = os.Stderr
return editCmd.Run()
}

var pattern string
Expand All @@ -58,7 +63,6 @@ func NewCmdEdit() *cobra.Command {
}
defer os.Remove(tempfile.Name())

// If stdin is not a terminal, copy stdin to tempfile
if !isatty.IsTerminal(os.Stdin.Fd()) {
f, err := os.OpenFile(tempfile.Name(), os.O_RDWR, 0644)
if err != nil {
Expand All @@ -77,19 +81,11 @@ func NewCmdEdit() *cobra.Command {
if err != nil {
return err
}
file, err := syntax.NewParser().Parse(strings.NewReader(fmt.Sprintf("%s %s", utils.FindEditor(), tempfile.Name())), "")
if err != nil {
fmt.Printf("Error parsing command: %v\n", err)
}

// Create a shell interpreter
sh, err := interp.New(interp.StdIO(tty, os.Stderr, nil))
if err != nil {
fmt.Printf("Error creating shell: %v\n", err)
}

// Create a shell interpreter
if err := sh.Run(context.Background(), file); err != nil {
editor := utils.FindEditor()
editCmd := exec.Command("sh", "-c", fmt.Sprintf("%s %s", editor, tempfile.Name()))
editCmd.Stdin = tty
editCmd.Stdout = os.Stderr
if err := editCmd.Run(); err != nil {
return err
}

Expand Down
3 changes: 0 additions & 3 deletions internal/cli/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"os"
"os/exec"
"path/filepath"
"regexp"
"strings"

tea "github.com/charmbracelet/bubbletea"
Expand Down Expand Up @@ -52,8 +51,6 @@ func extractAlias(origin string) (string, error) {
return strings.TrimSuffix(base, filepath.Ext(base)), nil
}

var repoRegexp = regexp.MustCompile(`^https://github.com/([^/]+)/([^/]+)`)

func normalizeOrigin(origin string) (string, error) {
if !strings.HasPrefix(origin, "http://") && !strings.HasPrefix(origin, "https://") {
if _, err := os.Stat(origin); err != nil {
Expand Down
1 change: 0 additions & 1 deletion internal/cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ See https://pomdtr.github.io/sunbeam for more information.`,
})
rootCmd.AddCommand(NewValidateCmd())
rootCmd.AddCommand(NewCmdEdit())
rootCmd.AddCommand(NewCmdShell())
rootCmd.AddCommand(NewCmdCopy())
rootCmd.AddCommand(NewCmdPaste())
rootCmd.AddCommand(NewCmdOpen())
Expand Down
58 changes: 0 additions & 58 deletions internal/cli/shell.go

This file was deleted.

2 changes: 1 addition & 1 deletion internal/tui/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ func (c *RootList) Update(msg tea.Msg) (Page, tea.Cmd) {
c.form.SetSize(c.width, c.height)
return c, c.form.Init()
case sunbeam.ActionTypeExec:
cmd := exec.Command("sunbeam", "shell", "-c", msg.Exec.Command)
cmd := exec.Command("sh", "-c", msg.Exec.Command)
cmd.Dir = msg.Exec.Dir
if strings.HasPrefix(cmd.Dir, "~") {
homeDir, err := os.UserHomeDir()
Expand Down
28 changes: 0 additions & 28 deletions internal/utils/shell.go

This file was deleted.

0 comments on commit b9e3bb3

Please sign in to comment.