MCPcopy Create free account
hub / github.com/Facets-cloud/flow / buildScript

Function buildScript

internal/warp/warp.go:145–171  ·  view source on GitHub ↗

buildScript produces the bash script body that the keystroked `bash ` line invokes. Shape: #!/bin/bash rm -- "$0" printf '\033]2;%s\007' ' ' cd ' ' || exit 1 exec env FOO='bar' BAZ='qux' Notes: - Env vars are sorted alphabetically for stable test output, matching the

(title, cwd, command string, envVars map[string]string)

Source from the content-addressed store, hash-verified

143// no `env` wrapper, so the command process isn't a child of env.
144// - When title is empty, the OSC 2 line is omitted.
145func buildScript(title, cwd, command string, envVars map[string]string) string {
146 var b strings.Builder
147 b.WriteString("#!/bin/bash\n")
148 b.WriteString(`rm -- "$0"`)
149 b.WriteString("\n")
150 if title != "" {
151 fmt.Fprintf(&b, "printf '\\033]2;%%s\\007' %s\n", ShellQuote(title))
152 }
153 fmt.Fprintf(&b, "cd %s || exit 1\n", ShellQuote(cwd))
154
155 if len(envVars) == 0 {
156 fmt.Fprintf(&b, "exec %s\n", command)
157 return b.String()
158 }
159
160 keys := make([]string, 0, len(envVars))
161 for k := range envVars {
162 keys = append(keys, k)
163 }
164 sort.Strings(keys)
165 parts := make([]string, 0, len(envVars))
166 for _, k := range keys {
167 parts = append(parts, fmt.Sprintf("%s=%s", k, ShellQuote(envVars[k])))
168 }
169 fmt.Fprintf(&b, "exec env %s %s\n", strings.Join(parts, " "), command)
170 return b.String()
171}
172
173// buildAppleScript activates Warp, waits for the new tab from
174// `open warp://...` to take key focus, then keystrokes

Callers 1

SpawnTabFunction · 0.85

Calls 2

StringMethod · 0.80
ShellQuoteFunction · 0.70

Tested by

no test coverage detected