0

tldr

i'd like to run an export command in zshrc that takes a while to run. i don't need the env variable immediately but would like to have my command prompt available right away. is there a way to start this command in the background?

background

i'm using docker on osx via boot2docker. i'd like to be able to have an env variable available (DOCKER_HOST) so trying to set that up in zshrc.

the command i need to run though in order to figure out the correct value for DOCKER_HOST can take a few seconds to run:

cd /boot2docker && export DOCKER_HOST="tcp://`vagrant ssh-config | sed -n "s/[ ]*HostName[ ]*//gp"`:2375"

(that command is taken directly from https://github.com/Parallels/boot2docker-vagrant-box)

basically the command does the following:

  1. enters the /boot2docker directory
  2. runs vagrant ssh-config and gets the hostname
  3. exports DOCKER_HOST="$HOST_NAME:2375"

but that step #2 can take some time. so putting this command as-is into my ~/.zshrc.local file causes new terminal windows to take way too long to show the prompt (5-10 seconds!).

i'm wondering if anyone knows a way to run this in the background. i'm ok with the env variable not being available those first 5-10 seconds but i want my prompt to show up and be usable right away!

Etan Reisner
  • 77,877
  • 8
  • 106
  • 148
hackerhasid
  • 11,699
  • 10
  • 42
  • 60
  • @EtanReisner Right. But if terminals are going to be started before this command finishes, as the OP states, then wouldn't any deferral of the results require that another operation be done in those shells to set `DOCKER_HOST` when the task finally completes? – lurker Mar 18 '15 at 17:01
  • Not sure I understood that but a solution here would certainly be to perform that in the background and use a lock/state file to ensure only one runs at once and that the result is cached and loaded in new shells. – Etan Reisner Mar 18 '15 at 17:04

0 Answers0