Skip to content

Instantly share code, notes, and snippets.

@tkanmae
Last active December 18, 2015 00:28
Show Gist options
  • Save tkanmae/5696513 to your computer and use it in GitHub Desktop.
Save tkanmae/5696513 to your computer and use it in GitHub Desktop.
Call ipython with a per-project profile. It assumes that .ipython directory is in the top level directory managed by git.
#!/usr/bin/env bash
# Call ipython with a per-project profile. It assumes that .ipython directory
# is in the top level directory of a project managed by git.
function ipython() {
local project_root_dir
# If the user specifies `IPYTHONDIR` either by giving --ipython-dir
# option or by an environmental variable IPYTHONDIR, then the specified
# directory should have precedence over per-project `IPYTHONDIR`.
if [[ $* =~ --ipython-dir || -n $IPYTHONDIR ]]; then
command ipython $*
else
project_root_dir=$(git rev-parse --show-toplevel 2>/dev/null)
if [[ -d "$project_root_dir/.ipython" ]]; then
command ipython $* --ipython-dir="$project_root_dir/.ipython"
else
command ipython $*
fi
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment