Skip to content

Instantly share code, notes, and snippets.

@sgrankin
Created June 11, 2016 17:12
Show Gist options
  • Save sgrankin/169914a5c6386aef6ca657b1af043d09 to your computer and use it in GitHub Desktop.
Save sgrankin/169914a5c6386aef6ca657b1af043d09 to your computer and use it in GitHub Desktop.
Docker machine LaunchAgent using launchctl to set environment vars
# This is a shell archive. Save it in a file, remove anything before
# this line, and then unpack it by entering "sh file". Note, it may
# create directories; files and directories will be owned by you and
# have default permissions.
#
# This archive contains:
#
# Library/LaunchAgents/com.docker.machine.default.plist
#
echo x - Library/LaunchAgents/com.docker.machine.default.plist
sed 's/^X//' >Library/LaunchAgents/com.docker.machine.default.plist << 'END-of-Library/LaunchAgents/com.docker.machine.default.plist'
X<?xml version="1.0" encoding="UTF-8"?>
X<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
X<plist version="1.0">
X<dict>
X <key>EnvironmentVariables</key>
X <dict>
X <key>PATH</key>
X <string>/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin</string>
X </dict>
X <key>Label</key>
X <string>com.docker.machine.default</string>
X <key>ProgramArguments</key>
X <array>
X <string>/bin/sh</string>
X <string>-c</string>
X <string>docker-machine start default &amp;&amp; (docker-machine env --shell sh | awk &apos;BEGIN{FS=&quot;[ =]&quot;} $1==&quot;export&quot;{system(sprintf(&quot;launchctl setenv \&quot;%s\&quot; \&quot;%s\&quot;&quot;, $2, $3))}&apos;)</string>
X </array>
X <key>RunAtLoad</key>
X <true/>
X</dict>
X</plist>
END-of-Library/LaunchAgents/com.docker.machine.default.plist
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment