Skip to content

Commit

Permalink
gosh: stop running scripts if they end with .sh
Browse files Browse the repository at this point in the history
Not a good way to figure out how to run something.
Filed mvdan/sh#1065 instead.

Signed-off-by: Chris Koch <[email protected]>
  • Loading branch information
hugelgupf committed Mar 4, 2024
1 parent c76776b commit 565191e
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 24 deletions.
12 changes: 0 additions & 12 deletions cmds/core/gosh/completer.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,6 @@ func runInteractive(runner *interp.Runner, parser *syntax.Parser, stdout, stderr
default:
}

// check if we want to execute a shell script
fields := strings.Fields(line)
if len(fields) > 0 && strings.HasSuffix(fields[0], "sh") {
if err := runScript(runner, parser, fields[0]); err != nil {
fmt.Fprintf(stderr, "error: %s\n", err.Error())
}

continue
}

if line != "" {
if err := input.AddHistory(line); err != nil {
fmt.Fprintf(stdout, "unable to add %s to history: %v\n", line, err)
Expand All @@ -161,12 +151,10 @@ func runInteractive(runner *interp.Runner, parser *syntax.Parser, stdout, stderr
if err := parser.Stmts(strings.NewReader(line), func(stmt *syntax.Stmt) bool {
if parser.Incomplete() {
fmt.Fprintf(stdout, "-> ")

return true
}

runErr = runner.Run(context.Background(), stmt)

return !runner.Exited()
}); err != nil {
fmt.Fprintf(stderr, "error: %s\n", err.Error())
Expand Down
12 changes: 0 additions & 12 deletions cmds/core/gosh/completer_liner.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,6 @@ func runInteractive(runner *interp.Runner, parser *syntax.Parser, stdout, stderr
default:
}

// check if we want to execute a shell script
fields := strings.Fields(line)
if len(fields) > 0 && strings.HasSuffix(fields[0], "sh") {
if err := runScript(runner, parser, fields[0]); err != nil {
fmt.Fprintf(stderr, "error: %s\n", err.Error())
}

continue
}

if line != "" {
input.AppendHistory(line)
if f != nil {
Expand All @@ -101,12 +91,10 @@ func runInteractive(runner *interp.Runner, parser *syntax.Parser, stdout, stderr
if err := parser.Stmts(strings.NewReader(line), func(stmt *syntax.Stmt) bool {
if parser.Incomplete() {
fmt.Fprintf(stdout, "-> ")

return true
}

runErr = runner.Run(context.Background(), stmt)

return !runner.Exited()
}); err != nil {
fmt.Fprintf(stderr, "error: %s\n", err.Error())
Expand Down

0 comments on commit 565191e

Please sign in to comment.