From 77f9c3fdd0b9e75b7c073a1b43826d9c6e9d6996 Mon Sep 17 00:00:00 2001 From: Christopher Allen Lane Date: Mon, 8 Aug 2022 19:17:59 -0400 Subject: [PATCH] fix(Sheets): cheatsheets in hidden directories (#690) Fix an issue whereby cheatsheets that were contained within hidden directories were prevented from being loaded. --- internal/sheets/load.go | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/internal/sheets/load.go b/internal/sheets/load.go index 0d88c24..4442b3e 100644 --- a/internal/sheets/load.go +++ b/internal/sheets/load.go @@ -49,17 +49,18 @@ func Load(cheatpaths []cp.Cheatpath) ([]map[string]sheet.Sheet, error) { string(os.PathSeparator), ) - // ignore hidden files and directories. Otherwise, we'll likely load - // .git/* and .DS_Store. + // Don't walk the `.git` directory. Doing so creates + // hundreds/thousands of needless syscalls and could + // potentially harm performance on machines with slow disks. // - // NB: this is still somewhat brittle in that it will miss files - // contained within hidden directories in the middle of a path, though - // that should not realistically occur. - if strings.HasPrefix(title, ".") || strings.HasPrefix(info.Name(), ".") { - // Do not walk hidden directories. This is important, - // because it's common for cheatsheets to be stored in - // version-control, and a `.git` directory can easily - // contain thousands of files. + // NB: We _do_ want to walk hidden directories, however, so we + // should not constrain this further (perhaps to include all + // hidden directories). In the wild, many users appear to store + // cheatsheets in a `.config` directory (seemingly a default + // behavior of `brew`), and `cheat` explicitly supports a + // local `.cheat` directory. Constraining further here will + // break those use-cases - and has done so in the past! + if strings.Contains(path, ".git") { return fs.SkipDir }