1
0
mirror of https://github.com/dcarrillo/dotfiles.git synced 2024-12-22 13:58:00 +00:00

Update secrets Kitten

This commit is contained in:
Daniel Carrillo 2021-12-06 12:21:18 +01:00
parent 44b209a56d
commit 4ef1b6ab1a
Signed by: dcarrillo
GPG Key ID: E4CD5C09DAED6E16

View File

@ -1,23 +1,37 @@
from contextlib import closing
from typing import Dict, List
from typing import Dict, List, Optional
from simple_term_menu import TerminalMenu
from prompt_toolkit.application.current import get_app
from prompt_toolkit import PromptSession
from prompt_toolkit.completion import WordCompleter
import secretstorage
from kitty.boss import Boss
def main(args: List[str]) -> str:
options = get_secret_names(args[1], args[2])
terminal_menu = TerminalMenu(options)
menu_entry_index = terminal_menu.show()
def main(args: List[str]) -> Optional[str]:
secrets = get_secret_names(args[1], args[2])
entries = WordCompleter(secrets)
session = PromptSession(completer=entries)
try:
entry = session.prompt('> ', pre_run=expand_prompt)
except (KeyboardInterrupt, EOFError):
pass
else:
return secrets[entry]
if menu_entry_index is not None:
return list(options.values())[menu_entry_index]
return None
return ''
def expand_prompt() -> None:
app = get_app()
buffer = app.current_buffer
if buffer.complete_state:
buffer.complete_next()
else:
buffer.start_completion(select_first=False)
def get_secret_names(attribute: str, value: str) -> Dict[str, str]: