MCPcopy Create free account
hub / github.com/wavetermdev/waveterm / ShellQuote

Function ShellQuote

pkg/util/utilfn/utilfn.go:122–139  ·  view source on GitHub ↗

minimum maxlen=6, pass -1 for no max length

(val string, forceQuote bool, maxLen int)

Source from the content-addressed store, hash-verified

120
121// minimum maxlen=6, pass -1 for no max length
122func ShellQuote(val string, forceQuote bool, maxLen int) string {
123 if maxLen != -1 && maxLen < 6 {
124 maxLen = 6
125 }
126 rtn := val
127 if needsQuoteRe.MatchString(val) {
128 rtn = "'" + strings.ReplaceAll(val, "'", `'"'"'`) + "'"
129 } else if forceQuote {
130 rtn = "\"" + rtn + "\""
131 }
132 if maxLen == -1 || len(rtn) <= maxLen {
133 return rtn
134 }
135 if strings.HasPrefix(rtn, "\"") || strings.HasPrefix(rtn, "'") {
136 return rtn[0:maxLen-4] + "..." + rtn[len(rtn)-1:]
137 }
138 return rtn[0:maxLen-3] + "..."
139}
140
141func EllipsisStr(s string, maxLen int) string {
142 if maxLen < 4 {

Callers 2

createCmdStrAndOptsFunction · 0.92
FixupWaveZshHistoryFunction · 0.92

Calls

no outgoing calls

Tested by

no test coverage detected