forked from direnv/direnv
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathshell_vim.go
43 lines (34 loc) · 866 Bytes
/
shell_vim.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
package main
import (
"errors"
"strings"
)
type vim int
var VIM vim
func (x vim) Hook() (string, error) {
return "", errors.New("this feature is not supported. Install the direnv.vim plugin instead.")
}
func (x vim) Export(e ShellExport) (out string) {
for key, value := range e {
if value == nil {
out += x.unset(key)
} else {
out += x.export(key, *value)
}
}
return out
}
func (x vim) export(key, value string) string {
return "let $" + x.escapeKey(key) + " = " + x.escapeValue(value) + "\n"
}
func (x vim) unset(key string) string {
return "let $" + x.escapeKey(key) + " = ''\n"
}
// TODO: support keys with special chars or fail
func (x vim) escapeKey(str string) string {
return str
}
// TODO: Make sure this escaping is valid
func (x vim) escapeValue(str string) string {
return "'" + strings.Replace(str, "'", "''", -1) + "'"
}