Skip to content

Commit

Permalink
allow negation
Browse files Browse the repository at this point in the history
  • Loading branch information
seanenck committed Oct 25, 2024
1 parent c8f9156 commit 21ecbe6
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions internal/dotfiles/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ func (v variables) list() ([]dotfile, error) {
if v.Dotfiles.Host != "" {
options = append(options, v.Dotfiles.Host)
}
ignores := make(map[string]struct{})
for _, opt := range options {
path := filepath.Join(v.root, opt)
if !paths.Exists(path) {
Expand All @@ -120,6 +121,10 @@ func (v variables) list() ([]dotfile, error) {
if t == "" {
continue
}
negate := strings.HasPrefix(t, "!")
if negate {
t = t[1:]
}
full := filepath.Join(v.root, t)
items := []string{full}
if strings.Contains(full, "*") {
Expand All @@ -137,6 +142,9 @@ func (v variables) list() ([]dotfile, error) {
if info.IsDir() {
return nil
}
if negate {
ignores[p] = struct{}{}
}
if _, ok := found[item]; !ok {
offset := strings.TrimPrefix(p, v.root)
found[p] = dotfile{path: p, offset: offset, info: info}
Expand All @@ -155,6 +163,9 @@ func (v variables) list() ([]dotfile, error) {
}
var results []dotfile
for _, k := range keys {
if _, ok := ignores[k]; ok {
continue
}
results = append(results, found[k])
}
return results, nil
Expand Down

0 comments on commit 21ecbe6

Please sign in to comment.