mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-13 01:47:51 +08:00
Add a but: glob qualifier to exclude paths.
This commit is contained in:
parent
79350d7b9c
commit
8db13b85ec
|
@ -101,7 +101,7 @@ func cat(lhs, rhs Value) Value {
|
|||
segs := stringToSegments(string(lhs))
|
||||
// We know rhs contains exactly one segment.
|
||||
segs = append(segs, rhs.Segments[0])
|
||||
return GlobPattern{glob.Pattern{segs, ""}, rhs.Flags}
|
||||
return GlobPattern{glob.Pattern{segs, ""}, rhs.Flags, rhs.Buts}
|
||||
}
|
||||
case GlobPattern:
|
||||
// NOTE Modifies lhs in place.
|
||||
|
@ -113,6 +113,7 @@ func cat(lhs, rhs Value) Value {
|
|||
// We know rhs contains exactly one segment.
|
||||
lhs.append(rhs.Segments[0])
|
||||
lhs.Flags |= rhs.Flags
|
||||
lhs.Buts = append(lhs.Buts, rhs.Buts...)
|
||||
return lhs
|
||||
}
|
||||
}
|
||||
|
@ -260,7 +261,7 @@ func (cp *compiler) primary(n *parse.Primary) ValuesOpFunc {
|
|||
case parse.Wildcard:
|
||||
vs := []Value{GlobPattern{
|
||||
glob.Pattern{[]glob.Segment{wildcardToSegment(n.SourceText())}, ""},
|
||||
0}}
|
||||
0, nil}}
|
||||
return func(ec *EvalCtx) []Value {
|
||||
return vs
|
||||
}
|
||||
|
|
12
eval/glob.go
12
eval/glob.go
|
@ -15,6 +15,7 @@ import (
|
|||
type GlobPattern struct {
|
||||
glob.Pattern
|
||||
Flags GlobFlag
|
||||
Buts []string
|
||||
}
|
||||
|
||||
type GlobFlag uint
|
||||
|
@ -72,6 +73,8 @@ func (gp GlobPattern) Index(modifiers []Value) []Value {
|
|||
switch {
|
||||
case modifier == "nomatch-ok":
|
||||
gp.Flags |= NoMatchOK
|
||||
case strings.HasPrefix(modifier, "but:"):
|
||||
gp.Buts = append(gp.Buts, modifier[len("but:"):])
|
||||
case modifier == "match-hidden":
|
||||
lastSeg := gp.mustGetLastWildSeg()
|
||||
gp.Segments[len(gp.Segments)-1] = glob.Wild{
|
||||
|
@ -171,6 +174,11 @@ func stringToSegments(s string) []glob.Segment {
|
|||
}
|
||||
|
||||
func doGlob(gp GlobPattern, abort <-chan struct{}) []Value {
|
||||
but := make(map[string]struct{})
|
||||
for _, s := range gp.Buts {
|
||||
but[s] = struct{}{}
|
||||
}
|
||||
|
||||
vs := make([]Value, 0)
|
||||
if !gp.Glob(func(name string) bool {
|
||||
select {
|
||||
|
@ -179,7 +187,9 @@ func doGlob(gp GlobPattern, abort <-chan struct{}) []Value {
|
|||
return false
|
||||
default:
|
||||
}
|
||||
vs = append(vs, String(name))
|
||||
if _, b := but[name]; !b {
|
||||
vs = append(vs, String(name))
|
||||
}
|
||||
return true
|
||||
}) {
|
||||
throw(ErrInterrupted)
|
||||
|
|
Loading…
Reference in New Issue
Block a user