2023-12-05 20:24:33 +00:00
|
|
|
#!/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
|
2023-12-12 11:23:21 +00:00
|
|
|
cmd_explicit=$(echo -e "euporie-console\njupyter-console\nptipython\nipython\npython" | fzf)
|
2023-12-05 20:24:33 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# search for molten session for current dir
|
|
|
|
if [ -n "$(ls -A "${search_dir}" 2>/dev/null)" ]; then
|
2023-12-12 11:23:21 +00:00
|
|
|
session=$(find "$search_dir" -maxdepth 1 -type f -name "*.json")
|
|
|
|
if [ "$(echo "$session" | wc -l)" -gt 1 ]; then
|
|
|
|
session=$(echo "$session" | fzf --prompt "Molten session> ")
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$cmd_explicit" ] && not exist "$cmd_explicit"; then
|
|
|
|
echo "Command $cmd_explicit not found."
|
|
|
|
exit 1
|
|
|
|
elif [ "$cmd_explicit" == "euporie-console" ]; then
|
|
|
|
if [ -n "$session" ]; then
|
|
|
|
euporie-console --edit-mode vi --connection-file "$session"
|
|
|
|
else
|
|
|
|
echo "Starting euporie without a session to attach to."
|
|
|
|
euporie-console --edit-mode vi
|
|
|
|
fi
|
|
|
|
exit 0
|
|
|
|
elif [ "$cmd_explicit" == "jupyter-console" ]; then
|
|
|
|
if [ -n "$session" ]; then
|
|
|
|
jupyter-console --existing "$session"
|
|
|
|
else
|
|
|
|
echo "Starting jupyter console without a session to attach to."
|
|
|
|
jupyter-console
|
|
|
|
fi
|
|
|
|
exit 0
|
|
|
|
elif [ -n "$cmd_explicit" ]; then
|
|
|
|
"$cmd_explicit"
|
|
|
|
exit 0
|
|
|
|
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
|
2023-12-05 20:24:33 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# attach to kernel
|
|
|
|
if [ -n "${session}" ]; then
|
2023-12-12 11:23:21 +00:00
|
|
|
if exist euporie-console; then
|
|
|
|
euporie-console --edit-mode vi --connection-file "$session"
|
|
|
|
exit 0
|
|
|
|
elif exist jupyter-console; then
|
|
|
|
jupyter-console --existing "$session"
|
|
|
|
exit 0
|
|
|
|
fi
|
2023-12-05 20:24:33 +00:00
|
|
|
fi
|
2023-12-12 11:23:21 +00:00
|
|
|
# or just run normal python
|
|
|
|
$cmd
|