Skip to content

Instantly share code, notes, and snippets.

@kbambz
Created May 29, 2014 20:28
Show Gist options
  • Select an option

  • Save kbambz/5882c6becd3f8d5961c6 to your computer and use it in GitHub Desktop.

Select an option

Save kbambz/5882c6becd3f8d5961c6 to your computer and use it in GitHub Desktop.
~/.pythonrc
# ~/.pythonrc
import readline, rlcompleter
### Indenting
class TabCompleter(rlcompleter.Completer):
"""Completer that supports indenting"""
def complete(self, text, state):
if not text:
return (' ', None)[state]
else:
return rlcompleter.Completer.complete(self, text, state)
readline.set_completer(TabCompleter().complete)
### Add autocompletion
if 'libedit' in readline.__doc__:
readline.parse_and_bind("bind -e")
readline.parse_and_bind("bind '\t' rl_complete")
else:
readline.parse_and_bind("tab: complete")
### Add history
import os
histfile = os.path.join(os.environ["HOME"], ".pyhist")
try:
readline.read_history_file(histfile)
except IOError:
pass
import atexit
atexit.register(readline.write_history_file, histfile)
del histfile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment