File tree Expand file tree Collapse file tree 8 files changed +111
-66
lines changed Expand file tree Collapse file tree 8 files changed +111
-66
lines changed File renamed without changes.
Original file line number Diff line number Diff line change 1
- package shell
1
+ package shenv
2
2
3
3
import "fmt"
4
4
@@ -8,15 +8,15 @@ type bash struct{}
8
8
var Bash Shell = bash {}
9
9
10
10
const bashHook = `
11
- _direnv_hook () {
11
+ _devbox_hook () {
12
12
local previous_exit_status=$?;
13
13
trap -- '' SIGINT;
14
- eval "$("{{.SelfPath}}" export bash )";
14
+ eval "$(devbox shellenv --config {{ .ProjectDir }} )";
15
15
trap - SIGINT;
16
16
return $previous_exit_status;
17
17
};
18
- if ! [[ "${PROMPT_COMMAND:-}" =~ _direnv_hook ]]; then
19
- PROMPT_COMMAND="_direnv_hook ${PROMPT_COMMAND:+;$PROMPT_COMMAND}"
18
+ if ! [[ "${PROMPT_COMMAND:-}" =~ _devbox_hook ]]; then
19
+ PROMPT_COMMAND="_devbox_hook ${PROMPT_COMMAND:+;$PROMPT_COMMAND}"
20
20
fi
21
21
`
22
22
Original file line number Diff line number Diff line change 1
- package shell
1
+ package shenv
2
2
3
3
import (
4
4
"fmt"
@@ -11,29 +11,9 @@ type fish struct{}
11
11
var Fish Shell = fish {}
12
12
13
13
const fishHook = `
14
- function __direnv_export_eval --on-event fish_prompt;
15
- "{{.SelfPath}}" export fish | source;
16
-
17
- if test "$direnv_fish_mode" != "disable_arrow";
18
- function __direnv_cd_hook --on-variable PWD;
19
- if test "$direnv_fish_mode" = "eval_after_arrow";
20
- set -g __direnv_export_again 0;
21
- else;
22
- "{{.SelfPath}}" export fish | source;
23
- end;
24
- end;
25
- end;
26
- end;
27
-
28
- function __direnv_export_eval_2 --on-event fish_preexec;
29
- if set -q __direnv_export_again;
30
- set -e __direnv_export_again;
31
- "{{.SelfPath}}" export fish | source;
32
- echo;
33
- end;
34
-
35
- functions --erase __direnv_cd_hook;
36
- end;
14
+ function __devbox_shellenv_eval --on-event fish_prompt;
15
+ devbox shellenv --config {{ .ProjectDir }} | source;
16
+ end;
37
17
`
38
18
39
19
func (sh fish ) Hook () (string , error ) {
Original file line number Diff line number Diff line change
1
+ package shenv
2
+
3
+ type ksh struct {}
4
+
5
+ // Ksh adds support the korn shell
6
+ var Ksh Shell = ksh {}
7
+
8
+ // um, this is ChatGPT writing it. I need to verify and test
9
+ const kshHook = `
10
+ _devbox_hook() {
11
+ eval "$(devbox shellenv --config {{ .ProjectDir }})";
12
+ }
13
+ if [[ "$(typeset -f precmd)" != *"_devbox_hook"* ]]; then
14
+ function precmd {
15
+ devbox_hook
16
+ }
17
+ fi
18
+ `
19
+
20
+ func (sh ksh ) Hook () (string , error ) {
21
+ return kshHook , nil
22
+ }
23
+
24
+ func (sh ksh ) Export (e ShellExport ) (out string ) {
25
+ panic ("not implemented" )
26
+ }
27
+
28
+ func (sh ksh ) Dump (env Env ) (out string ) {
29
+ panic ("not implemented" )
30
+ }
Original file line number Diff line number Diff line change
1
+ package shenv
2
+
3
+ type posix struct {}
4
+
5
+ // Posix adds support for posix-compatible shells
6
+ // Specifically, in the context of devbox, this includes
7
+ // `dash`, `ash`, and `shell`
8
+ var Posix Shell = posix {}
9
+
10
+ // um, this is ChatGPT writing it. I need to verify and test
11
+ const posixHook = `
12
+ _devbox_hook() {
13
+ local previous_exit_status=$?
14
+ trap : INT
15
+ eval "$(devbox shellenv --config {{ .ProjectDir }})"
16
+ trap - INT
17
+ return $previous_exit_status
18
+ }
19
+ if [ -z "$PROMPT_COMMAND" ] || ! printf "%s" "$PROMPT_COMMAND" | grep -q "_devbox_hook"; then
20
+ PROMPT_COMMAND="_devbox_hook${PROMPT_COMMAND:+;$PROMPT_COMMAND}"
21
+ fi
22
+ `
23
+
24
+ func (sh posix ) Hook () (string , error ) {
25
+ return posixHook , nil
26
+ }
27
+
28
+ func (sh posix ) Export (e ShellExport ) (out string ) {
29
+ panic ("not implemented" )
30
+ }
31
+
32
+ func (sh posix ) Dump (env Env ) (out string ) {
33
+ panic ("not implemented" )
34
+ }
Original file line number Diff line number Diff line change
1
+ package shenv
2
+
3
+ type unknown struct {}
4
+
5
+ // UnknownSh adds support the unknown shell. This serves
6
+ // as a fallback alternative to outright failure.
7
+ var UnknownSh Shell = unknown {}
8
+
9
+ const unknownHook = `
10
+ echo "Warning: this shell will not update its environment.
11
+ Please exit and re-enter shell after making any changes that may affect the devbox generated environment.\n"
12
+ `
13
+
14
+ func (sh unknown ) Hook () (string , error ) {
15
+ return unknownHook , nil
16
+ }
17
+
18
+ func (sh unknown ) Export (e ShellExport ) (out string ) {
19
+ panic ("not implemented" )
20
+ }
21
+
22
+ func (sh unknown ) Dump (env Env ) (out string ) {
23
+ panic ("not implemented" )
24
+ }
Original file line number Diff line number Diff line change 1
- package shell
1
+ package shenv
2
2
3
3
// ZSH is a singleton instance of ZSH_T
4
4
type zsh struct {}
@@ -7,18 +7,14 @@ type zsh struct{}
7
7
var Zsh Shell = zsh {}
8
8
9
9
const zshHook = `
10
- _direnv_hook () {
10
+ _devbox_hook () {
11
11
trap -- '' SIGINT;
12
- eval "$("{{.SelfPath}}" export zsh )";
12
+ eval "$(devbox shellenv --config {{ .ProjectDir }} )";
13
13
trap - SIGINT;
14
14
}
15
15
typeset -ag precmd_functions;
16
- if [[ -z "${precmd_functions[(r)_direnv_hook]+1}" ]]; then
17
- precmd_functions=( _direnv_hook ${precmd_functions[@]} )
18
- fi
19
- typeset -ag chpwd_functions;
20
- if [[ -z "${chpwd_functions[(r)_direnv_hook]+1}" ]]; then
21
- chpwd_functions=( _direnv_hook ${chpwd_functions[@]} )
16
+ if [[ -z "${precmd_functions[(r)_devbox_hook]+1}" ]]; then
17
+ precmd_functions=( _devbox_hook ${precmd_functions[@]} )
22
18
fi
23
19
`
24
20
Original file line number Diff line number Diff line change 1
- package shell
2
-
3
- import (
4
- "path/filepath"
5
- )
1
+ package shenv
6
2
7
3
type Env map [string ]string
8
4
@@ -33,36 +29,21 @@ func (e ShellExport) Remove(key string) {
33
29
e [key ] = nil
34
30
}
35
31
36
- // DetectShell returns a Shell instance from the given target.
37
- //
38
- // target is usually $0 and can also be prefixed by `-`
32
+ // DetectShell returns a Shell instance from the given shell name
33
+ // TODO: use a single common "enum" for both shenv and DevboxShell
39
34
func DetectShell (target string ) Shell {
40
- target = filepath .Base (target )
41
- // $0 starts with "-"
42
- if target [0 :1 ] == "-" {
43
- target = target [1 :]
44
- }
45
-
46
35
switch target {
47
36
case "bash" :
48
37
return Bash
49
- //case "elvish":
50
- // return Elvish
51
38
case "fish" :
52
39
return Fish
53
- //case "gha":
54
- // return GitHubActions
55
- //case "gzenv":
56
- // return GzEnv
57
- //case "json":
58
- // return JSON
59
- //case "tcsh":
60
- // return Tcsh
61
- //case "vim":
62
- // return Vim
40
+ case "ksh" :
41
+ return Ksh
42
+ case "posix" :
43
+ return Posix
63
44
case "zsh" :
64
45
return Zsh
46
+ default :
47
+ return UnknownSh
65
48
}
66
-
67
- return nil
68
49
}
You can’t perform that action at this time.
0 commit comments