How to add "platformio" / "pio" shortcut on Linux command line

Typically, when you want to use the pio executable from PlatformIO, you need to first activate the virtual environment using

source ~/.platformio/penv/bin/activate

However, you can easily create a shortcut using a shell alias using:

For bash:

echo -e '\nalias platformio="source ~/.platformio/penv/bin/activate"\n' >> ~/.bashrc

For zsh:

echo -e '\nalias platformio="source ~/.platformio/penv/bin/activate"\n' >> ~/.zshrc

Note that in order for the change to take effect, you need to restart your shell(or open a new shell).

Now you can use run

platformio

and you’ll immediately have access to pio and other PlatformIO tools.