diff --git a/Dockerfile b/Dockerfile index 145097803..c78bd3706 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,13 @@ -FROM golang:1.18-alpine as builder -RUN apk update && \ - apk add --virtual build-deps make git +FROM golang:1.20-alpine as builder +RUN apk add --no-cache --virtual build-deps make git # Build Elvish COPY . /go/src/src.elv.sh RUN make -C /go/src/src.elv.sh get -FROM alpine:3.13 -COPY --from=builder /go/bin/elvish /bin/elvish +FROM alpine:3.18 RUN adduser -D elf -RUN apk update && apk add tmux mandoc man-pages vim curl git +RUN apk update && apk add tmux mandoc man-pages vim curl sqlite git +COPY --from=builder /go/bin/elvish /bin/elvish USER elf WORKDIR /home/elf CMD ["/bin/elvish"] diff --git a/pkg/eval/builtin_fn_str.go b/pkg/eval/builtin_fn_str.go index a97179507..13c2572db 100644 --- a/pkg/eval/builtin_fn_str.go +++ b/pkg/eval/builtin_fn_str.go @@ -67,11 +67,29 @@ func base(fm *Frame, b int, nums ...int) error { return nil } -var eawkWordSep = regexp.MustCompile("[ \t]+") +type eawkOpt struct { + Sep string + Posix bool +} + +func (o *eawkOpt) SetDefaultOptions() { + o.Posix = false + o.Sep = "[ \t]+" +} -func eawk(fm *Frame, f Callable, inputs Inputs) error { +func eawk(fm *Frame, opts eawkOpt, f Callable, inputs Inputs) error { broken := false + var eawkWordSep *regexp.Regexp var err error + if opts.Posix { + eawkWordSep, err = regexp.CompilePOSIX(opts.Sep) + } else { + eawkWordSep, err = regexp.Compile(opts.Sep) + } + if err != nil { + return err + } + inputs(func(v any) { if broken { return diff --git a/pkg/eval/builtin_fn_str_test.go b/pkg/eval/builtin_fn_str_test.go index 168dc4823..8bd36c2d1 100644 --- a/pkg/eval/builtin_fn_str_test.go +++ b/pkg/eval/builtin_fn_str_test.go @@ -87,5 +87,17 @@ func TestEawk(t *testing.T) { } } `).Puts("a", "c", "e"), + // Parsing docker image ls output with custom separator: + That(` + to-lines [ + 'REPOSITORY TAG IMAGE ID CREATED SIZE' + ' 265c2d25a944 16 minutes ago 67.5 MB' + ' 26408a88b236 16 minutes ago 389 MB' + 'localhost/elvish_eawk latest 0570db4e3eaa 32 hours ago 67.5 MB' + 'localhost/elvish latest 59b1eec93ab7 33 hours ago 67.5 MB' + 'docker.io/library/golang latest 015e6b7f599b 46 hours ago 838 MB' + 'docker.io/library/golang 1.20-alpine 93db368a0a9e 3 days ago 266 MB' + ] | eawk &sep=" [ ]+" {|0 1 2 3 4 5| put $5 } + `).Puts("SIZE", "67.5 MB", "389 MB", "67.5 MB", "67.5 MB", "838 MB", "266 MB"), ) }