diff --git a/bin/nwg-drawer b/bin/nwg-drawer index 47ffd6b..eb980d5 100755 Binary files a/bin/nwg-drawer and b/bin/nwg-drawer differ diff --git a/main.go b/main.go index e5d0dec..7c47e5a 100644 --- a/main.go +++ b/main.go @@ -262,7 +262,7 @@ func main() { // For opening files we use xdg-open. As its configuration is PITA, we may override some associations // in the ~/.config/nwg-panel/preferred-apps.json file. - paFile := filepath.Join(configDirectory, "preferred-apps.json") + paFile := path.Join(configDirectory, "preferred-apps.json") preferredApps, err = loadPreferredApps(paFile) if err != nil { log.Infof("Custom associations file %s not found or invalid", paFile) @@ -271,13 +271,12 @@ func main() { } // Load user-defined paths excluded from file search - exFile := filepath.Join(configDirectory, "excluded-dirs") + exFile := path.Join(configDirectory, "excluded-dirs") exclusions, err = loadTextFile(exFile) if err != nil { log.Infof("Search exclusions file %s not found %s", exFile, err) } else { log.Infof("Found %v search exclusions in %s", len(exclusions), exFile) - log.Info(exclusions) } // USER INTERFACE diff --git a/tools.go b/tools.go index 7905315..2ef5a44 100644 --- a/tools.go +++ b/tools.go @@ -154,18 +154,23 @@ func oldConfigDir() (string, error) { if os.Getenv("XDG_CONFIG_HOME") != "" { dir := path.Join(os.Getenv("XDG_CONFIG_HOME"), "nwg-panel") return dir, nil + } else if os.Getenv("HOME") != "" { + dir := path.Join(os.Getenv("HOME"), ".config/nwg-panel") + return dir, nil } return "", errors.New("old config dir not found") } func configDir() string { - var home string - home = os.Getenv("XDG_CONFIG_HOME") - if home == "" { - home = os.Getenv("HOME") + var dir string + if os.Getenv("XDG_CONFIG_HOME") != "" { + dir = path.Join(os.Getenv("XDG_CONFIG_HOME"), "nwg-drawer") + } else if os.Getenv("HOME") != "" { + dir = path.Join(os.Getenv("HOME"), ".config/nwg-drawer") } - dir := path.Join(home, ".config/nwg-drawer") + + log.Infof("Config dir: %s", dir) createDir(dir) return dir diff --git a/uicomponents.go b/uicomponents.go index 9376b78..a741858 100644 --- a/uicomponents.go +++ b/uicomponents.go @@ -291,16 +291,26 @@ func walk(path string, d fs.DirEntry, e error) error { if e != nil { return e } - 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) - } + // don't search leading part of the path, as e.g. '/home/user/Pictures' + toSearch := strings.Split(path, ignore)[1] + + // Remaing part of the path (w/o file name) must be checked against being present in excluded dirs + doSearch := true + parts := strings.Split(toSearch, "/") + remainingPart := "" + if len(parts) > 1 { + remainingPart = strings.Join(parts[:len(parts)-1], "/") + } + if remainingPart != "" && isExcluded(remainingPart) { + doSearch = false + } + + if doSearch && 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) } } @@ -412,8 +422,11 @@ func searchUserDir(dir string) { for _, path := range fileSearchResults { partOfPathToShow := strings.Split(path, userDirsMap[dir])[1] if partOfPathToShow != "" { - btn := setUpUserFileSearchResultButton(partOfPathToShow, path) - fileSearchResultFlowBox.Add(btn) + if !(strings.HasPrefix(path, "#is_dir#") && isExcluded(path)) { + btn := setUpUserFileSearchResultButton(partOfPathToShow, path) + fileSearchResultFlowBox.Add(btn) + } + } } fileSearchResultFlowBox.Hide()