Skip to content

Instantly share code, notes, and snippets.

@spelufo
Last active August 29, 2015 13:56
Show Gist options
  • Save spelufo/9019033 to your computer and use it in GitHub Desktop.
Save spelufo/9019033 to your computer and use it in GitHub Desktop.
IPython/IJulia Notebook Launcher with tmux

IPython/IJulia Notebook Launcher with tmux

sudo apt-get install tmux

then create this shell scripts somewhere in your $PATH and chmod +x them.

#!/bin/bash

tmux new-session -d -s ipython && \
tmux send-keys -t ipython 'ipython notebook --no-browser --profile=santiago' Enter && \
notify-send IPython 'Notebook started: http://localhost:8888' || \
notify-send IPython 'Failed to start. Maybe it was already running: http://localhost:8888'
#!/bin/bash

tmux new-session -d -s ijulia && \
tmux send-keys -t ijulia 'ipython notebook --no-browser --profile=julia' Enter && \
notify-send IJulia 'Notebook started: http://localhost:8888' || \
notify-send IJulia 'Failed to start. Maybe it was already running: http://localhost:8888'

and finally create launchers for them. I did this from the cinnamon menu editor in linux mint.

Reattach to them with tmux attach.

The other files in this gist are an older method. It asked you for a folder from where to start the notebook. This new method always start from the home directory, thats how I like it.

xdg-open to open notebook on double click from file browser

Make an executable file:

#!/bin/bash


tmux new-session -d -s ipython && \
tmux send-keys -t ipython 'ipython notebook --no-browser --profile=santiago' Enter

URL=`echo "$1" | cut -d / -f 4-`

google-chrome "http://localhost:8888/notebooks/$URL"

and set it as the default application for .ipynb files

#!/bin/bash
# put this file somewhere in your path (eg. ~/bin/ipn) and then chmod +x ipn. Then put ipn.desktop in /usr/share/applications/
function ipnb() {
cwd=${PWD##*/}
if [ "$1" = '--gl' ]; then
shift; # take the $1 out of $@ so ipython doesnt crash on unknown flag.
screen -d -m -S "ipython_$cwd" ipython notebook --profile=santiago --browser="google-chrome --user-data-dir=/home/santiago/.config/google-chrome/WebGL/ %s" "$@"
echo " Starting ipyhton notebook and launching chrome with webGL enabled..."
else
screen -d -m -S "ipython_$cwd" ipython notebook --profile=santiago "$@"
echo " Starting ipyhton notebook..."
fi
}
if [ "$BASHRC_LOADED" ]; then # called from command line
ipnb "$@"
else # called without arguments, from launcher perhaps: prompt for folder.
export PATH="$PATH:/opt/anaconda/bin"
cwd=$(zenity --file-selection --title="Choose ipython notebooks directory...")
if [ "$?" = 0 ]; then
notify-send "IPython Notebook" "Preparing for awesome..." -i /opt/anaconda/glider.png
id=${cwd##*/}
screen -d -m -S "ipython_$id" ipython notebook --profile=santiago "$cwd/"
screen -R
else
notify-send "IPython Notebook" "Good bye!" -i /opt/anaconda/glider.png
fi
fi
[Desktop Entry]
Version=1.0
Type=Application
Terminal=false
Icon=/path/to/icon.png
Name=IPython Notebook
Exec=ipn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment