]>
git.immae.eu Git - perso/Immae/Config/Ansible.git/blob - roles/programming/python/files/startup_script.py
403afe58d2fd08353cced04a5d93077f939d7422
3 # Adapted from /usr/lib/python3.7/site.py # enablerlcompleter
4 def register_readline():
13 # Reading the initialization (config) file may not be enough to set a
14 # completion key, so we set one first and then read the file.
15 readline_doc
= getattr(readline
, '__doc__', '')
16 if readline_doc
is not None and 'libedit' in readline_doc
:
17 readline
.parse_and_bind('bind ^I rl_complete')
19 readline
.parse_and_bind('tab: complete')
22 readline
.read_init_file()
24 # An OSError here could have many causes, but the most likely one
25 # is that there's no .inputrc file (or .editrc file in the case of
26 # Mac OS X + libedit) in the expected location. In that case, we
27 # want to ignore the exception.
30 if readline
.get_current_history_length() == 0:
31 # If no history was loaded, default to .python_history.
32 # The guard is necessary to avoid doubling history size at
33 # each interpreter exit when readline was already configured
34 # through a PYTHONSTARTUP hook, see:
35 # http://bugs.python.org/issue5845#msg198636
36 environ
= os
.environ
.get("XDG_STATE_HOME") or os
.environ
.get("XDG_DATA_HOME")
37 if environ
is not None:
38 if not os
.path
.exists(os
.path
.join(environ
, "python")):
39 os
.mkdir(os
.path
.join(environ
, "python"))
40 history
= os
.path
.join(environ
, "python", "history")
42 history
= os
.path
.join(os
.path
.expanduser('~'),
45 readline
.read_history_file(history
)
48 atexit
.register(readline
.write_history_file
, history
)
50 sys_
.__interactivehook
__ = register_readline