runit-user-services/import-env.zsh
2023-09-19 10:48:15 +02:00

14 lines
325 B
Bash

import-env() {
for source_name in $@; do
SOURCE_PID=$(pgrep $source_name | head -n 1)
if [[ -n $SOURCE_PID ]]; then break; fi
done
if [[ -z $SOURCE_PID ]]; then
echo "import-env: No matching process for: $*"
return 1;
fi
SOURCE_ENV=("${(@ps:\000:)$(</proc/${SOURCE_PID}/environ)}")
export ${SOURCE_ENV[@]:#}
}