This can be found in lib / ROOT.py
there is a condition that if not ipython, sys.excepthook is overridden:
sys.excepthook = _excepthook
which, in turn, contains such things as:
------------------------------------------------------
def _excepthook( exctype, value, traceb ):
if isinstance( value, SyntaxError ) and value.text:
cmd, arg = split( value.text[:-1] )
if cmd == '.q':
sys.exit( 0 )
or a few lines below:
elif cmd == '.ls':
return sys.modules[ __name__ ].gDirectory.ls()
, .