aboutsummaryrefslogtreecommitdiff
path: root/config
diff options
context:
space:
mode:
authorCharles Cabergs <me@cacharle.xyz>2021-02-28 13:58:17 +0100
committerCharles Cabergs <me@cacharle.xyz>2021-02-28 13:58:17 +0100
commit757a8eb53de15124a149f2c9e13ec64f07c100a9 (patch)
tree7f63c6117e0ee0b329cecbec0390f10e18206b4f /config
parentd7f0a32d7c5f6935c08f9c4adcab76c1fdc16c78 (diff)
downloaddotfiles-757a8eb53de15124a149f2c9e13ec64f07c100a9.tar.gz
dotfiles-757a8eb53de15124a149f2c9e13ec64f07c100a9.tar.bz2
dotfiles-757a8eb53de15124a149f2c9e13ec64f07c100a9.zip
Added python startup script to avoid writting python interpretor hisotry in ~/.python_history
Diffstat (limited to 'config')
-rw-r--r--config/python/startup.py64
-rw-r--r--config/qutebrowser/config.py2
-rwxr-xr-xconfig/zsh/zprofile4
3 files changed, 68 insertions, 2 deletions
diff --git a/config/python/startup.py b/config/python/startup.py
new file mode 100644
index 0000000..900a568
--- /dev/null
+++ b/config/python/startup.py
@@ -0,0 +1,64 @@
+#!/usr/bin/env python3
+
+import os
+import sys
+from pathlib import Path
+
+
+def register_readline():
+ import atexit
+ try:
+ import readline
+ except ImportError:
+ return
+
+ # Reading the initialization (config) file may not be enough to set a
+ # completion key, so we set one first and then read the file.
+ readline_doc = getattr(readline, '__doc__', '')
+ if readline_doc is not None and 'libedit' in readline_doc:
+ readline.parse_and_bind('bind ^I rl_complete')
+ else:
+ readline.parse_and_bind('tab: complete')
+
+ try:
+ readline.read_init_file()
+ except OSError:
+ # An OSError here could have many causes, but the most likely one
+ # is that there's no .inputrc file (or .editrc file in the case of
+ # Mac OS X + libedit) in the expected location. In that case, we
+ # want to ignore the exception.
+ pass
+
+ if readline.get_current_history_length() == 0:
+ # If no history was loaded, default to .python_history.
+ # The guard is necessary to avoid doubling history size at
+ # each interpreter exit when readline was already configured
+ # through a PYTHONSTARTUP hook, see:
+ # http://bugs.python.org/issue5845#msg198636
+ history = ""
+ if "XDG_CACHE_HOME" in os.environ:
+ history = Path(os.environ["XDG_CACHE_HOME"]) / "python" / "history"
+ history.parent.mkdir(parents=True, exist_ok=True)
+ else:
+ history = os.path.join(os.path.expanduser('~'),
+ '.python_history')
+ try:
+ readline.read_history_file(history)
+ except OSError:
+ pass
+
+ def write_history():
+ try:
+ readline.write_history_file(history)
+ except OSError:
+ # bpo-19891, bpo-41193: Home directory does not exist
+ # or is not writable, or the filesystem is read-only.
+ pass
+
+ atexit.register(write_history)
+
+
+sys.__interactivehook__ = register_readline
+
+sys.ps1 = "> "
+sys.ps2 = ". "
diff --git a/config/qutebrowser/config.py b/config/qutebrowser/config.py
index 2bf8d19..55da493 100644
--- a/config/qutebrowser/config.py
+++ b/config/qutebrowser/config.py
@@ -39,7 +39,7 @@ c.url.searchengines = {
}
-c.fonts.default_family = ['Fira Mono', 'Baekmuk']
+c.fonts.default_family = ['Fira Mono', 'Baekmuk', 'Symbola']
c.fonts.hints = 'bold 11pt default_family'
c.hints.chars = 'asdfghjkl;' # use key in the main row for hints
diff --git a/config/zsh/zprofile b/config/zsh/zprofile
index c18b368..e18025d 100755
--- a/config/zsh/zprofile
+++ b/config/zsh/zprofile
@@ -21,6 +21,7 @@ export XMONAD_CACHE_HOME="$XDG_CACHE_HOME/xmonad"
export ZDOTDIR="$XDG_CONFIG_HOME/zsh"
export XINITRC="$XDG_CONFIG_HOME/x11/xinitrc"
export INPUTRC="$XDG_CONFIG_HOME/readline/inputrc"
+export PYTHONSTARTUP="$XDG_CONFIG_HOME/python/startup.py"
# shellcheck disable=SC2016
export VIMINIT='let $MYVIMRC="$XDG_CONFIG_HOME/vim/vimrc" | source $MYVIMRC'
export IPYTHONDIR="$XDG_CONFIG_HOME/ipython"
@@ -32,6 +33,7 @@ export CARGO_HOME="$XDG_DATA_HOME/cargo"
# cache
export HISTFILE="$XDG_CACHE_HOME/history"
export LESSHISTFILE='-' # no ~/.lesshst
+export PYTHON_EGG_CACHE="$XDG_CACHE_HOME/python-eggs"
# runtime
export XAUTHORITY="$XDG_RUNTIME_DIR/Xauthority"
@@ -53,4 +55,4 @@ export LESS_TERMCAP_ZW=$(tput rsupm)
export MINIKUBE_IN_STYLE=false # disable cringe minikube emojies
-[ "$(tty)" = '/dev/tty1' ] && startx ; poweroff
+[ "$(tty)" = '/dev/tty1' ] && { startx ; poweroff; }