Skip to content

Commit

Permalink
Drop unfit globstar to ignore .direnv (#256)
Browse files Browse the repository at this point in the history
* Drop unfit globstar to ignore .direnv

* `go mod tidy`
  • Loading branch information
kachick committed Aug 6, 2023
1 parent c291ad3 commit 915c035
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 40 deletions.
5 changes: 5 additions & 0 deletions _typos.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# https://github.com/crate-ci/typos/issues/536#issuecomment-1216549808
[default.extend-words]
iterm = "iterm"

[files]
extend-exclude = [
"go.mod",
]
13 changes: 2 additions & 11 deletions cmd/fmt/main.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
package main

import (
"log"
"os"

"github.com/kachick/dotfiles"
)

func main() {
wd, err := os.Getwd()
if err != nil {
log.Fatalln(err)
}
fsys := os.DirFS(wd)

bashPaths := dotfiles.MustGetAllBash(fsys)
nixPaths := dotfiles.MustGetAllNix(fsys)
bashPaths := dotfiles.MustGetAllBash()
nixPaths := dotfiles.MustGetAllNix()

// Do not cover the same files in another formatter for parallel processing
cmds := dotfiles.Commands{
Expand Down
13 changes: 2 additions & 11 deletions cmd/lint/main.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
package main

import (
"log"
"os"

"github.com/kachick/dotfiles"
)

func main() {
wd, err := os.Getwd()
if err != nil {
log.Fatalln(err)
}
fsys := os.DirFS(wd)

bashPaths := dotfiles.MustGetAllBash(fsys)
nixPaths := dotfiles.MustGetAllNix(fsys)
bashPaths := dotfiles.MustGetAllBash()
nixPaths := dotfiles.MustGetAllNix()

cmds := dotfiles.Commands{
{Path: "dprint", Args: []string{"check"}},
Expand Down
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@ module github.com/kachick/dotfiles

go 1.20

require (
github.com/bmatcuk/doublestar/v4 v4.6.0
)
require golang.org/x/exp v0.0.0-20230801115018-d63ba01acd4b
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
github.com/bmatcuk/doublestar v1.3.4 h1:gPypJ5xD31uhX6Tf54sDPUOBXTqKH4c9aPY66CyQrS0=
github.com/bmatcuk/doublestar v1.3.4/go.mod h1:wiQtGV+rzVYxB7WIlirSN++5HPtPlXEo9MEoZQC/PmE=
github.com/bmatcuk/doublestar/v4 v4.6.0 h1:HTuxyug8GyFbRkrffIpzNCSK4luc0TY3wzXvzIZhEXc=
github.com/bmatcuk/doublestar/v4 v4.6.0/go.mod h1:xBQ8jztBU6kakFMg+8WGxn0c6z1fTSPVIjEY1Wr7jzc=
golang.org/x/exp v0.0.0-20230801115018-d63ba01acd4b h1:r+vk0EmXNmekl0S0BascoeeoHk/L7wmaW2QF90K+kYI=
golang.org/x/exp v0.0.0-20230801115018-d63ba01acd4b/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc=
47 changes: 36 additions & 11 deletions path.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package dotfiles

import (
"io/fs"
"log"
"path/filepath"
"strings"

"github.com/bmatcuk/doublestar/v4"
"golang.org/x/exp/slices"
)

func GetTyposTargetedRoots() []string {
Expand All @@ -15,18 +16,42 @@ func GetTyposTargetedRoots() []string {
}
}

func MustGetAllBash(fsys fs.FS) []string {
bashPaths, err := doublestar.Glob(fsys, "./**/{*.bash,.bash*}")
if err != nil {
log.Fatalln(err)
func checkIgnoreDir(d fs.DirEntry) error {
if d.IsDir() {
if slices.Contains([]string{".git", ".direnv", "dist"}, d.Name()) {
return fs.SkipDir
}
}
return nil
}

func MustGetAllBash() []string {
bashPaths := []string{}
filepath.WalkDir(".", func(path string, d fs.DirEntry, err error) error {
if err := checkIgnoreDir(d); err != nil {
return err
}
if strings.HasSuffix(d.Name(), ".bash") {
bashPaths = append(bashPaths, path)
}
return nil
})

return bashPaths
}

func MustGetAllNix(fsys fs.FS) []string {
nixPaths, err := doublestar.Glob(fsys, "./**/*.nix")
if err != nil {
log.Fatalln(err)
}
func MustGetAllNix() []string {
nixPaths := []string{}

filepath.WalkDir(".", func(path string, d fs.DirEntry, err error) error {
if err := checkIgnoreDir(d); err != nil {
return err
}
if strings.HasSuffix(d.Name(), ".nix") {
nixPaths = append(nixPaths, path)
}
return nil
})

return nixPaths
}

0 comments on commit 915c035

Please sign in to comment.