{"modulePath":"github.com/wavetermdev/waveterm/waveshell","version":"v0.7.6","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package shellapi\n\n## Constants\n\n```go\nconst (\n\tBashSection_Ignored = iota\n\tBashSection_Version\n\tBashSection_Cwd\n\tBashSection_Vars\n\tBashSection_Aliases\n\tBashSection_Funcs\n\tBashSection_PVars\n\tBashSection_EndBytes\n\n\tBashSection_Count // must be last\n)\n```\n\n```go\nconst (\n\tZshSection_Version = iota\n\tZshSection_Cwd\n\tZshSection_Env\n\tZshSection_Mods\n\tZshSection_Vars\n\tZshSection_Aliases\n\tZshSection_Fpath\n\tZshSection_Funcs\n\tZshSection_PVars\n\tZshSection_Prompt\n\tZshSection_EndBytes\n\n\tZshSection_NumFieldsExpected // must be last\n)\n```\n\n```go\nconst BaseBashOpts = `set +m; set +H; shopt -s extglob`\n```\n\n```go\nconst BaseZshOpts = ``\n```\n\n```go\nconst BashShellVersionCmdStr = `echo bash v${BASH_VERSINFO[0]}.${BASH_VERSINFO[1]}.${BASH_VERSINFO[2]}`\n```\n\n```go\nconst DebugState = false\n```\n\n```go\nconst DefaultMacOSShell = \"/bin/bash\"\n```\n\n```go\nconst FirstExtraFilesFdNum = 3\n```\n\n```go\nconst GetGitBranchCmdStr = `printf \"GITBRANCH %s\\x00\" \"$(git rev-parse --abbrev-ref HEAD 2\u003e/dev/null)\"`\n```\n\n```go\nconst GetK8sContextCmdStr = `printf \"K8SCONTEXT %s\\x00\" \"$(kubectl config current-context 2\u003e/dev/null)\"`\n```\n\n```go\nconst GetK8sNamespaceCmdStr = `printf \"K8SNAMESPACE %s\\x00\" \"$(kubectl config view --minify --output 'jsonpath={..namespace}' 2\u003e/dev/null)\"`\n```\n\n```go\nconst GetVersionTimeout = 5 * time.Second\n```\n\n```go\nconst NumRandomEndBytes = 8\n```\n\n```go\nconst RemoteBashPath = \"bash\"\n```\n\n```go\nconst RunBashSudoCommandFmt = `sudo -n -C %d bash /dev/fd/%d`\n```\nTODO fix bash path in these constants\n\n```go\nconst RunBashSudoPasswordCommandFmt = `cat /dev/fd/%d | sudo -k -S -C %d bash -c \"echo '[from-mshell]'; exec %d\u003e\u0026-; bash /dev/fd/%d \u003c /dev/fd/%d\"`\n```\n\n```go\nconst RunCommandFmt = `%s`\n```\n\n```go\nconst RunZshSudoCommandFmt = `sudo -n -C %d zsh /dev/fd/%d`\n```\nTODO these need updating\n\n```go\nconst RunZshSudoPasswordCommandFmt = `cat /dev/fd/%d | sudo -k -S -C %d zsh -c \"echo '[from-mshell]'; exec %d\u003e\u0026-; zsh /dev/fd/%d \u003c /dev/fd/%d\"`\n```\n\n```go\nconst (\n\tShellStateOutputStatus_Done = \"done\"\n)\n```\n\n```go\nconst StateOutputFdNum = 20\n```\n\n```go\nconst ValidateTimeout = 2 * time.Second\n```\n\n```go\nconst ZModsVarName = \"WAVESTATE_ZMODS\"\n```\n\n```go\nconst ZshAutoloadFnBody = \"builtin autoload -XU\"\n```\n\n```go\nconst ZshFnAutoLoad = \"autoload\"\n```\nsentinel value for functions that should be autoloaded\n\n```go\nconst ZshShellVersionCmdStr = `echo zsh v$ZSH_VERSION`\n```\n\n## Variables\n\n```go\nvar BashNoStoreVarNames = map[string]bool{\n\t\"BASH\":                  true,\n\t\"BASHOPTS\":              true,\n\t\"BASHPID\":               true,\n\t\"BASH_ALIASES\":          true,\n\t\"BASH_ARGC\":             true,\n\t\"BASH_ARGV\":             true,\n\t\"BASH_ARGV0\":            true,\n\t\"BASH_CMDS\":             true,\n\t\"BASH_COMMAND\":          true,\n\t\"BASH_EXECUTION_STRING\": true,\n\t\"LINENO\":                true,\n\t\"BASH_LINENO\":           true,\n\t\"BASH_REMATCH\":          true,\n\t\"BASH_SOURCE\":           true,\n\t\"BASH_SUBSHELL\":         true,\n\t\"COPROC\":                true,\n\t\"DIRSTACK\":              true,\n\t\"EPOCHREALTIME\":         true,\n\t\"EPOCHSECONDS\":          true,\n\t\"FUNCNAME\":              true,\n\t\"HISTCMD\":               true,\n\t\"OLDPWD\":                true,\n\t\"PIPESTATUS\":            true,\n\t\"PPID\":                  true,\n\t\"PWD\":                   true,\n\t\"RANDOM\":                true,\n\t\"SECONDS\":               true,\n\t\"SHLVL\":                 true,\n\t\"HISTFILE\":              true,\n\t\"HISTFILESIZE\":          true,\n\t\"HISTCONTROL\":           true,\n\t\"HISTIGNORE\":            true,\n\t\"HISTSIZE\":              true,\n\t\"HISTTIMEFORMAT\":        true,\n\t\"SRANDOM\":               true,\n\t\"COLUMNS\":               true,\n\t\"LINES\":                 true,\n}\n```\n[https://wiki.bash-hackers.org/syntax/shellvars](https://wiki.bash-hackers.org/syntax/shellvars)\n\n```go\nvar GetBashShellStateCmds = []string{\n\t\"exec 2\u003e /dev/null;\",\n\tBashShellVersionCmdStr + \";\",\n\t`pwd;`,\n\t`declare -p $(compgen -A variable);`,\n\t`alias -p;`,\n\t`declare -f;`,\n\tGetGitBranchCmdStr + \";\",\n}\n```\nthe \"exec 2\u003e\" line also adds an extra printf at the \\*beginning\\* to strip out spurious rc file output\n\n```go\nvar ZshForceLoadMods = map[string]bool{\n\t\"zsh/parameter\": true,\n\t\"zsh/langinfo\":  true,\n}\n```\n\n```go\nvar ZshForceOptions = map[string]bool{\n\t\"globalrcs\":        false,\n\t\"ksharrays\":        false,\n\t\"kshtypeset\":       false,\n\t\"kshautoload\":      false,\n\t\"kshzerosubscript\": false,\n\t\"xtrace\":           false,\n\t\"verbose\":          false,\n\t\"debugbeforecmd\":   false,\n}\n```\nforce these options on/off at beginning of rcfile\n\n```go\nvar ZshIgnoreFuncs = map[string]bool{\n\t\"zftp_chpwd\":    true,\n\t\"zftp_progress\": true,\n}\n```\n\n```go\nvar ZshIgnoreOptions = map[string]bool{\n\t\"globalrcs\":        true,\n\t\"ksharrays\":        true,\n\t\"kshtypeset\":       true,\n\t\"kshautoload\":      true,\n\t\"kshzerosubscript\": true,\n\t\"interactive\":      true,\n\t\"login\":            true,\n\t\"zle\":              true,\n\t\"shinstdin\":        true,\n\t\"privileged\":       true,\n\t\"restricted\":       true,\n\t\"singlecommand\":    true,\n}\n```\nonly options we restore (other than ZshForceOptions)\n\n```go\nvar ZshIgnoreVars = map[string]bool{\n\t\"_\":                    true,\n\t\"0\":                    true,\n\t\"terminfo\":             true,\n\t\"RANDOM\":               true,\n\t\"COLUMNS\":              true,\n\t\"LINES\":                true,\n\t\"argv\":                 true,\n\t\"SECONDS\":              true,\n\t\"PWD\":                  true,\n\t\"HISTCHARS\":            true,\n\t\"HISTFILE\":             true,\n\t\"HISTSIZE\":             true,\n\t\"SAVEHIST\":             true,\n\t\"ZSH_EXECUTION_STRING\": true,\n\t\"EPOCHSECONDS\":         true,\n\t\"EPOCHREALTIME\":        true,\n\t\"SHLVL\":                true,\n\t\"TTY\":                  true,\n\t\"ZDOTDIR\":              true,\n\t\"PPID\":                 true,\n\t\"epochtime\":            true,\n\t\"langinfo\":             true,\n\t\"keymaps\":              true,\n\t\"widgets\":              true,\n\t\"options\":              true,\n\t\"aliases\":              true,\n\t\"dis_aliases\":          true,\n\t\"saliases\":             true,\n\t\"dis_saliases\":         true,\n\t\"galiases\":             true,\n\t\"dis_galiases\":         true,\n\t\"builtins\":             true,\n\t\"dis_builtins\":         true,\n\t\"modules\":              true,\n\t\"history\":              true,\n\t\"historywords\":         true,\n\t\"jobdirs\":              true,\n\t\"jobstates\":            true,\n\t\"jobtexts\":             true,\n\t\"funcfiletrace\":        true,\n\t\"funcsourcetrace\":      true,\n\t\"funcstack\":            true,\n\t\"functrace\":            true,\n\t\"nameddirs\":            true,\n\t\"userdirs\":             true,\n\t\"parameters\":           true,\n\t\"commands\":             true,\n\t\"functions\":            true,\n\t\"dis_functions\":        true,\n\t\"functions_source\":     true,\n\t\"dis_functions_source\": true,\n\t\"_comps\":               true,\n\t\"_patcomps\":            true,\n\t\"_postpatcomps\":        true,\n\n\t\"errnos\":    true,\n\t\"sysparams\": true,\n\n\t\"ZCURSES_COLORS\":      true,\n\t\"ZCURSES_COLOR_PAIRS\": true,\n\t\"zcurses_attrs\":       true,\n\t\"zcurses_colors\":      true,\n\t\"zcurses_keycodes\":    true,\n\t\"zcurses_windows\":     true,\n\n\t\"_GITSTATUS_CLIENT_PID_POWERLEVEL9K\":  true,\n\t\"GITSTATUS_DAEMON_PID_POWERLEVEL9K\":   true,\n\t\"_GITSTATUS_FILE_PREFIX_POWERLEVEL9K\": true,\n}\n```\n\n```go\nvar ZshSpecialDecls = map[string]bool{\n\t\"precmd_functions\":  true,\n\t\"preexec_functions\": true,\n}\n```\n\n```go\nvar ZshUniqueArrayVars = map[string]bool{\n\t\"path\":  true,\n\t\"fpath\": true,\n}\n```\n\n```go\nvar ZshUnsetVars = []string{\n\t\"HISTFILE\",\n\t\"ZSH_EXECUTION_STRING\",\n}\n```\n\n## Functions\n\n```go\nfunc BashDeclareStmt(d *DeclareDeclType) string\n```\n\n```go\nfunc DecodeZshMapForDiff(barr []byte) (map[string][]byte, error)\n```\n\n```go\nfunc DetectLocalShellType() string\n```\n\n```go\nfunc EncodeZshMap(m ZshMap) []byte\n```\n\n```go\nfunc EncodeZshMapForApply(m map[string][]byte) string\n```\n\n```go\nfunc GetBashShellState(ctx context.Context, outCh chan ShellStateOutput, stdinDataCh chan []byte)\n```\n\n```go\nfunc GetBashShellStateCmd(fdNum int) (string, []byte)\n```\n\n```go\nfunc GetBashShellStateRedirectCommandStr(outputFdNum int) (string, []byte)\n```\n\n```go\nfunc GetLocalBashMajorVersion() string\n```\n\n```go\nfunc GetLocalBashPath() string\n```\n\n```go\nfunc GetLocalZshMajorVersion() string\n```\n\n```go\nfunc GetLocalZshPath() string\n```\n\n```go\nfunc GetMacUserShell() string\n```\n\n```go\nfunc GetParserConfig(envMap map[string]string) *expand.Config\n```\n\n```go\nfunc GetZshShellStateCmd(fdNum int) (string, []byte)\n```\nreturns (cmd-string, endbytes)\n\n```go\nfunc HasShell(shellType string) bool\n```\n\n```go\nfunc MakeBashExitTrap(fdNum int) (string, []byte)\n```\n\n```go\nfunc MakeBashShExecCommand(cmdStr string, rcFileName string, usePty bool) *exec.Cmd\n```\n\n```go\nfunc MakeZshExitTrap(fdNum int) (string, []byte)\n```\n\n```go\nfunc ParseZshFunctions(fpathArr []string, fnBytes []byte, partSeparator []byte) map[ZshParamKey]string\n```\n\n```go\nfunc RunSimpleCmdInPty(ecmd *exec.Cmd, endBytes []byte) ([]byte, error)\n```\n\n```go\nfunc StreamCommandWithExtraFd(ctx context.Context, ecmd *exec.Cmd, outputCh chan []byte, extraFdNum int, endBytes []byte, stdinDataCh chan []byte) ([]byte, error)\n```\nreturns output(stdout+stderr), extraFdOutput, error\n\n## Types\n\n```go\ntype DeclareDeclType = shellenv.DeclareDeclType\n```\n\n```go\ntype RunCommandOpts struct {\n\tSudo              bool\n\tSudoWithPass      bool\n\tMaxFdNum          int // needed for Sudo\n\tCommandFdNum      int // needed for Sudo\n\tPwFdNum           int // needed for SudoWithPass\n\tCommandStdinFdNum int // needed for SudoWithPass\n}\n```\n\n```go\ntype ShellApi interface {\n\tGetShellType() string\n\tMakeExitTrap(fdNum int) (string, []byte)\n\tValidateCommandSyntax(cmdStr string) error\n\tGetLocalMajorVersion() string\n\tGetLocalShellPath() string\n\tGetRemoteShellPath() string\n\tMakeRunCommand(cmdStr string, opts RunCommandOpts) string\n\tMakeShExecCommand(cmdStr string, rcFileName string, usePty bool) *exec.Cmd\n\tGetShellState(ctx context.Context, outCh chan ShellStateOutput, stdinDataCh chan []byte)\n\tGetBaseShellOpts() string\n\tParseShellStateOutput(output []byte) (*packet.ShellState, *packet.ShellStateStats, error)\n\tMakeRcFileStr(pk *packet.RunPacketType) string\n\tMakeShellStateDiff(oldState *packet.ShellState, oldStateHash string, newState *packet.ShellState) (*packet.ShellStateDiff, error)\n\tApplyShellStateDiff(oldState *packet.ShellState, diff *packet.ShellStateDiff) (*packet.ShellState, error)\n}\n```\n\n```go\nfunc MakeShellApi(shellType string) (ShellApi, error)\n```\n\n```go\ntype ShellStateOutput struct {\n\tOutput     []byte\n\tShellState *packet.ShellState\n\tStats      *packet.ShellStateStats\n\tError      string\n}\n```\n\n```go\ntype ZshMap = map[ZshParamKey]string\n```\n\n```go\nfunc DecodeZshMap(barr []byte) (ZshMap, error)\n```\n\n```go\ntype ZshParamKey struct {\n\t// paramtype cannot contain spaces\n\t// \"aliases\", \"dis_aliases\", \"saliases\", \"dis_saliases\", \"galiases\", \"dis_galiases\"\n\t// \"functions\", \"dis_functions\", \"functions_source\", \"dis_functions_source\"\n\tParamType string\n\tParamName string\n}\n```\n\n```go\nfunc ZshParamKeyFromString(s string) (ZshParamKey, error)\n```\n\n```go\nfunc (k ZshParamKey) String() string\n```\n\n","path":"github.com/wavetermdev/waveterm/waveshell/pkg/shellapi","name":"shellapi","synopsis":"","isRedistributable":true}
