I'd like a shortcut key for GEdit that will run the currently open .py file when I press, say, F5. I have a script that does this via an external Terminal window, but I'm having more trouble creating a version that uses the internal output window (Shell Output, I guess), since I can't find a good way to grab the pyenv details from the ~./bashrc file. Working with pyenv is mandatory.
Here's what I have via GEdit's External Tools plugin:
UNSOLVED: Internal Shell Output method:
I wanted to get access to the pyenv settings in ~./bashrc, so I tried this External Tools script:
#!/bin/bash
set +m
bash -i python $GEDIT_DOCUMENTS_PATH
This works (thanks to -i), but it gives me the "bash: no job control in this shell" warning. Running set +m should get rid of this message, but it doesn't.
So I moved the relevant stuff I had at the end of ~/.bashrc over to this script, which is not ideal at all:
#!/bin/bash
export PYENV_ROOT="${HOME}/.pyenv"
if [ -d "${PYENV_ROOT}" ]; then
export PATH="${PYENV_ROOT}/bin:${PATH}"
eval "$(pyenv init -)"
fi
export PYENV_VERSION=3.3.4
export LD_LIBRARY_PATH=~/.pyenv/versions/3.3.4/lib/python3.3/site-packages/PySide-1.2.1-py3.3.egg/PySide/
python $GEDIT_CURRENT_DOCUMENT_NAME
Problems: This last block is terrible. It's just copied from ~/.bashrc, and it even has to include PySide data that ~/.bashrc should take care of. Also, for some reason, using this method always outputs the first line of the .py file (say, import sys). Obviously, no input() can be given using this method, and outputting to GEdit's Embedded Terminal seems impossible. Also, I can't get rid of the "Done" message, even by using set +m or running the command in a subshell.
SOLVED: External Terminal window method:
#!/bin/sh
gnome-terminal -x $SHELL -ic "python $GEDIT_CURRENT_DOCUMENT_NAME; printf \"\nPress any key to continue.\"; read -n 1 -s"
or, define a Terminal profile called, say, Wait, that sets Title and Command->When terminal exits: Hold the terminal open, and do this:
#!/bin/sh
gnome-terminal --profile=Wait -x $SHELL -ic "python $GEDIT_CURRENT_DOCUMENT_NAME; printf \"\nPress any key to continue.\""
This gives a "status 0" message though, so the other method is better. Both methods use an interactive shell to access ~/.bashrc.