We start in the theme folder.
-
Capture the current composer command and store it as
$CMD
. -
Find the relative path to our current working directory from the root of the project directory. Find the path to the
Vagrantfile
levels down from the current directory. There must be one because our theme is in a subdirectory of the site repository. -
Store the relative path to our theme folder as
$RELATIVE_CWD
. Usepwd -P
to get the realpath to the current directory. Substract the absolute path to theVagrantfile
from the theme directory to get the relative theme directory. -
SSH into the Vagrant machine and run the
$CMD
command inside thephpfpm
docker container with a specific Composer working directory.$ vagrant ssh -c "cd /vagrant && docker-compose run phpfpm $CMD --working-dir=$RELATIVE_CWD"
-
Boom!