User Tools

Site Tools

Advanced Scientific Programming in Python

a Summer School by the G-Node and the Physik-Institut, University of Zurich


setup

Settinng up python for tab-completion and history

Setting up python so that pressing TAB autocompletes words, and so that after restarting python, one can use ↑ to access old entries.

You can just paste the whole block below into a shell.

# This script will try not to make changes twice, so it
# should be safe to run it more than once.
 
# turn colors on git
git config --global color.ui auto
 
# add ssh shortcut for multicore exercises
if ! grep -q sgi1 ~/.ssh/config &>/dev/null; then
(umask 0077;
mkdir -p ~/.ssh
cat >>~/.ssh/config <<EOF
Host sgi01
     HostName sgi1.cg3
     ProxyCommand ssh login.gc3.uzh.ch nc -w 20 %h %p
EOF
)
fi
 
# create .pythonrc
if ! test -f ~/.pythonrc &>/dev/null; then
cat >~/.pythonrc <<EOF
#from __future__ import division, print_function
#del division, print_function
 
import readline, rlcompleter
readline.parse_and_bind("tab: complete")
 
import os, atexit
histfile = os.path.join(os.environ["HOME"], ".pyhist")
try:
    readline.read_history_file(histfile)
except IOError:
    pass
atexit.register(readline.write_history_file, histfile)
del readline, rlcompleter, os, atexit, histfile
EOF
fi
 
# create .bashrc
if ! grep -q PYTHONSTARTUP ~/.bashrc &>/dev/null; then
cat >>~/.bashrc <<"EOF"
export PYTHONSTARTUP=$HOME/.pythonrc
HISTFILESIZE=100000
HISTSIZE=100000
PS1='\[\033[01;32m\]\u@\h\[\033[00m\] \[\033[01;34m\]\w\[\033[00m\]\[\033[01;35m\]$(__git_ps1 " (% s)")\[\033[00m\]$ '
 
# beginners aliases
alias rm='rm -i'
alias mv='mv -i'
alias cp='cp -i'
 
EOF
fi
 
# restart bash
exec bash
 
# we are missing one package
sudo apt-get install -y python-coverage gitk
 
setup.txt · Last modified: 2013/09/04 16:04 by zbyszek

Page Tools