shcoreutils

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 106 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

charm.land/turtle/shcoreutils

An mvdan/sh interpreter middleware that runs our coreutils inside Go programs.

This is particularly useful on Windows, where the Unix core utilities are not normally installed. Utilities provided by the interpreter as builtins keep their builtin behavior. Nested invocations through xargs, env, find -exec and similar utilities also resolve coreutils and use the interpreter's remaining execution handlers for external programs.

package main

import (
	"log"

	"charm.land/turtle/shcoreutils"
	"mvdan.cc/sh/v3/interp"
)

func main() {
	interpreter, err := interp.New(interp.ExecHandlers(shcoreutils.New()))
	if err != nil {
		log.Fatal(err)
	}
	_ = interpreter
}

By default the Turtle implementations shadow the system ones. Use shcoreutils.New with shcoreutils.WithPriority to change that:

  • PriorityTurtle (default): always run the Turtle implementations.
  • PrioritySystem: run the system utility when it resolves in PATH, falling back to Turtle otherwise.
  • PriorityAuto: Turtle on Windows, system utilities elsewhere.

On Windows, a few programs whose system namesakes are unrelated tools (find, sort, expand, timeout) always run as Turtle, whatever the priority.

connector := shcoreutils.New(shcoreutils.WithPriority(shcoreutils.PriorityAuto))
interpreter, err := interp.New(interp.ExecHandlers(connector))

Install it with:

go get charm.land/turtle/shcoreutils@latest

Documentation

Overview

Package shcoreutils provides a middleware for the mvdan/sh interpreter that runs the core utils commands of charm.land/turtle/coreutils.

This is particularly useful to keep the max compability on Windows where these core utils are not available, unless when installed manually by the user.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

New returns an interp.ExecHandlerFunc middleware configured with opts. It handles the core utils commands, excluding those shadowed by interpreter builtins. Use WithPriority to prefer the system implementations.

Utilities which invoke other programs resolve those names through the same table, and run external programs through the remaining handler chain with the requested directory, environment, and streams.

Types

type Error

type Error struct {
	// contains filtered or unexported fields
}

Error wraps an error returned from a core utility, carrying its exit status.

func (*Error) Error

func (err *Error) Error() string

func (*Error) Unwrap

func (err *Error) Unwrap() []error

type Option

type Option func(*config)

Option configures the middleware returned by New.

func WithPriority

func WithPriority(priority Priority) Option

WithPriority sets which implementation runs when both are available.

type Priority

type Priority uint8

Priority decides whether a command in the table runs as a Turtle utility or as the system executable.

const (
	// PriorityTurtle runs the Turtle implementations, shadowing the system
	// ones. It's the default.
	PriorityTurtle Priority = iota

	// PrioritySystem runs the system utility when it resolves in the PATH of
	// the command, falling back to Turtle otherwise.
	PrioritySystem

	// PriorityAuto runs Turtle on Windows, and the system utilities
	// elsewhere.
	PriorityAuto
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL