github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/shell/autocomplete/paths_windows.go (about)

     1  //go:build windows
     2  // +build windows
     3  
     4  package autocomplete
     5  
     6  import (
     7  	"io/ioutil"
     8  	"strings"
     9  
    10  	"github.com/lmorg/murex/utils/consts"
    11  )
    12  
    13  func pathIsLocal(s string) bool {
    14  	return strings.HasPrefix(s, "."+consts.PathSlash) || strings.HasPrefix(s, ".."+consts.PathSlash) || strings.HasPrefix(s, consts.PathSlash) || (len(s) > 2 && strings.HasPrefix(s[1:], ":"+consts.PathSlash))
    15  }
    16  
    17  func matchDirsOnce(s string) (items []string) {
    18  	//s = variables.ExpandString(s)
    19  	path, partial := partialPath(s)
    20  
    21  	var dirs []string
    22  
    23  	files, _ := ioutil.ReadDir(path)
    24  	for _, f := range files {
    25  		if f.IsDir() {
    26  			dirs = append(dirs, f.Name()+consts.PathSlash)
    27  		}
    28  	}
    29  
    30  	dirs = append(dirs, ".."+consts.PathSlash)
    31  
    32  	for i := range dirs {
    33  		if strings.HasPrefix(dirs[i], partial) {
    34  			items = append(items, dirs[i][len(partial):])
    35  		}
    36  	}
    37  	return
    38  }