mirror of
https://github.com/expo/direnv.git
synced 2026-11-15 17:31:31 -10:00
The Hook function can now return an error for when it's unsupported The Export function now takes a ShellExport object. This will allow for more complex serialization formats. Only Shell interface functions are public
44 lines
866 B
Go
44 lines
866 B
Go
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) + "'"
|
|
}
|