Tips and tricks for the developer

I thought we might collect together some helpful tips related to developing plugins and other code on an OctoPrint installation. Feel free to add your own here.

Add an alias for that virtual environment command

I find myself typing this command a lot so I decided to add a shell alias for it.

Before:

source ~/oprint/bin/activate

After:

begin

Instructions

I'll be describing this for a Raspbian install since that's what I'm using.

nano ~/.bashrc

Look for the "Alias definitions" section and add this line.

alias begin='source ~/oprint/bin/activate'

Exit and then ssh back into your Raspberry and you now have this new alias (macro).

3 Likes

Great tip...adding "begin" now.

Here's my contribution, which may be more of a "beginner tip"

If you install a plugin that completely fubars Octoprint (so you can't get into the UI), you can un-install the plugin with this command:

For Raspbian, ssh in:

pi@octoprusa:~ $ ~/oprint/bin/pip uninstall (full plugin name)

ie:

pi@octoprusa:~ $ ~/oprint/bin/pip uninstall Octoprint-FilamentWatch

1 Like

I'd add to this...

...having first run that begin (or source ~/oprint/bin/activate) to bring up the virtual environment.

Since I'm slightly lazy, I don't love retyping commands. I often allow the history command to help me repeat something I do. So I'll type history|grep tail which would show me a few times when I've done this. Bash then lets me type in something like !123 to repeat the command which was 123rd in that list.

So here, I introduce a combining of history + grep (find) = fistory as a new alias. Like before, edit your ~/.bashrc to add:

alias fistory='history | grep '

(Remember to include the space after "grep" there.

After:

fistory tail
# Output follows:
  435  tail -f ~/.octoprint/logs/octoprint.log
  442  fistory tail
!435  # So then I can re-run the earlier command

But then again, why not just create an alias for this as well while we're at it?

alias octocat='cat ~/.octoprint/logs/octoprint.log'
alias octotail='tail -f ~/.octoprint/logs/octoprint.log'

After

octotail # tail's the octoprint.log so that you can watch the progress