Jupyter Kernel Detection

The cell below is a piece of bash code used in Nextjournal to find kernel specifications within a specified environment. Running this cell against our default python 3 environment outputs IPython kernel specs as data.

DIR="share/jupyter/kernels/"
echo '[' > /results/kernels.json
first="true"
IFS=$'\n'
for path in "$HOME/.ipython/kernels" "$HOME/.local/$DIR" "/usr/$DIR" "/usr/local/$DIR" "/opt/conda/$DIR"; do
  if [ -d "$path" ]; then
    echo "searching in $path"
    for kernel in $(find "$path" -name kernel.json); do
      [ $first = "false" ] && echo ',' >> /results/kernels.json
      echo "found kernel at: $kernel"
      cat $kernel >> /results/kernels.json
      first="false"
    done
  fi
done
unset IFS
echo ']' >> /results/kernels.json
nil