Exemple #1
0
func mustGetHome(uname string) string {
	dir, err := osutil.GetHome(uname)
	if err != nil {
		throw(err)
	}
	return dir
}
Exemple #2
0
// EnsureDataDir ensures Elvish's data directory exists, creating it if
// necessary. It returns the path to the data directory (never with a
// trailing slash) and possible error.
func EnsureDataDir() (string, error) {
	home, err := osutil.GetHome("")
	if err != nil {
		return "", err
	}
	ddir := home + "/.elvish"
	return ddir, os.MkdirAll(ddir, 0700)
}
Exemple #3
0
func simpleCompound(pn *parse.Primary) (*parse.Compound, string) {
	thisIndexing, ok := pn.Parent().(*parse.Indexing)
	if !ok {
		return nil, ""
	}

	thisCompound, ok := thisIndexing.Parent().(*parse.Compound)
	if !ok {
		return nil, ""
	}

	tilde := false
	head := ""
	for _, in := range thisCompound.Indexings {
		if len(in.Indicies) > 0 {
			return nil, ""
		}
		switch in.Head.Type {
		case parse.Tilde:
			tilde = true
		case parse.Bareword, parse.SingleQuoted, parse.DoubleQuoted:
			head += in.Head.Value
		}

		if in == thisIndexing {
			break
		}
	}
	if tilde {
		i := strings.Index(head, "/")
		if i == -1 {
			return nil, ""
		}
		uname := head[:i]
		home, err := osutil.GetHome(uname)
		if err != nil {
			// TODO report error
			return nil, ""
		}
		head = home + head[i:]
	}
	return thisCompound, head
}