summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.yaml7
-rw-r--r--dotfiles/pam_environment5
-rw-r--r--dotfiles/programming/python/startup_script.py52
3 files changed, 64 insertions, 0 deletions
diff --git a/config.yaml b/config.yaml
index f33b6eb..9d544f4 100644
--- a/config.yaml
+++ b/config.yaml
@@ -118,6 +118,9 @@ dotfiles:
118 prog_nodejs_npm: 118 prog_nodejs_npm:
119 dst: ~/.config/npm/npmrc 119 dst: ~/.config/npm/npmrc
120 src: programming/nodejs/npmrc 120 src: programming/nodejs/npmrc
121 prog_python_startup:
122 dst: ~/.config/python/startup_script.py
123 src: programming/python/startup_script.py
121 remind_0_service: 124 remind_0_service:
122 actions: 125 actions:
123 - systemd_daemon_reload 126 - systemd_daemon_reload
@@ -171,6 +174,7 @@ profiles:
171 include: 174 include:
172 - _prog_haskell 175 - _prog_haskell
173 - _prog_nodejs 176 - _prog_nodejs
177 - _prog_python
174 _git: 178 _git:
175 dotfiles: 179 dotfiles:
176 - git_config_files 180 - git_config_files
@@ -198,6 +202,9 @@ profiles:
198 _prog_nodejs: 202 _prog_nodejs:
199 dotfiles: 203 dotfiles:
200 - prog_nodejs_npm 204 - prog_nodejs_npm
205 _prog_python:
206 dotfiles:
207 - prog_python_startup
201 _shell_bash: 208 _shell_bash:
202 dotfiles: 209 dotfiles:
203 - shell_bash_profile 210 - shell_bash_profile
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_