-
Notifications
You must be signed in to change notification settings - Fork 0
/
rgRunner.go
35 lines (30 loc) · 815 Bytes
/
rgRunner.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package fze
import (
"fmt"
"os/exec"
"strings"
)
func rgRunner(args []string, opts RunnerOptions) error {
// Get the output from rg
cmd := "rg -n " + fixArgs(args)
res, err := exec.Command("bash", "-c", cmd).Output()
if err != nil {
return fmt.Errorf("running rg: %v", err)
}
// Run the output from rg through fzf
outLines, err := runFzf(res, opts)
if err != nil {
return fmt.Errorf("runFzf: %v", err)
}
var paths []pathArg
for _, line := range outLines {
// Get the filename and linenumber from the output
output := strings.Split(line, ":")
if len(output) < 2 {
return fmt.Errorf("expecting a path and a line-number in this rg output: %s", output)
}
paths = append(paths, pathArg{path: output[0], lineNumber: output[1]})
}
// Run emacsclient
return openEditor(paths, opts)
}