Add tab-completion for paths#45
Conversation
Supported commands: all commands accepting a `path` argument (ls, rm, mv, edit, show). Caveats Completions must match exact structure of paths. As a result, it doesn't: - support db-prefixes - support case-insensitivty - support regexes Additional changes - Add `login` command (for explicit caching, when `zenity` is missing) - Remove extra '' around form label in `zenity` - Remove period from error message - Fix incorrect name being passed to default section prompt - Handle more cases in `decompose_path` + return tuple - Fix `info_parser` comment
|
@Evidlo I've yet to update the documentation with how to set it up, but please have a look/try it out. I'll update the docs when we've settled on something. |
|
In the meantime, if you're not familiar with |
|
I did some experimentation with prompting for the password during the completion to eliminate the need for
#!/bin/env python3
from getpass import getpass
import argcomplete, argparse
def path_completer(prefix, parsed_args, **kwargs):
password = getpass('\nInput Password:')
if password == 'password':
return ['helloworld', 'foobar']
parser = argparse.ArgumentParser()
patharg = parser.add_argument('path', metavar='PATH', type=str, help='item path')
patharg.completer = path_completer
argcomplete.autocomplete(parser)
args = parser.parse_args()
print(f'selected item: {args.path}')And for testing: It's not fully working, as you have to hit enter twice for some reason after entering a password and the prompt line isn't redrawn when the completion is finished. Also, argcomplete hijacks stdout so I had to abuse Ideally, tab completion when entering a password would look something like this: |
Supported commands: all commands accepting a
pathargument (ls, rm, mv, edit, show).Caveats
Completions must match exact structure of paths. As a result, it doesn't:
Additional changes
logincommand (for explicit caching, whenzenityis missing)zenitydecompose_path+ return tupleinfo_parsercommentCloses #44