felixarntz / wordpressdev

WordPress core development environment based on Lando.
GNU General Public License v2.0
13 stars 0 forks source link

Improve shell integration with Lando #14

Open westonruter opened 5 years ago

westonruter commented 5 years ago

On my machine, I have wordpressdev located at ~/sites/wordpressdev. I have a dotfiles repo with a .functions file that is sourced. In this file I just added a Bash function:

function wpdev {
    cd ~/sites/wordpressdev

    alias npm="lando npm"
    alias grunt="lando grunt"
    alias gulp="lando gulp"
    alias composer="lando composer"
    alias phpunit="lando phpunit"
    alias wp="lando wp"

    if ! grep -qi lando <<< $PS1; then
        export PS1=$(sed 's/\\n/\\nLando:/' <<< $PS1)
    fi
}

This sets up the Bash session for WordPress development by:

  1. Changing the working directory to where wordpressdev is located.
  2. Adds Bash aliases for running Lando commands.
  3. Prefixes the bash prompt with Lando: so I know that commands will be run in the container.

image

It would be nice to include this as part of wordpressdev if it makes sense. Nevertheless, there is one big problem that makes this not ideal: aliases aren't inherited by subshells. What is really needed is for a pre-commit hook to be able to invoke lando phpunit by just invoking phpunit. What's even more more problematic here is that lando commands don't work in pre-commit hooks: https://github.com/lando/lando/issues/904#issuecomment-450975991