Anonymous avatar Anonymous committed 11a5e47

using _2IGNORE env var to skip certain dirs; also skip missing directories

Comments (0)

Files changed (1)

 	"io"
 	"os"
 	"path/filepath"
+	"sort"
 	"strings"
 )
 
 
 // a storage for all known (visited at least once) directories
 type Paths struct {
-	Dirs []string
+	Dirs    []string
+	Ignored []string
 }
 
 // load paths list
 func LoadPaths() (p *Paths) {
-	home := os.Getenv("HOME")
-
 	p = new(Paths)
 	p.Dirs = make([]string, 0)
+	p.Ignored = make([]string, 0)
+
+	home := os.Getenv("HOME")
+	ignored := os.Getenv("_2IGNORE")
+
+	if len(ignored) > 0 {
+		p.Ignored = strings.Split(ignored, ":")
+		sort.Sort(sort.StringSlice(p.Ignored))
+	}
 
 	f, err := os.Open(filepath.Join(home, PATHS_FILENAME))
 	if err != nil {
 		return ""
 	}
 	for _, path := range p.Dirs {
+		skip := false
+
+		for _, ignored := range p.Ignored {
+			if len(ignored) > 0 && ignored[len(ignored)-1] == '*' {
+				if strings.HasPrefix(path, ignored[0:len(ignored)-1]) {
+					skip = true
+					break
+				}
+			} else if ignored == path {
+				skip = true
+				break
+			}
+		}
+
+		if skip {
+			continue
+		}
+
+		if _, err := os.Stat(path); err != nil && os.IsNotExist(err) {
+			continue // skip non-existing paths
+		}
 		w := 0
 		hintIndex := len(hints)
 		for i := len(path) - 1; i >= 0; i-- {
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.