Skip to content

Commit 4c0c3d0

Browse files
committed
env: use ripgrep for the grep tool
Signed-off-by: Tibor Vass <teabee89@gmail.com>
1 parent a5f70f4 commit 4c0c3d0

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

cmd/container-use/stdio.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ var stdioCmd = &cobra.Command{
3939

4040
func warmCache(ctx context.Context, dag *dagger.Client) {
4141
environment.EditUtil(dag).Sync(ctx)
42+
environment.GrepUtil(dag).Sync(ctx)
4243
}
4344

4445
func init() {

environment/filesystem.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ import (
1010
"github.com/dagger/container-use/edit"
1111
)
1212

13-
// FIXME: See hack where it's used
14-
const fileUtilsBaseImage = "busybox"
15-
1613
func (env *Environment) FileRead(ctx context.Context, targetFile string, shouldReadEntireFile bool, startLineOneIndexed int, endLineOneIndexedInclusive int) (string, error) {
1714
file, err := env.container().File(targetFile).Contents(ctx)
1815
if err != nil {
@@ -80,10 +77,10 @@ func (env *Environment) ls(ctx context.Context, path string, filter dagger.Direc
8077

8178
func (env *Environment) FileGrep(ctx context.Context, path, pattern, include string) (string, error) {
8279
// Hack: use busybox to run `sed` since dagger doesn't have native file editing primitives.
83-
args := []string{"/bin/grep", "-E", "--", pattern, include}
80+
args := []string{"/usr/bin/rg", "--no-unicode", "-g", include, "--", pattern, path}
8481

85-
dir := env.container().Rootfs().Directory(path)
86-
out, err := dag.Container().From(fileUtilsBaseImage).WithMountedDirectory("/mnt", dir).WithWorkdir("/mnt").WithExec(args).Stdout(ctx)
82+
dir := env.container().Directory(path)
83+
out, err := GrepUtil(env.dag).WithMountedDirectory("/mnt", dir).WithWorkdir("/mnt").WithExec(args).Stdout(ctx)
8784
if err != nil {
8885
return "", err
8986
}
@@ -106,6 +103,10 @@ func EditUtil(dag *dagger.Client) *dagger.Container {
106103
return dag.Container().From("scratch").WithFile("/edit", editBin).WithEntrypoint([]string{"/edit"})
107104
}
108105

106+
func GrepUtil(dag *dagger.Client) *dagger.Container {
107+
return dag.Container().From(alpineImage).WithExec([]string{"apk", "add", "-U", "ripgrep"})
108+
}
109+
109110
func (env *Environment) FileEdit(ctx context.Context, targetFile string, edits []FileEdit) error {
110111
// Hack: use busybox to run `sed` since dagger doesn't have native file editing primitives.
111112
args := []string{"/edit", "/target", "/new"}

0 commit comments

Comments
 (0)