eval-export.elv 579 B

12345678910111213141516171819202122232425262728293031323334
  1. use str
  2. var ignore = [
  3. _
  4. PWD
  5. SHLVL
  6. PATH
  7. ]
  8. fn apply-env {|env|
  9. for var $env {
  10. if (eq $var '') {
  11. break
  12. }
  13. var key value = (str:split &max=2 "=" $var)
  14. if (has-value $ignore $key) {
  15. continue
  16. }
  17. put +$key
  18. set-env $key $value
  19. }
  20. }
  21. # helper to set environment from programs that output a bash script to `eval`
  22. edit:add-var eval-export~ {
  23. var script = (slurp)
  24. var output = (env -i sh -c $script"\n/usr/bin/env -0")
  25. var @vars = (str:split "\x00" $output)
  26. edit:notify "Applying vars"
  27. edit:notify (print (apply-env $vars))
  28. }