Skip to content

Commit

Permalink
Get undo env from the env with recursive eval
Browse files Browse the repository at this point in the history
  • Loading branch information
mxcl committed Jan 8, 2025
1 parent be3650f commit 7d5ca42
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ for (const envln of env.trim().split("\n")) {
const value = Deno.env.get(key);

if (value) {
undo += ` export ${key}=${shell_escape(value)}\n`;
undo += ` export ${key}=\\"$${key}\\"\n`;
} else {
undo += ` unset ${key}\n`;
}
Expand All @@ -71,21 +71,21 @@ const dir = Deno.cwd();
const bye_bye_msg = pkgspecs.map((pkgspec) => `-${pkgspec.slice(1)}`).join(" ");

console.log(`
set -a
${env}
set +a
_pkgx_dev_try_bye() {
suffix="\${PWD#"${dir}"}"
if test "$PWD" != "${dir}$suffix"; then
eval "_pkgx_dev_try_bye() {
suffix=\\"\\\${PWD#\\"${dir}\\"}\\"
if test \\"\\$PWD\\" != \\"${dir}$suffix\\"; then
${undo.trim()}
unset -f _pkgx_dev_try_bye
echo "\\033[31m${bye_bye_msg}\\033[0m" >&2
echo -e \\"\\033[31m${bye_bye_msg}\\033[0m\\" >&2
return 0
else
return 1
fi
}
`.trim());
}"
set -a
${env}
set +a
`);

console.error("%c%s", "color: green", pkgspecs.join(" "));

0 comments on commit 7d5ca42

Please sign in to comment.