Created
May 29, 2014 20:28
-
-
Save kbambz/5882c6becd3f8d5961c6 to your computer and use it in GitHub Desktop.
~/.pythonrc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # ~/.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