Skip to content

Commit a855714

Browse files
authored
Merge pull request #773 from akinomyoga/function-not-found
fix(function): suppress error messages for non-existent functions
2 parents f575693 + f45fc77 commit a855714

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

completions/function

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ _function()
88
if ((cword == 1)); then
99
COMPREPLY=($(compgen -A function -- "$cur"))
1010
else
11-
COMPREPLY=("() $(type -- ${words[1]} | command sed -e 1,2d)")
11+
local funcdef=$(type -- "${words[1]}" 2>/dev/null | command sed -e 1,2d)
12+
COMPREPLY=("()${funcdef:+ $funcdef}")
1213
fi
1314
} &&
1415
complete -F _function function

test/t/test_function.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
import pytest
22

3+
from conftest import assert_bash_exec, assert_complete
34

5+
6+
@pytest.mark.bashcomp(ignore_env=r"^\+declare -f fn$")
47
class TestFunction:
58
@pytest.mark.complete("function _parse_")
69
def test_1(self, completion):
710
assert completion
11+
12+
@pytest.mark.complete("function non_existent_function ")
13+
def test_2(self, completion):
14+
assert completion == "()"
15+
16+
def test_3(self, bash):
17+
assert_bash_exec(bash, "fn() { echo; }")
18+
completion = assert_complete(bash, "function fn ")
19+
assert completion == "() { ^J echo^J}"

0 commit comments

Comments
 (0)