@@ -0,0 +1,43 @@
9+// SearchParent searches for a target file or directory starting from dir
10+// and walking up the directory tree until found or root or home is reached.
11+// Returns the full path to the target if found, empty string and false otherwise.
12+// The search includes the starting directory itself.
13+func SearchParent(dir, target string) (string, bool) {
14+ absDir, err := filepath.Abs(dir)
19+ path := filepath.Join(absDir, target)
20+ if _, err := os.Stat(path); err == nil {
22+ } else if !errors.Is(err, os.ErrNotExist) {
26+ previousParent := absDir
29+ parent := filepath.Dir(previousParent)
30+ if parent == previousParent || parent == HomeDir() {
34+ path := filepath.Join(parent, target)
35+ if _, err := os.Stat(path); err == nil {
37+ } else if !errors.Is(err, os.ErrNotExist) {
41+ previousParent = parent