shell

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package shell handles shell wrapper generation and installation for saws. Since a child process cannot modify its parent's environment, saws uses a shell function wrapper that evals the binary's --export output. This is the same pattern used by nvm, rbenv, direnv, and aws-vault.

Index

Constants

View Source
const WrapperEnvVar = "SAWS_WRAPPER"

WrapperEnvVar is the environment variable set by the shell wrapper so the binary can detect whether it's running inside the wrapper.

Variables

This section is empty.

Functions

func BinaryPath

func BinaryPath() (string, error)

BinaryPath returns the path to the saws binary. It first checks if the binary is in PATH, then falls back to the current executable.

func Install

func Install(sh Shell, binaryPath string, rcPath string) error

Install adds the saws wrapper function to the shell's rc file. If the block already exists, it replaces it. Otherwise, it appends it.

func IsInstalled

func IsInstalled(rcPath string) bool

IsInstalled checks if the saws wrapper is present in the given rc file.

func IsWrapped

func IsWrapped() bool

IsWrapped returns true if the current process is running inside the shell wrapper.

func RCFile

func RCFile(sh Shell) (string, error)

RCFile returns the path to the shell's rc file.

func SupportedShells

func SupportedShells() []string

SupportedShells returns the list of supported shell names.

func Uninstall

func Uninstall(rcPath string) error

Uninstall removes the saws wrapper function from the shell's rc file.

func WrapperScript

func WrapperScript(sh Shell, binaryPath string) string

WrapperScript generates the shell wrapper function for the given shell. The wrapper:

  1. Sets SAWS_WRAPPER=1 so the binary knows it's wrapped
  2. Runs the binary with --export and any extra args
  3. Evals the output to set env vars in the parent shell
  4. Falls through to the real binary for non-credential flows (configure, version, etc.)

Types

type Shell

type Shell string

Shell represents a supported shell type.

const (
	// Bash is the bash shell.
	Bash Shell = "bash"
	// Zsh is the zsh shell.
	Zsh Shell = "zsh"
	// Fish is the fish shell.
	Fish Shell = "fish"
)

func DetectShell

func DetectShell() (Shell, error)

DetectShell tries to determine the current shell from the SHELL environment variable.

func ParseShell

func ParseShell(name string) (Shell, error)

ParseShell parses a shell name string into a Shell type.

Jump to

Keyboard shortcuts

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