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)
| 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. |
| 145 | func 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 |
no test coverage detected