From bba5b16c6f1b3f76957af2e5f9e7c5afe95204fd Mon Sep 17 00:00:00 2001 From: Severin Kaderli Date: Wed, 8 Feb 2023 19:40:06 +0100 Subject: [PATCH] Get rid of old env script Signed-off-by: Severin Kaderli --- system/.config/custom/env | 42 --------------------- system/.config/environment.d/10_xdg.conf | 3 ++ system/.config/environment.d/40_shell.conf | 5 +++ system/.config/environment.d/50_nvidia.conf | 2 + system/.config/python/startup.py | 38 ++++++++++++------- system/.config/zsh/.zshrc | 18 ++++++--- 6 files changed, 46 insertions(+), 62 deletions(-) delete mode 100644 system/.config/custom/env create mode 100644 system/.config/environment.d/40_shell.conf create mode 100644 system/.config/environment.d/50_nvidia.conf diff --git a/system/.config/custom/env b/system/.config/custom/env deleted file mode 100644 index 49e3e8d..0000000 --- a/system/.config/custom/env +++ /dev/null @@ -1,42 +0,0 @@ -#!/bin/bash -# -# SCRIPT NAME: -# .env -# -# AUTHOR: -# Severin Kaderli -# -# DESCRIPTION: -# This file contains declarations of environment variables. -# -# USAGE: -# This script is sourced by .bashrc -# XDG_Base_Directories -# XDG Overrides for unsupported programs -export VIMINIT=":source ${XDG_CONFIG_HOME}/vim/vimrc" -export PYTHONSTARTUP="${XDG_CONFIG_HOME}/python/startup.py" - -# zsh -export HISTCONTROL=ignoreboth -export HISTSIZE=10000 -export SAVEHIST="${HISTSIZE}" -export HISTFILESIZE="${HISTSIZE}" - -# Ibus -export GTK_IM_MODULE=ibus -export XMODIFIERS=@im=ibus -export QT_IM_MODULE=ibus - -# NVIDIA -export __GL_SHADER_DISK_CACHE="1" -export __GL_SHADER_DISK_CACHE_SKIP_CLEANUP="1" - -mkdir -p "${__GL_SHADER_DISK_CACHE_PATH}" -mkdir -p "${XDG_DATA_HOME}/wine/prefixes" -mkdir -p "${XDG_CONFIG_HOME}/bazaar" -mkdir -p "${XDG_DATA_HOME}/zsh/zcompdump-${ZSH_VERSION}" -if [ -n "$(command -v compinit)" ]; then - compinit -d "${XDG_DATA_HOME}/zsh/zcompdump-${ZSH_VERSION}" -fi - -eval "$(starship init zsh)" diff --git a/system/.config/environment.d/10_xdg.conf b/system/.config/environment.d/10_xdg.conf index afe8ead..01d5d1d 100644 --- a/system/.config/environment.d/10_xdg.conf +++ b/system/.config/environment.d/10_xdg.conf @@ -21,6 +21,9 @@ GTK2_RC_FILES="${XDG_CONFIG_HOME}/gtk-2.0/gtkrc" WGETRC="${XDG_CONFIG_HOME}/wget/wgetrc" ZDOTDIR="${XDG_CONFIG_HOME}/zsh" NPM_CONFIG_USERCONFIG="${XDG_CONFIG_HOME}/npm/config" +_JAVA_OPTIONS="-Djava.util.prefs.userRoot=${XDG_CONFIG_HOME}/java" +PYTHONSTARTUP="${XDG_CONFIG_HOME}/python/startup.py" +VIMINIT=":source ${XDG_CONFIG_HOME}/vim/vimrc" # XDG Cache CUDA_CACHE_PATH="${XDG_CACHE_HOME}/nv" diff --git a/system/.config/environment.d/40_shell.conf b/system/.config/environment.d/40_shell.conf new file mode 100644 index 0000000..32f4351 --- /dev/null +++ b/system/.config/environment.d/40_shell.conf @@ -0,0 +1,5 @@ +# Zsh +HISTCONTROL="ignoreboth" +HISTSIZE="10000" +SAVEHIST="${HISTSIZE}" +HISTFILESIZE="${HISTSIZE}" \ No newline at end of file diff --git a/system/.config/environment.d/50_nvidia.conf b/system/.config/environment.d/50_nvidia.conf new file mode 100644 index 0000000..5b23d40 --- /dev/null +++ b/system/.config/environment.d/50_nvidia.conf @@ -0,0 +1,2 @@ +__GL_SHADER_DISK_CACHE="1" +__GL_SHADER_DISK_CACHE_SKIP_CLEANUP="1" \ No newline at end of file diff --git a/system/.config/python/startup.py b/system/.config/python/startup.py index e19684a..887d18e 100755 --- a/system/.config/python/startup.py +++ b/system/.config/python/startup.py @@ -1,20 +1,30 @@ -import atexit import os +import atexit import readline +from pathlib import Path -XDG_DATA_HOME = os.environ["XDG_DATA_HOME"] +if readline.get_current_history_length() == 0: + state_home = os.environ.get("XDG_STATE_HOME") + if state_home is None: + state_home = Path.home() / ".local" / "state" + else: + state_home = Path(state_home) -if not XDG_DATA_HOME: - histfile = os.path.join(os.path.expanduser( - "~"), ".local", "share", "python", "history") -else: - histfile = os.path.join(XDG_DATA_HOME, "python", "history") + history_path = state_home / "python_history" + if history_path.is_dir(): + raise OSError(f"'{history_path}' cannot be a directory") -try: - readline.set_auto_history(False) - readline.read_history_file(histfile) - readline.set_history_length(1000) -except FileNotFoundError: - pass + history = str(history_path) -atexit.register(readline.write_history_file, histfile) + try: + readline.read_history_file(history) + except OSError: # Non existent + pass + + def write_history(): + try: + readline.write_history_file(history) + except OSError: + pass + + atexit.register(write_history) diff --git a/system/.config/zsh/.zshrc b/system/.config/zsh/.zshrc index cc3a2e7..1359173 100644 --- a/system/.config/zsh/.zshrc +++ b/system/.config/zsh/.zshrc @@ -19,7 +19,6 @@ setopt INC_APPEND_HISTORY setopt SHARE_HISTORY unsetopt correct - # Zsh keybindings # Ctrl + Left @@ -42,11 +41,6 @@ zstyle ':completion:*' menu select # Persistent rehash zstyle ':completion:*' rehash true -# Sourcing environment variables -if [ -f "${HOME}/.config/custom/env" ]; then - . "${HOME}/.config/custom/env" -fi - # Enable color support of ls if [ -f "${XDG_CONFIG_HOME}/custom/dircolors" ]; then dircolors -b "${XDG_CONFIG_HOME}/custom/dircolors" > /dev/null 2>&1 @@ -57,6 +51,18 @@ if [ -f "${XDG_CONFIG_HOME}/custom/aliases" ]; then . "${XDG_CONFIG_HOME}/custom/aliases" fi +# Create necessary directories +mkdir -p "${__GL_SHADER_DISK_CACHE_PATH}" +mkdir -p "${XDG_DATA_HOME}/wine/prefixes" +mkdir -p "${XDG_CONFIG_HOME}/bazaar" +mkdir -p "${XDG_STATE_HOME}/zsh" +mkdir -p "${XDG_DATA_HOME}/zsh/zcompdump-${ZSH_VERSION}" +if [ -n "$(command -v compinit)" ]; then + compinit -d "${XDG_DATA_HOME}/zsh/zcompdump-${ZSH_VERSION}" +fi + +# Initialize prompt +eval "$(starship init zsh)" # Plugins source "/usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh"