Python + Shell Tips

A whistle-stop tour of commands, flags and keyboard shortcuts that I wish I'd known about earlier

Presenter Notes

Readline shortcuts

readline shortcuts

Presenter Notes

The biggest thing I wish I'd understood earlier was how many things used readline, and how many keyboard shortcuts there were.

Not just Bash, used by Python Shell, the Postgres and MySQL shells...

Unto Ctrl+_ Ctrl+P Ctrl+N Ctrl+A Ctrl+E Ctrl+R

You may notice they look like emacs keybindings, but...

set editing-mode vi

in ~/.inputrc

Presenter Notes

if you put this in your inputrc, you get vim keybindings instead

HTTPie

http post http://requestb.in/17dp02s1 fizz=b

Presenter Notes

Like curl, but nicer
General HTTP debugging tool (but written in Python)
Nice syntax for the HTTP verbs, queries and headers
Shows headers by default (less typing)
but the nicest thing:

HTTPie

http get example

Presenter Notes

Is colour!
Syntax highlighted. Really useful for JSON responses to APIs where is also automatically indents.

autojump

~$ j bar

~/some/dir/foobar/$ j bar

~/other/barcamp/$ j bar

Presenter Notes

tig

tig --all

Presenter Notes

Nice colourful interactive output, but still on the commandline

Particularly tig --all, which shows all commits, not just ones in the branch you're currently on.

ipython -i

Presenter Notes

actually equivalent to running with pdb or running python \n from ... import *
but possibly faster / nicer

Not to be confused with...

python manage.py shell -i ipython

Presenter Notes

The other -i
Also recommended

Get a shell for your Django setup with a custom interpreter. ipython has lots of good features, including colours (spot the pattern here)

py.test --pdb

Presenter Notes

Using a debugger is something that took me a while to pick up on....

Also pdb++ highly recommended

inotify

while [ 1 ]; do inotifywait -r --event modify --exclude ".*\.swp" stats; clear; py.test stats; done

Presenter Notes

So, you want to run a test every time a file changes. Many approaches to doing this. This one's general purpose and lightweight.

landslide

Presenter Notes

Written in Python (+ JS)
Write your slides in Markdown or RestructuredText

Presenter Notes