diff --git a/bin/nwg-drawer b/bin/nwg-drawer index 27e13dc..aa0bb03 100755 Binary files a/bin/nwg-drawer and b/bin/nwg-drawer differ diff --git a/main.go b/main.go index 0914edb..4bf3852 100644 --- a/main.go +++ b/main.go @@ -30,6 +30,7 @@ var ( pinned []string id2entry map[string]desktopEntry preferredApps map[string]interface{} + exclusions []string ) var categoryNames = [...]string{ @@ -264,11 +265,21 @@ func main() { paFile := filepath.Join(configDirectory, "preferred-apps.json") preferredApps, err = loadPreferredApps(paFile) if err != nil { - log.Errorf("Custom associations file %s not found or invalid", paFile) + log.Infof("Custom associations file %s not found or invalid", paFile) } else { log.Infof("Found %v associations in %s", len(preferredApps), paFile) } + // Load user-defined paths excluded from file search + exFile := filepath.Join(configDirectory, "excluded-dirs") + exclusions, err = loadTextFile(exFile) + if err != nil { + log.Infof("Search exclusions file %s not found", exFile) + } else { + log.Infof("Found %v search exclusions in %s", len(exclusions), exFile) + fmt.Println(exclusions) + } + // USER INTERFACE gtk.Init(nil) diff --git a/tools.go b/tools.go index f9bb790..3a3ca42 100644 --- a/tools.go +++ b/tools.go @@ -465,7 +465,7 @@ func loadTextFile(path string) ([]string, error) { var output []string for _, line := range lines { line = strings.TrimSpace(line) - if line != "" { + if line != "" && !strings.HasPrefix(line, "#") { output = append(output, line) } diff --git a/uicomponents.go b/uicomponents.go index 08946d9..9376b78 100644 --- a/uicomponents.go +++ b/uicomponents.go @@ -291,16 +291,19 @@ func walk(path string, d fs.DirEntry, e error) error { if e != nil { return e } - // don't search leading part of the path, as e.g. '/home/user/Pictures' - toSearch := strings.Split(path, ignore)[1] - if strings.Contains(strings.ToLower(toSearch), strings.ToLower(phrase)) { - // mark directories - if d.IsDir() { - fileSearchResults = append(fileSearchResults, fmt.Sprintf("#is_dir#%s", path)) - } else { - fileSearchResults = append(fileSearchResults, path) + if !isExcluded(path) { + // don't search leading part of the path, as e.g. '/home/user/Pictures' + toSearch := strings.Split(path, ignore)[1] + if strings.Contains(strings.ToLower(toSearch), strings.ToLower(phrase)) { + // mark directories + if d.IsDir() { + fileSearchResults = append(fileSearchResults, fmt.Sprintf("#is_dir#%s", path)) + } else { + fileSearchResults = append(fileSearchResults, path) + } } } + return nil } @@ -388,6 +391,15 @@ func setUpSearchEntry() *gtk.SearchEntry { return searchEntry } +func isExcluded(dir string) bool { + for _, exclusion := range exclusions { + if strings.Contains(dir, exclusion) { + return true + } + } + return false +} + func searchUserDir(dir string) { fileSearchResults = nil ignore = userDirsMap[dir]