Skip to content

Instantly share code, notes, and snippets.

@hiway
Created January 25, 2017 00:57
Show Gist options
  • Save hiway/43f6032e0882de8f48495b1ba4a186e7 to your computer and use it in GitHub Desktop.
Save hiway/43f6032e0882de8f48495b1ba4a186e7 to your computer and use it in GitHub Desktop.
Seems to work, with rough edges.
import os
import readline
AUTOCOMPLETE_CACHE = {}
def completer(text, state):
global AUTOCOMPLETE_CACHE
buffer = os.path.expanduser(readline.get_line_buffer())
cached_response = AUTOCOMPLETE_CACHE.get(buffer, [])
dir_name = os.path.dirname(buffer)
if not cached_response:
complete = os.path.basename(buffer)
cached_response = [p for p in os.listdir(dir_name) if
p.startswith(complete)]
AUTOCOMPLETE_CACHE[buffer] = cached_response
try:
return cached_response[state]
except IndexError:
return None
readline.add_history('~/.ssh/')
readline.set_completer(completer)
readline.parse_and_bind('tab: menu-complete')
pick_file = input('file: ')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment