@@ -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-
1613func (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
8178func (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+
109110func (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