forked from direnv/direnv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shell.go
54 lines (46 loc) · 782 Bytes
/
shell.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
package main
import (
"path/filepath"
)
/*
* Shells
*/
type Shell interface {
Hook() (string, error)
Export(e ShellExport) string
Dump(env Env) 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 "gzenv":
return GZENV
case "vim":
return VIM
case "tcsh":
return TCSH
case "json":
return JSON
case "elvish":
return ELVISH
}
return nil
}