forked from pkgxdev/pkgx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.magic.ts
132 lines (110 loc) · 3.43 KB
/
app.magic.ts
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import { basename } from "deno/path/mod.ts"
import { undent } from "utils"
import Path from "path"
import { useEnv } from "./hooks/useConfig.ts"
export default function(self: Path, shell?: string) {
const { SHELL } = useEnv()
shell ??= basename(SHELL ?? "unknown")
const d = self.parent()
switch (shell) {
case "zsh":
return undent`
_tea_chpwd_hook() {
if [ "\${TEA_MAGIC:-}" != 0 -a -x "${d}"/tea ]; then
source <("${d}"/tea +tea.xyz/magic -Esk --chaste env)
fi
}
if test "$TERM_PROGRAM" = WarpTerminal -o "$TERM_PROGRAM" = vscode; then
# warp.dev & vscode integrated terminal don’t call the hook on startup
_tea_chpwd_hook
fi
typeset -ag chpwd_functions
if [[ -z "\${chpwd_functions[(r)_tea_hook]+1}" ]]; then
chpwd_functions=( _tea_chpwd_hook \${chpwd_functions[@]} )
fi
if [[ "$PATH" != *"$HOME/.local/bin"* ]]; then
export PATH="$HOME/.local/bin:$PATH"
fi
if ! command -v tea 2>&1 >/dev/null || ! tea --prefix 2>&1 >/dev/null; then
export PATH="${d}:$PATH"
fi
function command_not_found_handler {
if [ "\${TEA_MAGIC:-}" != 0 -a -x "${d}"/tea ]; then
"${d}"/tea -- $*
else
echo "zsh: command not found: $*" >&2
exit 127
fi
}
`
case "elvish":
// eval ($MAGIC | slurp)
return undent`
set after-chdir = [ $@after-chdir { |dir|
eval ("${d}"/tea +tea.xyz/magic -Esk --chaste env | slurp)
}]
# insert env for current dir too
eval ("${d}"/tea +tea.xyz/magic -Esk --chaste env | slurp)
if not (echo $PATH | split ':' | each [p]{ has-prefix $p $HOME/.local/bin }) {
echo "$HOME/.local/bin is not in PATH"
}
if (not (has-external tea)) {
set paths = [
${d}
$@paths
]
}
# command-not-found
set edit:after-command = [ $@edit:after-command { |m|
var error = $m[error]
var src = $m[src]
if (not-eq $error $nil) {
var reason
try {
set reason = $error[reason]
} catch {
set reason = ""
}
use str
if (str:has-prefix (repr $reason) "<unknown exec:") {
"${d}"/tea (str:split &max=-1 ' ' $src[code])
}
}
}]
`
case "fish":
return undent`
function add_tea_environment --on-variable PWD
"${d}"/tea --env --keep-going --silent --dry-run=w/trace | source
end
if not string match -q -r "^$HOME/.local/bin(:|\\$)" $PATH
export PATH="$HOME/.local/bin:$PATH"
end
if ! command -v tea 2>&1 >/dev/null || ! tea --prefix 2>&1 >/dev/null
export PATH="${d}:$PATH"
end
function fish_command_not_found
"${d}"/tea -- $argv
end
"${d}"/tea --env --keep-going --silent --dry-run=w/trace | source
`
case "bash":
return undent`
cd() {
builtin cd "$@" || return
source /dev/stdin <<<"$("${d}"/tea +tea.xyz/magic -Esk --chaste env)"
}
if [[ "$PATH" != *"$HOME/.local/bin"* ]]; then
export PATH="$HOME/.local/bin:$PATH"
fi
if ! command -v tea 2>&1 >/dev/null || ! tea --prefix 2>&1 >/dev/null; then
export PATH="${d}:$PATH"
fi
function command_not_found_handle {
"${d}"/tea -- $*
}
`
default:
throw new Error("unsupported shell")
}
}