Skip to content

Commit e27feb4

Browse files
committed
Revert "move all autocomplete shell files into Go code strings"
This reverts commit cffef65.
1 parent d211484 commit e27feb4

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

autocomplete/bash_autocomplete

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#! /bin/bash
2+
3+
: ${PROG:=$(basename ${BASH_SOURCE})}
4+
5+
# Macs have bash3 for which the bash-completion package doesn't include
6+
# _init_completion. This is a minimal version of that function.
7+
_cli_init_completion() {
8+
COMPREPLY=()
9+
_get_comp_words_by_ref "$@" cur prev words cword
10+
}
11+
12+
_cli_bash_autocomplete() {
13+
if [[ "${COMP_WORDS[0]}" != "source" ]]; then
14+
local cur opts base words
15+
COMPREPLY=()
16+
cur="${COMP_WORDS[COMP_CWORD]}"
17+
if declare -F _init_completion >/dev/null 2>&1; then
18+
_init_completion -n "=:" || return
19+
else
20+
_cli_init_completion -n "=:" || return
21+
fi
22+
words=("${words[@]:0:$cword}")
23+
if [[ "$cur" == "-"* ]]; then
24+
requestComp="${words[*]} ${cur} --generate-shell-completion"
25+
else
26+
requestComp="${words[*]} --generate-shell-completion"
27+
fi
28+
opts=$(eval "${requestComp}" 2>/dev/null)
29+
COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
30+
return 0
31+
fi
32+
}
33+
34+
complete -o bashdefault -o default -o nospace -F _cli_bash_autocomplete $PROG
35+
unset PROG
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
$fn = $($MyInvocation.MyCommand.Name)
2+
$name = $fn -replace "(.*)\.ps1$", '$1'
3+
Register-ArgumentCompleter -Native -CommandName $name -ScriptBlock {
4+
param($commandName, $wordToComplete, $cursorPosition)
5+
$other = "$wordToComplete --generate-shell-completion"
6+
Invoke-Expression $other | ForEach-Object {
7+
[System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
8+
}
9+
}

0 commit comments

Comments
 (0)