mirror of
https://github.com/expo/direnv.git
synced 2026-11-15 17:31:31 -10:00
This format can be useful for IDEs.
The JSON format is of `{ key: value }` where the value can either be a
string or null. If the value is null it needs to be removed from the
environment.
50 lines
698 B
Go
50 lines
698 B
Go
package main
|
|
|
|
import (
|
|
"path/filepath"
|
|
)
|
|
|
|
/*
|
|
* Shells
|
|
*/
|
|
type Shell interface {
|
|
Hook() (string, error)
|
|
Export(e ShellExport) string
|
|
}
|
|
|
|
// Used to describe what to generate for the shell
|
|
type ShellExport map[string]*string
|
|
|
|
func (e ShellExport) Add(key, value string) {
|
|
e[key] = &value
|
|
}
|
|
|
|
func (e ShellExport) Remove(key string) {
|
|
e[key] = nil
|
|
}
|
|
|
|
func DetectShell(target string) Shell {
|
|
target = filepath.Base(target)
|
|
// $0 starts with "-"
|
|
if target[0:1] == "-" {
|
|
target = target[1:]
|
|
}
|
|
|
|
switch target {
|
|
case "bash":
|
|
return BASH
|
|
case "zsh":
|
|
return ZSH
|
|
case "fish":
|
|
return FISH
|
|
case "vim":
|
|
return VIM
|
|
case "tcsh":
|
|
return TCSH
|
|
case "json":
|
|
return JSON
|
|
}
|
|
|
|
return nil
|
|
}
|