Skip to content

Commit

Permalink
Use setenv in vim to allow non alphanumeric vars (#901)
Browse files Browse the repository at this point in the history
ref: `:h setenv()` https://vimhelp.org/builtin.txt.html#setenv%28%29

Of note, the `:h expr-env` documentation says

> The functions getenv() and setenv() can also be used and work for
> environment variables with non-alphanumeric names.
> The function environ() can be used to get a Dict with all environment
> variables.
  • Loading branch information
Jared Weakly committed Apr 14, 2022
1 parent c965ba0 commit 9d9cd5b
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions internal/cmd/shell_vim.go
Expand Up @@ -33,16 +33,16 @@ func (sh vim) Dump(env Env) (out string) {
}

func (sh vim) export(key, value string) string {
return "let $" + sh.escapeKey(key) + " = " + sh.escapeValue(value) + "\n"
return "call setenv(" + sh.escapeKey(key) + "," + sh.escapeValue(value) + ")\n"
}

func (sh vim) unset(key string) string {
return "let $" + sh.escapeKey(key) + " = ''\n"
return "call setenv(" + sh.escapeKey(key) + ",v:null)\n"
}

// TODO: support keys with special chars or fail
func (sh vim) escapeKey(str string) string {
return str
return sh.escapeValue(str)
}

// TODO: Make sure this escaping is valid
Expand Down

0 comments on commit 9d9cd5b

Please sign in to comment.