MCPcopy Create free account
hub / github.com/dim-an/cod / GetPreamble

Method GetPreamble

shells/shells.go:207–340  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

205}
206
207func (b *Bash) GetPreamble() (lines []string) {
208 codBinaryVar := fmt.Sprintf("__COD_BINARY=%v", quoteArg(b.codCommandPath))
209 scriptText := `
210cod_enable_trace=${cod_enable_trace-false}
211
212__cod_ref_count=0
213function __cod_ref_trace() {
214 if [ "$((__cod_ref_count))" -eq 0 ] ; then
215 echo "--> inside: ${FUNCNAME[@]}" >&2
216 set -x
217 fi
218 : $((__cod_ref_count++))
219}
220
221function __cod_unref_trace() {
222 : $((__cod_ref_count--))
223 if [ "$__cod_ref_count" -eq 0 ] ; then
224 set +x
225 fi
226}
227
228function __cod_add_completions() {
229 $cod_enable_trace && __cod_ref_trace
230
231 complete -o filenames -o bashdefault -F __cod_complete_bash "$1"
232
233 $cod_enable_trace && __cod_unref_trace
234 return 0
235}
236
237function __cod_clear_completions() {
238 $cod_enable_trace && __cod_ref_trace
239
240 local TO_KEEP
241 TO_KEEP=$(complete -p | command $__COD_BINARY api bash-clean-completions -- "$1")
242 eval "$TO_KEEP"
243
244 $cod_enable_trace && __cod_unref_trace
245 return 0
246}
247
248function __cod_complete_bash() {
249 $cod_enable_trace && __cod_ref_trace
250
251 # First we want to get file completions.
252
253 local FILTEROPT
254 if [ -z "$2" ] ; then
255 # If user trying to complete empty string we want to filter out dot files.
256 FILTEROPT='.*'
257 fi
258
259 local FILE_COMPLETIONS
260 local COD_COMPLETIONS
261 # Generate file completions
262 readarray -t FILE_COMPLETIONS < <(compgen -f -X "$FILTEROPT" -- "$2")
263
264 # Generate cod completions.

Callers

nothing calls this directly

Calls 1

quoteArgFunction · 0.85

Tested by

no test coverage detected