Add tabcompletion support

Add proper tabcompletion support. Most work is code cleanup and adding unittests.
`wordlist` is the meaning of the `compgen -W` option. but i can change it if you really insist