Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion completions/function
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ _function()
if ((cword == 1)); then
COMPREPLY=($(compgen -A function -- "$cur"))
else
COMPREPLY=("() $(type -- ${words[1]} | command sed -e 1,2d)")
local funcdef=$(type -- "${words[1]}" 2>/dev/null | command sed -e 1,2d)
COMPREPLY=("()${funcdef:+ $funcdef}")
fi
} &&
complete -F _function function
Expand Down
12 changes: 12 additions & 0 deletions test/t/test_function.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
import pytest

from conftest import assert_bash_exec, assert_complete


@pytest.mark.bashcomp(ignore_env=r"^\+declare -f fn$")
class TestFunction:
@pytest.mark.complete("function _parse_")
def test_1(self, completion):
assert completion

@pytest.mark.complete("function non_existent_function ")
def test_2(self, completion):
assert completion == "()"

def test_3(self, bash):
assert_bash_exec(bash, "fn() { echo; }")
completion = assert_complete(bash, "function fn ")
assert completion == "() { ^J echo^J}"