All pastes #411138 Raw Edit

Miscellany

public text v1 · immutable
#411138 ·published 2007-03-26 21:26 UTC
rendered paste body
#!/usr/bin/python

import readline

primary = ["bob", "bill", "foo", "bar"]
secondary = ["--bar", "--foo"]

def complete(text, state):
	incmd = False
	line = readline.get_line_buffer()
	for cmd in primary:
		if line.startswith(cmd +" "):
			incmd = True
	if (incmd):
		values = [s for s in secondary if s.startswith(text)]
	else:
		values = [s for s in primary if s.startswith(text)]

	values.sort()
	return values[state]

readline.set_completer_delims(' \t\n`~!@#$%^&*()=+[{]}\\|;:\'",<>/?')
readline.set_completer(complete)
readline.parse_and_bind("tab: complete")

while (True):
	inp = raw_input("input# ")