Created
January 25, 2017 00:57
-
-
Save hiway/43f6032e0882de8f48495b1ba4a186e7 to your computer and use it in GitHub Desktop.
Seems to work, with rough edges.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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