forked from mah0x211/lenv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
path.go
54 lines (48 loc) · 1.11 KB
/
path.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package main
import (
"path/filepath"
"strconv"
"strings"
)
func cmdPath() {
printf(`
#
# please add the following lenv settings to your environment
#
`)
for _, name := range []string{"PATH", "LUA_PATH", "LUA_CPATH"} {
var (
format string
value string
)
switch name {
case "PATH":
format = `export %s="%s"`
value = strings.Join([]string{
filepath.Clean(CurrentDir + "/bin"),
filepath.Clean(CurrentDir + "/lua_modules/bin"),
"$PATH",
}, ":")
case "LUA_PATH":
format = `export %s="%s;"`
prefix := filepath.Clean(CurrentDir+"/lua_modules/lualib") + "/"
paths := []string{}
for i := 0; i <= 10; i++ {
dir := prefix + strconv.Itoa(i)
paths = append(paths, dir+"/?.lua", dir+"/?/init.lua")
}
value = strings.Join(paths, ";")
case "LUA_CPATH":
format = `export %s="%s;"`
prefix := filepath.Clean(CurrentDir+"/lua_modules/luaclib") + "/"
paths := []string{}
for i := 0; i <= 10; i++ {
dir := prefix + strconv.Itoa(i)
paths = append(paths, dir+"/?.so")
}
value = strings.Join(paths, ";")
}
printf(format, name, value)
}
printf("")
}