Skip to content

Commit

Permalink
*: complete commands when prefixed with a backslash
Browse files Browse the repository at this point in the history
Closes #368
  • Loading branch information
scop committed Dec 11, 2019
1 parent 8130f87 commit 1e029e8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
16 changes: 14 additions & 2 deletions bash_completion
Original file line number Diff line number Diff line change
Expand Up @@ -2096,17 +2096,29 @@ __load_completion()
dirs+=( ./completions )
fi
local backslash=
if [[ $cmd == \\* ]]; then
cmd="${cmd:1}"
# If we already have a completion for the "real" command, use it
$(complete -p "$cmd" 2>/dev/null || echo false) "\\$cmd" && return 0
backslash=\\
fi
for dir in "${dirs[@]}"; do
[[ -d "$dir" ]] || continue
for compfile in "$cmd" "$cmd.bash" "_$cmd"; do
compfile="$dir/$compfile"
# Avoid trying to source dirs; https://bugzilla.redhat.com/903540
[[ -f "$compfile" ]] && . "$compfile" &>/dev/null && return 0
if [[ -f "$compfile" ]] && . "$compfile" &>/dev/null; then
[[ $backslash ]] && $(complete -p "$cmd") "\\$cmd"
return 0
fi
done
done
# Look up simple "xspec" completions
[[ "${_xspecs[$cmd]}" ]] && complete -F _filedir_xspec "$cmd" && return 0
[[ "${_xspecs[$cmd]}" ]] &&
complete -F _filedir_xspec "$cmd" "$backslash$cmd" && return 0
return 1
}
Expand Down
4 changes: 4 additions & 0 deletions test/t/test_complete.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ class TestComplete:
@pytest.mark.complete("complete -")
def test_1(self, completion):
assert completion

@pytest.mark.complete(r"\complete -")
def test_2(self, completion):
assert completion

0 comments on commit 1e029e8

Please sign in to comment.