Skip to content

Commit 4224ef9

Browse files
authored
feat: output relative paths in search results (#23)
1 parent decd3cb commit 4224ef9

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

cmd/grepturbo/main.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ package main
3030
import (
3131
"fmt"
3232
"os"
33+
"path/filepath"
3334

3435
"github.com/spf13/cobra"
3536

@@ -198,8 +199,13 @@ func runSearch(idxDir, pattern string) error {
198199
os.Exit(1) // grep convention: exit 1 when no matches
199200
}
200201

202+
root := r.Meta.RootDir
201203
for _, m := range matches {
202-
fmt.Printf("%s:%d:%s\n", m.File, m.Line, m.Text)
204+
rel, err := filepath.Rel(root, m.File)
205+
if err != nil {
206+
rel = m.File
207+
}
208+
fmt.Printf("%s:%d:%s\n", rel, m.Line, m.Text)
203209
}
204210
return nil
205211
}

0 commit comments

Comments
 (0)