#NEWLINE# def split_line_like_bash( line , point ) : #NEWLINE# #INDENT# "\n    :returns: comp_words, comp_cword\n\n    Split the line like bash would, and then put it back together with\n    IFS, and calculate cword while you're at it.\n\n    Use os.environ['COMP_POINT'] to figure out which word we're in\n    " #NEWLINE# point = int ( point ) #NEWLINE# cwords = [ ] #NEWLINE# current_word = '' #NEWLINE# append_to_current_word = False #NEWLINE# for pos in range ( len ( line ) ) : #NEWLINE# #INDENT# if ( pos == point ) : #NEWLINE# #INDENT# cword = len ( cwords ) #NEWLINE# #UNINDENT# if append_to_current_word : #NEWLINE# #INDENT# append_to_current_word = False #NEWLINE# current_word += line [ pos ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( line [ pos ] == '\\' ) : #NEWLINE# #INDENT# append_to_current_word = True #NEWLINE# current_word += line [ pos ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if line [ pos ] . isspace ( ) : #NEWLINE# #INDENT# if ( len ( current_word ) > 0 ) : #NEWLINE# #INDENT# cwords . append ( current_word ) #NEWLINE# current_word = '' #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( line [ pos ] in '[<>=:]' ) : #NEWLINE# #INDENT# if ( len ( current_word ) > 0 ) : #NEWLINE# #INDENT# cwords . append ( current_word ) #NEWLINE# current_word = '' #NEWLINE# #UNINDENT# cwords . append ( line [ pos ] ) #NEWLINE# if ( pos == point ) : #NEWLINE# #INDENT# cword += 1 #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# current_word += line [ pos ] #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# if ( len ( current_word ) > 0 ) : #NEWLINE# #INDENT# cwords . append ( current_word ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if line [ ( - 1 ) ] . isspace ( ) : #NEWLINE# #INDENT# cwords . append ( '' ) #NEWLINE# #UNINDENT# #UNINDENT# if ( point == len ( line ) ) : #NEWLINE# #INDENT# cword = ( len ( cwords ) - 1 ) #NEWLINE# #UNINDENT# return ( IFS . join ( cwords ) , str ( cword ) )