forked from direnv/direnv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshell_elvish.go
55 lines (48 loc) · 886 Bytes
/
shell_elvish.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
55
package main
import (
"bytes"
"encoding/json"
)
type elvish struct{}
// Elvish add support for the elvish shell
var Elvish Shell = elvish{}
func (elvish) Hook() (string, error) {
return `## hook for direnv
@edit:before-readline = $@edit:before-readline {
try {
m = [("{{.SelfPath}}" export elvish | from-json)]
if (> (count $m) 0) {
m = (explode $m)
keys $m | each [k]{
if $m[$k] {
set-env $k $m[$k]
} else {
unset-env $k
}
}
}
} except e {
echo $e
}
}
`, nil
}
func (sh elvish) Export(e ShellExport) string {
buf := new(bytes.Buffer)
err := json.NewEncoder(buf).Encode(e)
if err != nil {
panic(err)
}
return buf.String()
}
func (sh elvish) Dump(env Env) (out string) {
buf := new(bytes.Buffer)
err := json.NewEncoder(buf).Encode(env)
if err != nil {
panic(err)
}
return buf.String()
}
var (
_ Shell = (*elvish)(nil)
)