Debugging Completion Scripts - oilshell/oil GitHub Wiki

(Back to Contributing)

Context: Running Bash Completion Scripts with OSH

Related: How To Test OSH

Reading and debugging completion scripts is difficult. Here is a way OSH helps. This can certainly be improved.

It helps to open two tmux panes, or two terminals side-by-side. Then you can type on the left and see debug logs on the right.

$ mkfifo _tmp/debug  # named pipe

$ misc/complete.sh osh-trace     # do this on the LEFT.  
                                 # Type commands here like 'source testdata/completion/git'.
$ cat _tmp/debug                 # do this on the RIGHT.

For reference, this is the osh-trace function:

osh-trace() {
  env -i OSH_CRASH_DUMP_DIR=_tmp PS4='+[${LINENO}:${FUNCNAME[0]}] ' \
    bin/osh -x --debug-file _tmp/debug --xtrace-to-debug-file "$@"
}

It uses -x / xtrace and $PS4 to display logs. And it redirects -x output to _tmp/debug.