How to debug bash completions

bashcommand linedebug

I have created some bash completion functions that all appear to work in isolation but give me unexpected results when I attempt to tab complete with them.

Is it possible to connect bashdb, then attempt to tab complete something and step through to debug and determine what is going wrong?

Best Answer

set -x

If you set -x either in the interactive session or the autocomplete script itself, (nearly?) every command and its results will be printed out. This includes the work done inside the autocomplete script.

This can then be quieted back down again with set +x.

-x

After expanding each simple command, for command, case command, select command, or arithmetic for command, display the expanded value of PS4, followed by the command and its expanded arguments or associated word list.

-from Bash manual #The Set Builtin

Related Question