dotfiles/scripts/.local/bin/py
Marty Oehme c487da69a8
nvim: Add molten and image.nvim plugins
Image nvim works mostly well (slow on wezterm but that will always be the case
with kitty protocol for now as far as I know).
Would love to be able to toggle images on/off dynamically but I don't see a
way to accomplish that now. (or really, get to any option of the plugin).

Molten itself also works well - the output is displayed more nicely than for
the Magma plugins and everything continues working mostly well (or rather,
just as wonky as I had it set up on my older magma install :)

For now, the molten - image.nvim integration seems to not work at all -
it simply errors out when it would produce an image as output. No clue why
and it also complains about the wrong image provider (which I have taken from
the molten readme). No time to bugfix now but maybe at some point.

To do - find a much better way of installing the image.nvim required
luarock magick - done manually with hardcoded path in setup now

Also extended the old `py` alias to a full-blown script which will in
addition to detecting the python repl also find any running molten
session for the current directory (i.e. any running jupy kernel) and let
the user choose the right one if there is multiple. Will then default to
starting a kernel-aware repl environment (euporia or jupyter-console).

Added a very simple `-c` option which lets you choose python command to
run manually.
2023-12-12 12:07:41 +01:00

43 lines
1.2 KiB
Bash
Executable file

#!/usr/bin/env bash
molten_session_dir="/run/user/$UID/molten-sessions"
cur_dir=$(pwd)
search_dir="${molten_session_dir}${cur_dir}"
if [ "$1" == "-c" ]; then
cmd=$(echo -e "euporie-console\njupyter-console\nptipython\nipython\npython" | fzf)
fi
# set normal command first
if [ -z "$cmd" ]; then
if exist ptipython; then
cmd=ptipython
elif exist ipython; then
cmd=ipython
elif exist python; then
cmd=python
else
echo "No python found on system, please install." 1>&2
exit 1
fi
fi
# search for molten session for current dir
if [ -n "$(ls -A "${search_dir}" 2>/dev/null)" ]; then
res=$(find "$search_dir" -maxdepth 1 -type f -name "*.json")
if [ "$(echo "$res" | wc -l)" -gt 1 ]; then
session=$(echo "$res" | fzf --prompt "Molten session> ")
fi
fi
# attach to kernel
if [ -n "${session}" ]; then
if exist euporie-console || [ "$cmd" == "euporie-console" ]; then
euporie-console --edit-mode vi --connection-file "$session"
elif exist jupyter-console || [ "$cmd" == "jupyter-console" ]; then
jupyter-console --existing "$session"
fi
# or just run normal python
else
$cmd
fi