summaryrefslogtreecommitdiff
path: root/dotfiles
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@fretlink.com>2018-10-28 11:42:18 +0100
committerIsmaël Bouya <ismael.bouya@fretlink.com>2018-10-28 11:42:18 +0100
commit3cfba3158e3e4801f63abd5f05ac48a0008b72b9 (patch)
treeedb206cd7c94e550fb386063a2c31fe3465c9d00 /dotfiles
parentd5458026c4d8559d883cac11e632ac30b15f3d8f (diff)
downloaddotdrop-3cfba3158e3e4801f63abd5f05ac48a0008b72b9.tar.gz
dotdrop-3cfba3158e3e4801f63abd5f05ac48a0008b72b9.tar.zst
dotdrop-3cfba3158e3e4801f63abd5f05ac48a0008b72b9.zip
Add python script
Diffstat (limited to 'dotfiles')
-rw-r--r--dotfiles/pam_environment5
-rw-r--r--dotfiles/programming/python/startup_script.py52
2 files changed, 57 insertions, 0 deletions
diff --git a/dotfiles/pam_environment b/dotfiles/pam_environment
index 09172e1..02741ba 100644
--- a/dotfiles/pam_environment
+++ b/dotfiles/pam_environment
@@ -16,6 +16,11 @@ VISUAL DEFAULT="vim"
16PAGER DEFAULT="less" 16PAGER DEFAULT="less"
17BROWSER DEFAULT="firefox" 17BROWSER DEFAULT="firefox"
18 18
19# Python
20IPYTHONDIR DEFAULT="${XDG_CONFIG_HOME}/ipython"
21JUPYTER_CONFIG_DIR DEFAULT="${XDG_CONFIG_HOME}/jupyter"
22PYTHONSTARTUP DEFAULT="${XDG_CONFIG_HOME}/python/startup_script.py"
23
19# VIM 24# VIM
20VIMINIT DEFAULT=":source ${XDG_CONFIG_HOME}/vim/vimrc" 25VIMINIT DEFAULT=":source ${XDG_CONFIG_HOME}/vim/vimrc"
21 26
diff --git a/dotfiles/programming/python/startup_script.py b/dotfiles/programming/python/startup_script.py
new file mode 100644
index 0000000..403afe5
--- /dev/null
+++ b/dotfiles/programming/python/startup_script.py
@@ -0,0 +1,52 @@
1import sys as sys_
2
3# Adapted from /usr/lib/python3.7/site.py # enablerlcompleter
4def register_readline():
5 import os
6 import atexit
7 try:
8 import readline
9 import rlcompleter
10 except ImportError:
11 return
12
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')
18 else:
19 readline.parse_and_bind('tab: complete')
20
21 try:
22 readline.read_init_file()
23 except OSError:
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.
28 pass
29
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")
41 else:
42 history = os.path.join(os.path.expanduser('~'),
43 '.python_history')
44 try:
45 readline.read_history_file(history)
46 except OSError:
47 pass
48 atexit.register(readline.write_history_file, history)
49
50sys_.__interactivehook__ = register_readline
51
52del sys_