github.com/delicb/asdf-exec@v0.1.3-0.20220111003559-af5f44250ab7/utils.go (about)

     1  package main
     2  
     3  import (
     4  	"path"
     5  	"strings"
     6  )
     7  
     8  // ReadLines reads all the lines in a given file
     9  // removing spaces and comments which are marked by '#'
    10  func ReadLines(content string) (lines []string) {
    11  	for _, line := range strings.Split(content, "\n") {
    12  		line = strings.SplitN(line, "#", 2)[0]
    13  		line = strings.TrimSpace(line)
    14  		if len(line) > 0 {
    15  			lines = append(lines, line)
    16  		}
    17  	}
    18  	return
    19  }
    20  
    21  // RemoveAsdfPath returns the PATH without asdf shims path
    22  func RemoveAsdfPath(currentPath string) string {
    23  	paths := strings.Split(currentPath, ":")
    24  	asdfShimPath := path.Join(GetAsdfDataPath(), "shims")
    25  	var newPaths []string
    26  	for _, fspath := range paths {
    27  		if fspath != asdfShimPath {
    28  			newPaths = append(newPaths, fspath)
    29  		}
    30  	}
    31  	return strings.Join(newPaths, ":")
    32  }