move ipython command line logic to one place

it keeps getting repeated, more elegant to move it out into the call