{"modulePath":"github.com/windsorcli/cli","version":"v0.10.0","isLatest":true,"isStandardLibrary":false,"goos":"linux","goarch":"amd64","docs":"# package shell\n\n## Constants\n\n```go\nconst MaxFolderSearchDepth = 10\n```\nMaxFolderSearchDepth is the maximum depth to search for the project root, shared by GetProjectRoot and the EnsureGitRepository / EnsureProjectAnchor helpers so all walk-up traversals stop at the same boundary.\n\n```go\nconst SessionTokenPrefix = \".session.\"\n```\nSessionTokenPrefix is the prefix used for session token files\n\n## Variables\n\n```go\nvar ErrCommandTimedOut = errors.New(\"command timed out\")\n```\nErrCommandTimedOut marks a command killed for exceeding its timeout.\n\n## Functions\n\n```go\nfunc EnsureGitRepository() error\n```\nEnsureGitRepository returns an actionable error when no .git entry exists at or above the current working directory. Windsor relies on git for project- state ownership (trusted directories, blueprint refs, terraform state placement); running init in a bare directory produces opaque errors downstream, so the missing-repo case is surfaced here with a one-line operator hint. The walk caps at MaxFolderSearchDepth to match GetProjectRoot.\n\n```go\nfunc EnsureProjectAnchor() (string, error)\n```\nEnsureProjectAnchor writes a minimal windsor.yaml in the working directory when no project file exists in the walk-up path. This keeps windsor init out of global mode at $HOME/.config/windsor. It does nothing when a project file exists at or above the working directory. It returns the directory that holds the project file.\n\n```go\nfunc RenderCsh(envVars, aliases map[string]string) string\n```\nRenderCsh returns envVars as setenv commands and aliases as alias commands in tcsh syntax. An empty value gives unsetenv or unalias. Keys are in sorted order, env vars first. A newline in a value becomes a space, because a tcsh command substitution cannot keep it.\n\n```go\nfunc WithRemoved(values map[string]string, names []string) map[string]string\n```\nWithRemoved returns a copy of values with an empty value for each name in names that values does not have. RenderCsh then prints unsetenv or unalias for these names.\n\n## Types\n\n```go\ntype DefaultShell struct {\n\tShell\n\t// contains filtered or unexported fields\n}\n```\nDefaultShell is the default implementation of the Shell interface\n\n```go\nfunc NewDefaultShell() *DefaultShell\n```\nNewDefaultShell creates a new instance of DefaultShell\n\n```go\nfunc (s *DefaultShell) AddCurrentDirToTrustedFile() error\n```\nAddCurrentDirToTrustedFile adds the current directory to a trusted list stored in a file. Creates necessary directories if they don't exist. Checks if the directory is already trusted before adding. In global mode, trust is implicit for $HOME/.config/windsor and this is a no-op.\n\n```go\nfunc (s *DefaultShell) CheckResetFlags() (bool, error)\n```\nCheckResetFlags checks if a reset signal file exists for the current session token. It returns true if the specific session token file exists and always removes all .session.\\* files.\n\n```go\nfunc (s *DefaultShell) CheckTrustedDirectory() error\n```\nCheckTrustedDirectory verifies that the project root equals a trusted directory or is inside one. It compares path components, so \"/a/proj-evil\" does not inherit trust from \"/a/proj\". In global mode, trust is implicit for $HOME/.config/windsor and this check is skipped.\n\n```go\nfunc (s *DefaultShell) Exec(command string, args ...string) (string, error)\n```\nExec runs a command with args, capturing stdout and stderr. It prints output and returns stdout as a string. If the command is \"sudo\", it connects stdin to the terminal for password input. All output is scrubbed to remove registered secrets before being displayed or returned.\n\n```go\nfunc (s *DefaultShell) ExecCaptureWithEnv(command string, env map[string]string, args ...string) (string, error)\n```\nExecCaptureWithEnv runs a command with merged environment variables and captures its output, never streaming to stdout or stderr even in verbose mode. Use it for internal, machine-only output (e.g. \\`terraform show -json\\` state inspection) that is parsed rather than shown and may contain sensitive material such as cluster PKI — unlike ExecSilentWithEnv, which echoes captured output under verbose.\n\n```go\nfunc (s *DefaultShell) ExecProgress(message string, command string, args ...string) (string, error)\n```\nExecProgress is a method of the DefaultShell struct that executes a command for a progress step. It takes a message, a command, and arguments, using the Exec method if verbose mode is enabled. Otherwise, it captures stdout and stderr with pipes; the caller's presenter step shows progress. The method returns the command's stdout as a string and any error encountered.\n\n```go\nfunc (s *DefaultShell) ExecProgressWithEnv(message string, command string, env map[string]string, args ...string) (string, error)\n```\nExecProgressWithEnv executes a command with command-scoped env overrides. In verbose mode it prints message and streams output; otherwise it captures output and prints it only on failure.\n\n```go\nfunc (s *DefaultShell) ExecSilent(command string, args ...string) (string, error)\n```\nExecSilent is a method that runs a command quietly, capturing its output. It returns the command's stdout as a string and any error encountered.\n\n```go\nfunc (s *DefaultShell) ExecSilentWithEnv(command string, env map[string]string, args ...string) (string, error)\n```\nExecSilentWithEnv runs a command with merged environment variables, capturing output silently. In verbose mode, output is streamed directly to stdout and stderr.\n\n```go\nfunc (s *DefaultShell) ExecSilentWithEnvAndIdleTimeout(command string, env map[string]string, args []string, idleTimeout, absoluteTimeout, gracePeriod time.Duration) (string, error)\n```\nExecSilentWithEnvAndIdleTimeout runs command and streams its output to find a stall. Each output line resets idleTimeout. absoluteTimeout stops a command that never finishes. On either timeout, it interrupts the process group, waits up to gracePeriod, and then kills it. Use it for a long command that a hard kill can damage, such as terraform destroy, which must write a state checkpoint and release its backend lock. Use ExecSilentWithEnvAndTimeout for other commands.\n\n```go\nfunc (s *DefaultShell) ExecSilentWithEnvAndTimeout(command string, env map[string]string, args []string, timeout time.Duration) (string, error)\n```\nExecSilentWithEnvAndTimeout combines ExecSilentWithEnv and ExecSilentWithTimeout: it merges command-scoped env overrides into the inherited environment AND enforces a timeout, killing the child process if it exceeds the deadline. Used by callers that need both behaviors at once — e.g. CheckAuth() running \\`aws sts get-caller-identity\\` with the context-scoped AWS\\_CONFIG\\_FILE/AWS\\_PROFILE set, where the env is required for credential resolution and the timeout guards against a hung network call.\n\n```go\nfunc (s *DefaultShell) ExecSilentWithTimeout(command string, args []string, timeout time.Duration) (string, error)\n```\nExecSilentWithTimeout executes a command with a timeout and returns the output. If the command takes longer than the timeout, it kills the process and returns an error. Uses ExecSilent internally but wraps it with a timeout mechanism.\n\n```go\nfunc (s *DefaultShell) ExecSudo(message string, command string, args ...string) (string, error)\n```\nExecSudo runs command with sudo and returns its output. In verbose mode or without a TTY, it runs the command directly. Otherwise it connects to /dev/tty for the password prompt and takes the terminal from the presenter. A scrubbingWriter buffers stderr by line, so registered secrets never reach the terminal. Because of the buffer, progress that uses only \\\\r shows when the child writes \\\\n or exits.\n\n```go\nfunc (s *DefaultShell) GetProjectRoot() (string, error)\n```\nGetProjectRoot finds the project root. It checks for a cached root first. If not found, it looks for \"windsor.yaml\" or \"windsor.yml\" in the current directory and its parents up to a maximum depth, returning the first match. When no project file is found, it falls back to $HOME/.config/windsor, creating that directory if needed, and marks the shell as operating in global mode.\n\n```go\nfunc (s *DefaultShell) GetSessionToken() (string, error)\n```\nGetSessionToken retrieves or generates a session token. It first checks if a token is already stored in memory. If not, it looks for a token in the environment variable. If no token is found in the environment, it generates a new token.\n\n```go\nfunc (s *DefaultShell) InstallHook(shellName string) error\n```\nInstallHook sets up a shell hook for a specified shell using a template with the Windsor path. It returns an error if the shell is unsupported. For PowerShell, it formats the script into a single line.\n\n```go\nfunc (s *DefaultShell) IsGlobal() bool\n```\nIsGlobal reports whether the shell is operating in global mode. Global mode is set when GetProjectRoot could not locate a windsor.yaml/windsor.yml in the current directory or any of its parents, and the shell has fallen back to the user's $HOME/.config/windsor directory as the effective project root.\n\n```go\nfunc (s *DefaultShell) IsVerbose() bool\n```\nIsVerbose returns the current verbosity flag value.\n\n```go\nfunc (s *DefaultShell) PrintEnvVars(envVars map[string]string, export bool)\n```\nPrintEnvVars is a platform-specific method that will be implemented by Unix/Windows-specific files The export parameter controls whether to use OS-specific export commands or plain KEY=value format\n\n```go\nfunc (s *DefaultShell) RegisterResolvedSecret(value string)\n```\nRegisterResolvedSecret registers a value that a secret provider resolved. It skips the length floor of RegisterSecret, because a resolved value is a deliberate secret. Empty values are ignored. A short value hides every occurrence of that text in command output, including inside other words.\n\n```go\nfunc (s *DefaultShell) RegisterSecret(value string)\n```\nRegisterSecret adds a secret value to the internal list of secrets that will be scrubbed from all command output. Values shorter than minRegisteredSecretLength are ignored, since scrubbing a short common substring mangles unrelated output while providing no real confidentiality. Duplicate values are automatically filtered out to maintain list efficiency. Safe for concurrent use with scrubString.\n\n```go\nfunc (s *DefaultShell) RenderAliases(aliases map[string]string) string\n```\nRenderAliases returns the rendered aliases as a string using Unix shell syntax\n\n```go\nfunc (s *DefaultShell) RenderEnvVars(envVars map[string]string, export bool) string\n```\nRenderEnvVars returns the rendered environment variables as a string instead of printing them The export parameter controls whether to use OS-specific export commands or plain KEY=value format\n\n```go\nfunc (s *DefaultShell) Reset(quiet ...bool)\n```\nReset removes all managed environment variables and aliases. It uses the environment variables \"WINDSOR\\_MANAGED\\_ENV\" and \"WINDSOR\\_MANAGED\\_ALIAS\" to retrieve the previous set of managed environment variables and aliases, respectively. These environment variables represent the previous set of managed values that need to be reset. The optional quiet parameter controls whether shell commands are printed during reset.\n\n```go\nfunc (s *DefaultShell) ResetSessionToken()\n```\nResetSessionToken resets the session token - used primarily for testing\n\n```go\nfunc (s *DefaultShell) SetVerbosity(verbose bool)\n```\nSetVerbosity sets the verbosity flag\n\n```go\nfunc (s *DefaultShell) UnsetAlias(aliases []string)\n```\nUnsetAlias generates individual unalias commands for each alias in Unix shells. It prints a separate 'unalias' command for each alias name provided. If the input slice is empty, no output is produced.\n\n```go\nfunc (s *DefaultShell) UnsetEnvs(envVars []string)\n```\nUnsetEnvs generates a single unset command for multiple environment variables in Unix shells. It prints a single 'unset' command with all provided variable names separated by spaces. If the input slice is empty, no output is produced.\n\n```go\nfunc (s *DefaultShell) WriteResetToken() (string, error)\n```\nWriteResetToken writes a reset token file based on the WINDSOR\\_SESSION\\_TOKEN environment variable. If the environment variable doesn't exist, no file is written. Returns the path to the written file or an empty string if no file was written.\n\n```go\ntype HookContext struct {\n\t// SelfPath is the unescaped absolute path to the Windsor binary\n\tSelfPath string\n}\n```\nHookContext are the variables available during hook template evaluation\n\n```go\ntype MockShell struct {\n\tDefaultShell\n\tRenderEnvVarsFunc                   func(envVars map[string]string, export bool) string\n\tRenderAliasesFunc                   func(aliases map[string]string) string\n\tGetProjectRootFunc                  func() (string, error)\n\tExecFunc                            func(command string, args ...string) (string, error)\n\tExecSilentFunc                      func(command string, args ...string) (string, error)\n\tExecSilentWithEnvFunc               func(command string, env map[string]string, args ...string) (string, error)\n\tExecCaptureWithEnvFunc              func(command string, env map[string]string, args ...string) (string, error)\n\tExecSilentWithTimeoutFunc           func(command string, args []string, timeout time.Duration) (string, error)\n\tExecSilentWithEnvAndTimeoutFunc     func(command string, env map[string]string, args []string, timeout time.Duration) (string, error)\n\tExecSilentWithEnvAndIdleTimeoutFunc func(command string, env map[string]string, args []string, idleTimeout, absoluteTimeout, gracePeriod time.Duration) (string, error)\n\tExecProgressFunc                    func(message string, command string, args ...string) (string, error)\n\tExecProgressWithEnvFunc             func(message string, command string, env map[string]string, args ...string) (string, error)\n\tExecSudoFunc                        func(message string, command string, args ...string) (string, error)\n\tInstallHookFunc                     func(shellName string) error\n\tSetVerbosityFunc                    func(verbose bool)\n\tIsVerboseFunc                       func() bool\n\tIsGlobalFunc                        func() bool\n\tAddCurrentDirToTrustedFileFunc      func() error\n\tCheckTrustedDirectoryFunc           func() error\n\tUnsetEnvsFunc                       func(envVars []string)\n\tUnsetAliasFunc                      func(aliases []string)\n\tWriteResetTokenFunc                 func() (string, error)\n\tGetSessionTokenFunc                 func() (string, error)\n\tCheckResetFlagsFunc                 func() (bool, error)\n\tResetFunc                           func(...bool)\n\tRegisterSecretFunc                  func(value string)\n\tRegisterResolvedSecretFunc          func(value string)\n}\n```\n\n```go\nfunc NewMockShell() *MockShell\n```\nNewMockShell creates a new instance of MockShell\n\n```go\nfunc (s *MockShell) AddCurrentDirToTrustedFile() error\n```\nAddCurrentDirToTrustedFile calls the custom AddCurrentDirToTrustedFileFunc if provided.\n\n```go\nfunc (s *MockShell) CheckResetFlags() (bool, error)\n```\nCheckResetFlags checks if a reset signal file exists for the current session\n\n```go\nfunc (s *MockShell) CheckTrustedDirectory() error\n```\nCheckTrustedDirectory calls the custom CheckTrustedDirectoryFunc if provided.\n\n```go\nfunc (s *MockShell) Exec(command string, args ...string) (string, error)\n```\nExec calls the custom ExecFunc if provided.\n\n```go\nfunc (s *MockShell) ExecCaptureWithEnv(command string, env map[string]string, args ...string) (string, error)\n```\nExecCaptureWithEnv calls the custom ExecCaptureWithEnvFunc if provided, otherwise delegates to ExecSilentWithEnv.\n\n```go\nfunc (s *MockShell) ExecProgress(message string, command string, args ...string) (string, error)\n```\nExecProgress calls the custom ExecProgressFunc if provided.\n\n```go\nfunc (s *MockShell) ExecProgressWithEnv(message string, command string, env map[string]string, args ...string) (string, error)\n```\nExecProgressWithEnv calls the custom ExecProgressWithEnvFunc if provided, otherwise falls back to ExecProgressFunc to preserve existing tests.\n\n```go\nfunc (s *MockShell) ExecSilent(command string, args ...string) (string, error)\n```\nExecSilent calls the custom ExecSilentFunc if provided.\n\n```go\nfunc (s *MockShell) ExecSilentWithEnv(command string, env map[string]string, args ...string) (string, error)\n```\nExecSilentWithEnv calls the custom ExecSilentWithEnvFunc if provided, otherwise delegates to ExecSilent.\n\n```go\nfunc (s *MockShell) ExecSilentWithEnvAndIdleTimeout(command string, env map[string]string, args []string, idleTimeout, absoluteTimeout, gracePeriod time.Duration) (string, error)\n```\nExecSilentWithEnvAndIdleTimeout calls the custom ExecSilentWithEnvAndIdleTimeoutFunc if provided. Falls back to ExecSilentWithEnvAndTimeout, reusing idleTimeout as its flat timeout and ignoring absoluteTimeout and gracePeriod, so existing tests that stub a simpler variant keep working.\n\n```go\nfunc (s *MockShell) ExecSilentWithEnvAndTimeout(command string, env map[string]string, args []string, timeout time.Duration) (string, error)\n```\nExecSilentWithEnvAndTimeout calls the custom ExecSilentWithEnvAndTimeoutFunc if provided. Falls back to ExecSilentWithEnvFunc (then ExecSilentWithTimeoutFunc, then ExecSilent) so existing tests that only stub one of the simpler variants keep working.\n\n```go\nfunc (s *MockShell) ExecSilentWithTimeout(command string, args []string, timeout time.Duration) (string, error)\n```\nExecSilentWithTimeout calls the custom ExecSilentWithTimeoutFunc if provided, otherwise delegates to ExecSilent.\n\n```go\nfunc (s *MockShell) ExecSudo(message string, command string, args ...string) (string, error)\n```\nExecSudo calls the custom ExecSudoFunc if provided.\n\n```go\nfunc (s *MockShell) GetProjectRoot() (string, error)\n```\nGetProjectRoot calls the custom GetProjectRootFunc if provided.\n\n```go\nfunc (s *MockShell) GetSessionToken() (string, error)\n```\nGetSessionToken retrieves or generates a session token\n\n```go\nfunc (s *MockShell) InstallHook(shellName string) error\n```\nInstallHook calls the custom InstallHook if provided.\n\n```go\nfunc (s *MockShell) IsGlobal() bool\n```\nIsGlobal calls the custom IsGlobalFunc if provided.\n\n```go\nfunc (s *MockShell) IsVerbose() bool\n```\nIsVerbose calls the custom IsVerboseFunc if provided.\n\n```go\nfunc (s *MockShell) RegisterResolvedSecret(value string)\n```\nRegisterResolvedSecret calls the custom RegisterResolvedSecretFunc if provided.\n\n```go\nfunc (s *MockShell) RegisterSecret(value string)\n```\nRegisterSecret calls the custom RegisterSecretFunc if provided.\n\n```go\nfunc (s *MockShell) RenderAliases(aliases map[string]string) string\n```\nRenderAliases calls the custom RenderAliasesFunc if provided.\n\n```go\nfunc (s *MockShell) RenderEnvVars(envVars map[string]string, export bool) string\n```\nRenderEnvVars calls the custom RenderEnvVarsFunc if provided.\n\n```go\nfunc (s *MockShell) Reset(quiet ...bool)\n```\nReset calls the custom ResetFunc if provided.\n\n```go\nfunc (s *MockShell) SetVerbosity(verbose bool)\n```\nSetVerbosity calls the custom SetVerbosityFunc if provided.\n\n```go\nfunc (s *MockShell) UnsetAlias(aliases []string)\n```\nUnsetAlias calls the custom UnsetAliasFunc if provided.\n\n```go\nfunc (s *MockShell) UnsetEnvs(envVars []string)\n```\nUnsetEnvs calls the custom UnsetEnvsFunc if provided.\n\n```go\nfunc (s *MockShell) WriteResetToken() (string, error)\n```\nWriteResetToken writes a reset token file\n\n```go\ntype Shell interface {\n\tSetVerbosity(verbose bool)\n\tIsVerbose() bool\n\tIsGlobal() bool\n\tRenderEnvVars(envVars map[string]string, export bool) string\n\tRenderAliases(aliases map[string]string) string\n\tGetProjectRoot() (string, error)\n\tExec(command string, args ...string) (string, error)\n\tExecSilent(command string, args ...string) (string, error)\n\tExecSilentWithEnv(command string, env map[string]string, args ...string) (string, error)\n\tExecCaptureWithEnv(command string, env map[string]string, args ...string) (string, error)\n\tExecSilentWithTimeout(command string, args []string, timeout time.Duration) (string, error)\n\tExecSilentWithEnvAndTimeout(command string, env map[string]string, args []string, timeout time.Duration) (string, error)\n\tExecSilentWithEnvAndIdleTimeout(command string, env map[string]string, args []string, idleTimeout, absoluteTimeout, gracePeriod time.Duration) (string, error)\n\tExecSudo(message string, command string, args ...string) (string, error)\n\tExecProgress(message string, command string, args ...string) (string, error)\n\tExecProgressWithEnv(message string, command string, env map[string]string, args ...string) (string, error)\n\tInstallHook(shellName string) error\n\tAddCurrentDirToTrustedFile() error\n\tCheckTrustedDirectory() error\n\tUnsetEnvs(envVars []string)\n\tUnsetAlias(aliases []string)\n\tWriteResetToken() (string, error)\n\tGetSessionToken() (string, error)\n\tCheckResetFlags() (bool, error)\n\tReset(quiet ...bool)\n\tRegisterSecret(value string)\n\tRegisterResolvedSecret(value string)\n}\n```\nShell is the interface that defines shell operations.\n\n```go\ntype Shims struct {\n\tshims.Shims\n\tExecutable            func() (string, error)\n\tCommand               func(name string, arg ...string) *exec.Cmd\n\tEnviron               func() []string\n\tOpenFile              func(name string, flag int, perm os.FileMode) (*os.File, error)\n\tCmdRun                func(cmd *exec.Cmd) error\n\tCmdStart              func(cmd *exec.Cmd) error\n\tCmdWait               func(cmd *exec.Cmd) error\n\tStdoutPipe            func(cmd *exec.Cmd) (io.ReadCloser, error)\n\tStderrPipe            func(cmd *exec.Cmd) (io.ReadCloser, error)\n\tNewTemplate           func(name string) *template.Template\n\tTemplateParse         func(tmpl *template.Template, text string) (*template.Template, error)\n\tTemplateExecute       func(tmpl *template.Template, wr io.Writer, data any) error\n\tNewScanner            func(r io.Reader) *bufio.Scanner\n\tScannerScan           func(scanner *bufio.Scanner) bool\n\tScannerErr            func(scanner *bufio.Scanner) error\n\tScannerText           func(scanner *bufio.Scanner) string\n\tRandRead              func(b []byte) (n int, err error)\n\tIsTerminal            func(fd int) bool\n\tSignalNotify          func(c chan\u003c- os.Signal, sig ...os.Signal)\n\tSignalStop            func(c chan\u003c- os.Signal)\n\tInterruptProcessGroup func(cmd *exec.Cmd) error\n\tKillProcessGroup      func(cmd *exec.Cmd) error\n}\n```\nShims holds the shared system call primitives and the shell-specific shims.\n\n```go\nfunc NewShims() *Shims\n```\nNewShims returns a Shims with every field set to its real implementation.\n\n","path":"github.com/windsorcli/cli/pkg/runtime/shell","name":"shell","synopsis":"","isRedistributable":true}
