scripts: Refactor py script
Made detection and setup a little more stable, will still have its kinks since it is rather hastily put together but should work for detecting kernels, invoking the right python repl and letting you set it manually with `py -c`.
This commit is contained in:
parent
029b38f368
commit
4dadcd5f9f
1 changed files with 52 additions and 27 deletions
|
@ -5,7 +5,39 @@ 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)
|
||||
cmd_explicit=$(echo -e "euporie-console\njupyter-console\nptipython\nipython\npython" | fzf)
|
||||
fi
|
||||
|
||||
# search for molten session for current dir
|
||||
if [ -n "$(ls -A "${search_dir}" 2>/dev/null)" ]; then
|
||||
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
|
||||
|
@ -22,22 +54,15 @@ if [ -z "$cmd" ]; then
|
|||
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
|
||||
if exist euporie-console; then
|
||||
euporie-console --edit-mode vi --connection-file "$session"
|
||||
elif exist jupyter-console || [ "$cmd" == "jupyter-console" ]; then
|
||||
exit 0
|
||||
elif exist jupyter-console; then
|
||||
jupyter-console --existing "$session"
|
||||
exit 0
|
||||
fi
|
||||
# or just run normal python
|
||||
else
|
||||
$cmd
|
||||
fi
|
||||
# or just run normal python
|
||||
$cmd
|
||||
|
|
Loading…
Reference in a new issue