Пример #1
0
func sh(dflt string) string {
	if dflt != "" {
		return dflt
	}
	// NB: Don't use SHELL, to leave unix alone.
	if c := app.GetEnv("shell"); c != "" {
		return c
	}
	return "rc"
}
Пример #2
0
func GetEnvAt(name, idxs string) ([]string, error) {
	s := app.GetEnv(name)
	if len(s) == 0 {
		return nil, nil
	}
	if strings.Contains(s, "\a") {
		m := envMap(s)
		if idxs == "" {
			return mapNames(m), nil
		}
		s := m[idxs]
		return []string{s}, nil
	}
	toks := strings.SplitN(s, "\b", -1)
	return idx(toks, idxs)
}
Пример #3
0
func (x *xEnv) ntype(nm string) string {
	if bltin[nm] != nil {
		return "builtin"
	}
	if x.funcs[nm] != nil {
		return "func"
	}
	if app.GetEnv(nm) != "" {
		return "env"
	}
	path := x.lookCmd(nm)
	if path != "" {
		path = ": " + path
	}
	return "external" + path
}
Пример #4
0
func SetEnvAt(name, idx string, val string) error {
	s := app.GetEnv(name)
	ismap := strings.Contains(s, "\a")
	n, err := strconv.ParseInt(idx, 10, 32)
	i := int(n)
	if err == nil && !ismap {
		toks := strings.SplitN(s, "\b", -1)
		if i == len(toks) {
			toks = append(toks, val)
		} else if i < 0 || i > len(toks) {
			return fmt.Errorf("bad index '%s' for '%s'", idx, name)
		} else {
			toks[i] = val
		}
		SetEnvList(name, toks...)
		return nil
	}
	m := envMap(name)
	m[idx] = val
	SetEnvMap(name, m)
	return nil
}
Пример #5
0
func GetEnvMap(n string) map[string]string {
	return envMap(app.GetEnv(n))
}