#NEWLINE# def cd_completer( self , event ) : #NEWLINE# #INDENT# 'Completer function for cd, which only returns directories.' #NEWLINE# ip = get_ipython ( ) #NEWLINE# relpath = event . symbol #NEWLINE# if ( event . line . endswith ( '-b' ) or ( ' -b ' in event . line ) ) : #NEWLINE# #INDENT# bkms = self . db . get ( 'bookmarks' , None ) #NEWLINE# if bkms : #NEWLINE# #INDENT# return list ( bkms . keys ( ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return [ ] #NEWLINE# #UNINDENT# #UNINDENT# if ( event . symbol == '-' ) : #NEWLINE# #INDENT# width_dh = str ( len ( str ( ( len ( ip . user_ns [ '_dh' ] ) + 1 ) ) ) ) #NEWLINE# fmt = ( ( '-%0' + d ) + 'd [%s]' ) #NEWLINE# ents = [ ( fmt % ( i , s ) ) for ( i , s ) in enumerate ( ip . user_ns [ '_dh' ] ) ] #NEWLINE# if ( len ( ents ) > 1 ) : #NEWLINE# #INDENT# return ents #NEWLINE# #UNINDENT# return [ ] #NEWLINE# #UNINDENT# if event . symbol . startswith ( '--' ) : #NEWLINE# #INDENT# return [ ( '--' + os . path . basename ( d ) ) for d in ip . user_ns [ '_dh' ] ] #NEWLINE# #UNINDENT# ( relpath , tilde_expand , tilde_val ) = expand_user ( relpath ) #NEWLINE# relpath = relpath . replace ( '\\' , '/' ) #NEWLINE# found = [ ] #NEWLINE# for d in [ ( f . replace ( '\\' , '/' ) + '/' ) for f in glob . glob ( ( relpath + '*' ) ) if os . path . isdir ( f ) ] : #NEWLINE# #INDENT# if ( ' ' in d ) : #NEWLINE# #INDENT# raise TryNext #NEWLINE# #UNINDENT# found . append ( d ) #NEWLINE# #UNINDENT# if ( not found ) : #NEWLINE# #INDENT# if os . path . isdir ( relpath ) : #NEWLINE# #INDENT# return [ compress_user ( relpath , tilde_expand , tilde_val ) ] #NEWLINE# #UNINDENT# bks = iter ( self . db . get ( 'bookmarks' , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) . keys ( ) ) #NEWLINE# bkmatches = [ s for s in bks if s . startswith ( event . symbol ) ] #NEWLINE# if bkmatches : #NEWLINE# #INDENT# return bkmatches #NEWLINE# #UNINDENT# raise TryNext #NEWLINE# #UNINDENT# return [ compress_user ( p , tilde_expand , tilde_val ) for p in found ]