excluded dirs
This commit is contained in:
BIN
bin/nwg-drawer
BIN
bin/nwg-drawer
Binary file not shown.
13
main.go
13
main.go
@@ -30,6 +30,7 @@ var (
|
|||||||
pinned []string
|
pinned []string
|
||||||
id2entry map[string]desktopEntry
|
id2entry map[string]desktopEntry
|
||||||
preferredApps map[string]interface{}
|
preferredApps map[string]interface{}
|
||||||
|
exclusions []string
|
||||||
)
|
)
|
||||||
|
|
||||||
var categoryNames = [...]string{
|
var categoryNames = [...]string{
|
||||||
@@ -264,11 +265,21 @@ func main() {
|
|||||||
paFile := filepath.Join(configDirectory, "preferred-apps.json")
|
paFile := filepath.Join(configDirectory, "preferred-apps.json")
|
||||||
preferredApps, err = loadPreferredApps(paFile)
|
preferredApps, err = loadPreferredApps(paFile)
|
||||||
if err != nil {
|
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 {
|
} else {
|
||||||
log.Infof("Found %v associations in %s", len(preferredApps), paFile)
|
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
|
// USER INTERFACE
|
||||||
gtk.Init(nil)
|
gtk.Init(nil)
|
||||||
|
|
||||||
|
|||||||
2
tools.go
2
tools.go
@@ -465,7 +465,7 @@ func loadTextFile(path string) ([]string, error) {
|
|||||||
var output []string
|
var output []string
|
||||||
for _, line := range lines {
|
for _, line := range lines {
|
||||||
line = strings.TrimSpace(line)
|
line = strings.TrimSpace(line)
|
||||||
if line != "" {
|
if line != "" && !strings.HasPrefix(line, "#") {
|
||||||
output = append(output, line)
|
output = append(output, line)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -291,6 +291,7 @@ func walk(path string, d fs.DirEntry, e error) error {
|
|||||||
if e != nil {
|
if e != nil {
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
|
if !isExcluded(path) {
|
||||||
// don't search leading part of the path, as e.g. '/home/user/Pictures'
|
// don't search leading part of the path, as e.g. '/home/user/Pictures'
|
||||||
toSearch := strings.Split(path, ignore)[1]
|
toSearch := strings.Split(path, ignore)[1]
|
||||||
if strings.Contains(strings.ToLower(toSearch), strings.ToLower(phrase)) {
|
if strings.Contains(strings.ToLower(toSearch), strings.ToLower(phrase)) {
|
||||||
@@ -301,6 +302,8 @@ func walk(path string, d fs.DirEntry, e error) error {
|
|||||||
fileSearchResults = append(fileSearchResults, path)
|
fileSearchResults = append(fileSearchResults, path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -388,6 +391,15 @@ func setUpSearchEntry() *gtk.SearchEntry {
|
|||||||
return 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) {
|
func searchUserDir(dir string) {
|
||||||
fileSearchResults = nil
|
fileSearchResults = nil
|
||||||
ignore = userDirsMap[dir]
|
ignore = userDirsMap[dir]
|
||||||
|
|||||||
Reference in New Issue
Block a user