Skip to content

Commit

Permalink
No stdin for python calls from bash completion functions
Browse files Browse the repository at this point in the history
Prevents usage of stdin by (python) executables that are called during completion generation. This prevents the completion locking up the entire shell when the python script is broken i.e. it enters an interactive mode (REPL) instead of generating the completions, as expected.
  • Loading branch information
bfis committed Jun 5, 2024
1 parent 6c9e540 commit 38d2f39
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
4 changes: 2 additions & 2 deletions argcomplete/bash_completion.d/_python-argcomplete
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ __python_argcomplete_run() {

__python_argcomplete_run_inner() {
if [[ -z "${_ARC_DEBUG-}" ]]; then
"$@" 8>&1 9>&2 1>/dev/null 2>&1
"$@" 8>&1 9>&2 1>/dev/null 2>&1 </dev/null
else
"$@" 8>&1 9>&2 1>&9 2>&1
"$@" 8>&1 9>&2 1>&9 2>&1 </dev/null
fi
}

Expand Down
4 changes: 2 additions & 2 deletions argcomplete/shell_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
__python_argcomplete_run_inner() {
if [[ -z "${_ARC_DEBUG-}" ]]; then
"$@" 8>&1 9>&2 1>/dev/null 2>&1
"$@" 8>&1 9>&2 1>/dev/null 2>&1 </dev/null
else
"$@" 8>&1 9>&2 1>&9 2>&1
"$@" 8>&1 9>&2 1>&9 2>&1 </dev/null
fi
}
Expand Down
6 changes: 6 additions & 0 deletions test/stuck
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env python
# PYTHON_ARGCOMPLETE_OK
from sys import argv

if argv[1:] != ["no-input"]:
input()
4 changes: 4 additions & 0 deletions test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1348,6 +1348,10 @@ def test_python_filename_completion(self):
self.sh.run_command("cd " + TEST_DIR)
self.assertEqual(self.sh.run_command("python3 ./pro\tbasic f\t"), "foo\r\n")

def test_python_stuck(self):
self.sh.run_command("cd " + TEST_DIR)
self.sh.run_command("python3 ./stuck no\t-input")

def test_python_not_executable(self):
"""Test completing a script that cannot be run directly."""
prog = os.path.join(TEST_DIR, "prog")
Expand Down

0 comments on commit 38d2f39

Please sign in to comment.