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

     1  //go:build plan9
     2  // +build plan9
     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) ||
    15  		strings.HasPrefix(s, "."+consts.PathSlash) ||
    16  		strings.HasPrefix(s, ".."+consts.PathSlash)
    17  }
    18  
    19  func matchDirsOnce(s string) (items []string) {
    20  	//s = variables.ExpandString(s)
    21  	path, partial := partialPath(s)
    22  
    23  	var dirs []string
    24  
    25  	files, _ := ioutil.ReadDir(path)
    26  	for _, f := range files {
    27  		if f.IsDir() && (f.Name()[0] != '.' ||
    28  			(len(partial) > 0 && partial[0] == '.')) {
    29  			dirs = append(dirs, f.Name()+consts.PathSlash)
    30  			continue
    31  		}
    32  
    33  		// TODO: There is a log of logic missing in here that appears in the unix source
    34  	}
    35  
    36  	if path != consts.PathSlash {
    37  		dirs = append(dirs, ".."+consts.PathSlash)
    38  	}
    39  
    40  	for i := range dirs {
    41  		if strings.HasPrefix(dirs[i], partial) {
    42  			items = append(items, dirs[i][len(partial):])
    43  		}
    44  	}
    45  
    46  	return
    47  }