(ctx *snap.Context)
| 2163 | } |
| 2164 | |
| 2165 | func runShExec(ctx *snap.Context) error { |
| 2166 | if ctx.NArgs() != 0 { |
| 2167 | fmt.Fprintf(ctx.Stderr(), "Usage: %s shExec\n", commandName) |
| 2168 | return fmt.Errorf("expected 0 arguments, got %d", ctx.NArgs()) |
| 2169 | } |
| 2170 | |
| 2171 | homeDir, err := os.UserHomeDir() |
| 2172 | if err != nil { |
| 2173 | return reportError(ctx, fmt.Errorf("determine home directory: %w", err)) |
| 2174 | } |
| 2175 | |
| 2176 | scriptsDir := filepath.Join(homeDir, "config", "sh") |
| 2177 | scripts, err := collectShellScripts(scriptsDir) |
| 2178 | if err != nil { |
| 2179 | return reportError(ctx, err) |
| 2180 | } |
| 2181 | |
| 2182 | if len(scripts) == 0 { |
| 2183 | fmt.Fprintf(ctx.Stdout(), "No shell scripts found under %s\n", scriptsDir) |
| 2184 | return nil |
| 2185 | } |
| 2186 | |
| 2187 | idx, err := fuzzyfinder.Find( |
| 2188 | scripts, |
| 2189 | func(i int) string { |
| 2190 | return scripts[i].Relative |
| 2191 | }, |
| 2192 | fuzzyfinder.WithPromptString("shExec> "), |
| 2193 | ) |
| 2194 | if err != nil { |
| 2195 | if errors.Is(err, fuzzyfinder.ErrAbort) { |
| 2196 | return nil |
| 2197 | } |
| 2198 | return reportError(ctx, fmt.Errorf("select script: %w", err)) |
| 2199 | } |
| 2200 | |
| 2201 | selected := scripts[idx] |
| 2202 | fmt.Fprintf(ctx.Stdout(), "▶️ %s\n", selected.Relative) |
| 2203 | |
| 2204 | cmd := exec.Command(selected.Absolute) |
| 2205 | cmd.Dir = filepath.Dir(selected.Absolute) |
| 2206 | cmd.Stdout = ctx.Stdout() |
| 2207 | cmd.Stderr = ctx.Stderr() |
| 2208 | cmd.Stdin = ctx.Stdin() |
| 2209 | if err := cmd.Run(); err != nil { |
| 2210 | return reportError(ctx, fmt.Errorf("run %s: %w", selected.Relative, err)) |
| 2211 | } |
| 2212 | |
| 2213 | fmt.Fprintf(ctx.Stdout(), "✔️ Finished %s\n", selected.Relative) |
| 2214 | return nil |
| 2215 | } |
| 2216 | |
| 2217 | type scriptCandidate struct { |
| 2218 | Absolute string |
no test coverage detected