Skip to content

Instantly share code, notes, and snippets.

@laughk
Last active August 5, 2017 17:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laughk/12bb6e1fde485fe4e5b8 to your computer and use it in GitHub Desktop.
Save laughk/12bb6e1fde485fe4e5b8 to your computer and use it in GitHub Desktop.
python インタラクティブシェルで補完とhistoryを取得する奴

メモ

  • ~/.pythonstartup.py とか適当に置く

  • ~/.zshrc なり ~/.bashrc なりに以下を追記

    export PYTHONSTARTUP=${HOME}/.pythonstartup.py
  • インタラクティブシェルで補完が出来て ~/.python_history に history 出るよ

# -*- coding:utf-8 -*-
# Python startup file
import readline
import rlcompleter
import atexit
import os
# tab complete
readline.parse_and_bind('tab: complete')
# history file
histfile = os.path.join(os.environ['HOME'], '.python_history')
try:
readline.read_history_file(histfile)
except IOError:
pass
atexit.register(readline.write_history_file, histfile)
del os, histfile, readline, rlcompleter, atexit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment