Skip to content

Commit 739a509

Browse files
committed
Accept the highlighted completion without executing the command
fixes #32
1 parent 41246d6 commit 739a509

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

evil_winrm_py/evil_winrm_py.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@
2626
from prompt_toolkit import PromptSession, prompt
2727
from prompt_toolkit.completion import Completer, Completion
2828
from prompt_toolkit.document import Document
29+
from prompt_toolkit.filters import has_completions
2930
from prompt_toolkit.formatted_text import ANSI
3031
from prompt_toolkit.history import FileHistory
32+
from prompt_toolkit.key_binding import KeyBindings
3133
from prompt_toolkit.shortcuts import clear
3234
from pypsrp.complex_objects import PSInvocationState
3335
from pypsrp.exceptions import AuthenticationError, WinRMTransportError, WSManFaultError
@@ -1166,6 +1168,16 @@ def interactive_shell(r_pool: RunspacePool) -> None:
11661168
# Set up command completer
11671169
completer = CommandPathCompleter(r_pool)
11681170

1171+
# Set up key bindings
1172+
kb = KeyBindings()
1173+
1174+
@kb.add("enter", filter=has_completions)
1175+
def _(event):
1176+
"""Accept the highlighted completion without executing the command."""
1177+
event.current_buffer.apply_completion(
1178+
event.current_buffer.complete_state.current_completion
1179+
)
1180+
11691181
while True:
11701182
try:
11711183
try:
@@ -1176,6 +1188,7 @@ def interactive_shell(r_pool: RunspacePool) -> None:
11761188
prompt_text,
11771189
completer=completer,
11781190
complete_while_typing=False,
1191+
key_bindings=kb,
11791192
)
11801193

11811194
if not command:

0 commit comments

Comments
 (0)