diff --git a/.bashrc b/.bashrc index 2f33f1e..c9687e4 100644 --- a/.bashrc +++ b/.bashrc @@ -40,7 +40,7 @@ shopt -s checkwinsize # Set these environment variables here (and not in ~/.profile) # due to conflict/overlap with zsh -export HISTFILE="$HOME/.bash_history" +export HISTFILE="$XDG_STATE_HOME/bash/history" export HISTSIZE=999999 # number of lines kept in memory export HISTFILESIZE=999999 # number of lines kept in $HISTFILE diff --git a/.gitconfig b/.config/git/config similarity index 100% rename from .gitconfig rename to .config/git/config diff --git a/.psqlrc b/.config/psql/psqlrc similarity index 91% rename from .psqlrc rename to .config/psql/psqlrc index 2ed95c7..cec074d 100644 --- a/.psqlrc +++ b/.config/psql/psqlrc @@ -22,7 +22,8 @@ -- Use separate history files per database and -- keep them in one folder (for easier sync with mackup) -\set HISTFILE ~/.config/psql/.psql_history- :DBNAME +-- under $XDG_STATE_HOME/psql +\set HISTFILE ~/.local/state/psql/history- :DBNAME -- Don't store the same SQL statement repeatedly \set HISTCONTROL ignoredups diff --git a/.config/python/pythonrc b/.config/python/pythonrc new file mode 100644 index 0000000..9dd9198 --- /dev/null +++ b/.config/python/pythonrc @@ -0,0 +1,33 @@ +# This file moves Python's history file to $XDG_STATE_HOME/python/history +# Adapted from: https://unix.stackexchange.com/questions/630642/change-location-of-python-history + +import os +import atexit +import readline +from pathlib import Path + +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) + + history_path = state_home / "python" / "history" + if history_path.is_dir(): + raise OSError(f"'{history_path}' cannot be a directory") + + history = str(history_path) + + 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/.config/shell/aliases.d/generic.sh b/.config/shell/aliases.d/generic.sh index f5838df..7b365be 100644 --- a/.config/shell/aliases.d/generic.sh +++ b/.config/shell/aliases.d/generic.sh @@ -56,7 +56,7 @@ _command_exists exa && alias exa='exa --group-directories-first --git --time-sty _command_exists netstat && alias ports='netstat -tulanp' _command_exists screenfetch && alias screenfetch='screenfetch -n' alias uptime='uptime --pretty' -alias wget='wget --continue' +alias wget="wget --continue --hsts-file=$XDG_STATE_HOME/wget/history" # Create shorter aliases for various utilities diff --git a/.config/shell/init_dotfiles.sh b/.config/shell/init_dotfiles.sh index e18dcee..fe27222 100755 --- a/.config/shell/init_dotfiles.sh +++ b/.config/shell/init_dotfiles.sh @@ -1,4 +1,8 @@ -# This file initializes the ~/.dotfiles as a bare repository +# This file sets up the $XDG_DATA_HOME/dotfiles, a bare git repository, +# such that they are available within a user's $HOME as common "dotfiles" + + +export XDG_DATA_HOME="$HOME/.local/share" # temporarily set here; mainly set in ~/.profile _command_exists() { @@ -14,14 +18,27 @@ rm -rf "$HOME/.dotfiles" >/dev/null git clone --bare https://code.webartifex.biz/alexander/dotfiles.git "$HOME/.dotfiles" # Distribute the dotfiles in $HOME -git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME checkout --force -git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME config --local status.showUntrackedFiles no +git --git-dir=$XDG_DATA_HOME/dotfiles/ --work-tree=$HOME checkout --force +git --git-dir=$XDG_DATA_HOME/dotfiles/ --work-tree=$HOME config --local status.showUntrackedFiles no +# Dirty Fix: Otherwise `gnupg` emits a warning +[ -d "$XDG_DATA_HOME/gnupg" ] && chmod 700 $XDG_DATA_HOME/gnupg if _command_exists zsh; then + # Set the $ZDOTDIR in /etc[/zsh]/zshenv if that is not already done + # Notes: + # - must use $HOME as $XDG_CONFIG_HOME is not yet set + # - on Fedora, the global config files are not in /etc/zsh but in /etc + export ZDOTDIR="$HOME/.config/zsh" + for _file in '/etc/zshenv' '/etc/zsh/zshenv'; do + if [ -f $_file ]; then + grep -q -F "export ZDOTDIR" $_file || echo 'export ZDOTDIR="$HOME"/.config/zsh' | sudo tee -a $_file + fi + done + # (Re-)Install oh-my-zsh - export ZSH="$HOME/.oh-my-zsh" + export ZSH="$XDG_DATA_HOME/oh-my-zsh" # temporarily set here; mainly set in $XDG_CONFIG_HOME/zsh/.zshenv rm -rf $ZSH >/dev/null # Let's NOT use the main repository but our personal fork git clone --origin fork --branch forked https://code.webartifex.biz/alexander/oh-my-zsh.git $ZSH @@ -30,16 +47,19 @@ if _command_exists zsh; then cd $HOME # (Re-)Install zplug - export ZPLUG_HOME="$HOME/.zplug" + export ZPLUG_HOME="$XDG_DATA_HOME/zplug" # temporarily set here; mainly set in $XDG_CONFIG_HOME/zsh/.zshenv rm -rf $ZPLUG_HOME >/dev/null git clone https://github.com/zplug/zplug $ZPLUG_HOME - - # Set up all the zplug plugins (-i so that the new ~/.zshrc is sourced) + # Set up all the zplug plugins (-i so that the new $XDG_CONFIG_HOME/zsh/.zshrc is sourced) zsh -i -c "zplug install" fi +# Disable the creation of ~/.sudo_as_admin_successful +echo 'Defaults !admin_flag' | sudo tee /etc/sudoers.d/disable_admin_note + + echo echo "Probably it's a good idea to restart the shell" echo "Make sure to start bash or zsh as a login shell the next time" diff --git a/.config/shell/utils.d/update.sh b/.config/shell/utils.d/update.sh index a981503..5d4fb5e 100644 --- a/.config/shell/utils.d/update.sh +++ b/.config/shell/utils.d/update.sh @@ -57,7 +57,7 @@ _update_repositories() { ZSH_DOTENV_FILE='.env' - _command_exists pass && echo "Fetching $HOME/.password-store" && pass git pull + _command_exists pass && echo "Fetching $XDG_DATA_HOME/pass" && pass git pull _update_dotfiles cd $cwd diff --git a/.vim/after/ftplugin/python.vim b/.config/vim/after/ftplugin/python.vim similarity index 100% rename from .vim/after/ftplugin/python.vim rename to .config/vim/after/ftplugin/python.vim diff --git a/.vim/backup/.gitkeep b/.config/vim/spell/.gitkeep similarity index 100% rename from .vim/backup/.gitkeep rename to .config/vim/spell/.gitkeep diff --git a/.vim/vimrc b/.config/vim/vimrc similarity index 95% rename from .vim/vimrc rename to .config/vim/vimrc index 30464dd..05bb49a 100644 --- a/.vim/vimrc +++ b/.config/vim/vimrc @@ -5,8 +5,9 @@ " Use VIM improved mode set nocompatible + " Set environment variables for convenient usage -let $RC="$HOME/.vim/vimrc" +let $RC="$XDG_CONFIG_HOME/vim/vimrc" let $RTP=split(&runtimepath, ',')[0] " Disable VIM's startup message @@ -39,13 +40,13 @@ set hidden set path=.,** -" Store all vim-related working files in the ~/.vim folder -set viminfo+=n~/.vim/viminfo +" Store all vim-related working files in the ~/.local/state/vim folder +set viminfo+=n$XDG_STATE_HOME/vim/viminfo " Use dedicated folders to store temporary backup, swap, and undo files " (the // means that VIM adapts names automatically to avoid duplicates) -set backupdir=~/.vim/backup// -set directory=~/.vim/swap// -set undodir=~/.vim/undo// +set backupdir=$XDG_STATE_HOME/vim/backup// +set directory=$XDG_STATE_HOME/vim/swap// +set undodir=$XDG_STATE_HOME/vim/undo// " To disable any of the temporary files, uncomment one of the following " set nobackup @@ -54,6 +55,9 @@ set undodir=~/.vim/undo// " set noundofile +set runtimepath+=$XDG_CONFIG_HOME/vim,$XDG_CONFIG_HOME/vim/after,$VIM,$VIMRUNTIME + + " Show the filename in the terminal window's title bar set title diff --git a/.p10k.zsh b/.config/zsh/.p10k.zsh similarity index 100% rename from .p10k.zsh rename to .config/zsh/.p10k.zsh diff --git a/.zlogout b/.config/zsh/.zlogout similarity index 100% rename from .zlogout rename to .config/zsh/.zlogout diff --git a/.zprofile b/.config/zsh/.zprofile similarity index 100% rename from .zprofile rename to .config/zsh/.zprofile diff --git a/.zshenv b/.config/zsh/.zshenv similarity index 83% rename from .zshenv rename to .config/zsh/.zshenv index 2b53214..ce96390 100644 --- a/.zshenv +++ b/.config/zsh/.zshenv @@ -2,8 +2,14 @@ # (it's kind of a zsh-only ~/.profile file) -export ZSH="$HOME/.oh-my-zsh" -export ZPLUG_HOME="$HOME/.zplug" +export XDG_CONFIG_HOME="$HOME/.config" +export XDG_DATA_HOME="$HOME/.local/share" + + +export ZDOTDIR="$XDG_CONFIG_HOME/zsh" +export ZSH="$XDG_DATA_HOME/oh-my-zsh" +export ZPLUG_HOME="$XDG_DATA_HOME/zplug" +export _Z_DATA="$XDG_DATA_HOME/z" # Use key to auto-complete a partially typed command @@ -32,4 +38,3 @@ export ZSH_COMPDUMP="${XDG_CACHE_HOME:-$HOME/.cache}/.zcompdump-$HOST-$ZSH_VERSI # Automatically source ".env" files in folders # Source: https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/dotenv export ZSH_DOTENV_FILE=".env" - diff --git a/.zshrc b/.config/zsh/.zshrc similarity index 93% rename from .zshrc rename to .config/zsh/.zshrc index f6e535c..cf8359c 100644 --- a/.zshrc +++ b/.config/zsh/.zshrc @@ -52,8 +52,8 @@ unalias -a # Set these environment variables here (and not in ~/.profile) # due to conflict/overlap with bash -# Can NOT be $HOME/.zhistory as zsh destroys mackup's symbolic link -export HISTFILE="$HOME/data/getraenkemarkt/mackup/.zhistory" +# Note: This file is NOT synced by mackup as zsh destroys the symbolic link +export HISTFILE="$XDG_STATE_HOME/zsh/history" export HISTSIZE=999999 # number of lines kept in memory export SAVEHIST=999999 # number of lines kept in $HISTFILE @@ -84,7 +84,7 @@ source "$ZSH/oh-my-zsh.sh" # Initialize zplug's plugins -source "$HOME/.zplug/init.zsh" # config in ~/.zshenv +source "$XDG_DATA_HOME/zplug/init.zsh" # config in ~/.config/zsh/.zshenv # Must use double quotes in this section # Source: https://github.com/zplug/zplug#example @@ -178,4 +178,4 @@ bindkey -M vicmd 'j' history-substring-search-down # Enable Powerlevel10k "full" prompt -[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh +[[ ! -f $XDG_CONFIG_HOME/zsh/.p10k.zsh ]] || source $XDG_CONFIG_HOME/zsh/.p10k.zsh diff --git a/.vim/swap/.gitkeep b/.local/share/tig/.gitkeep similarity index 100% rename from .vim/swap/.gitkeep rename to .local/share/tig/.gitkeep diff --git a/.vim/undo/.gitkeep b/.local/state/bash/.gitkeep similarity index 100% rename from .vim/undo/.gitkeep rename to .local/state/bash/.gitkeep diff --git a/.local/state/less/.gitkeep b/.local/state/less/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/.local/state/python/.gitkeep b/.local/state/python/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/.local/state/vim/backup/.gitkeep b/.local/state/vim/backup/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/.local/state/vim/swap/.gitkeep b/.local/state/vim/swap/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/.local/state/vim/undo/.gitkeep b/.local/state/vim/undo/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/.local/state/wget/.gitkeep b/.local/state/wget/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/.local/state/zsh/.gitkeep b/.local/state/zsh/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/.mackup.cfg b/.mackup.cfg index a71e896..98f9301 100644 --- a/.mackup.cfg +++ b/.mackup.cfg @@ -5,7 +5,7 @@ directory = mackup [applications_to_ignore] # Do not sync configuration files managed by -# https://gitlab.webartifex.biz/alexander/dotfiles +# https://code.webartifex.biz/alexander/dotfiles alacritty bash @@ -21,6 +21,6 @@ ssh vim zsh -# Do not sync ~/.password-store as it contains symlinks +# Do not sync $XDG_DATA_HOME/password-store as it contains symlinks # that Nextcloud does NOT support pass diff --git a/.mackup/histories.cfg b/.mackup/histories.cfg index 0291037..7f0ca41 100644 --- a/.mackup/histories.cfg +++ b/.mackup/histories.cfg @@ -2,12 +2,13 @@ name = various history files [configuration_files] -.bash_history -# .lesshst -> less overwrites the symlink unfortunately -.python_history -.tig_history -.zhistory - -[xdg_configuration_files] -# ~/.config/psql is set in ~/.psqlrc for all history files -psql +# Note: $XDG_STATE_HOME => ~/.local/state +.local/state/bash/history +# .local/state/less/history -> less overwrites the symlink unfortunately +.local/state/python/history +# tig only supports $XDG_DATA_HOME +.local/share/tig/history +# entire folder as $XDG_CONFIG_HOME/psql/psqlrc sets one history file per database +.local/state/psql +.local/state/wget/history +# .local/state/zsh/history -> zsh overwrites the symlink unfortunately diff --git a/.profile b/.profile index 2491fa5..dec21c0 100644 --- a/.profile +++ b/.profile @@ -1,26 +1,48 @@ # Executed by a login shell (e.g., bash, sh, or zsh) during start-up + +# Shell-independent stuff + + +# Configure the standard XDG base directories +# Further Info: https://wiki.archlinux.org/title/XDG_Base_Directory +export XDG_CACHE_HOME="$HOME/.cache" +export XDG_CONFIG_HOME="$HOME/.config" +export XDG_DATA_HOME="$HOME/.local/share" # also set temporarily in ~/.config/shell/init_dotfiles.sh +export XDG_STATE_HOME="$HOME/.local/state" # also set temporarily in ~/.config/shell/init_dotfiles.sh + +# Move common tools' config and cache files into XDG directories +export BAT_CONFIG_PATH="$XDG_CONFIG_PATH/bat/config" +export CUDA_CACHE_PATH="$XDG_CACHE_HOME/nv" +export GNUPGHOME="$XDG_DATA_HOME/gnupg" +export LESSHISTFILE="$XDG_STATE_HOME/less/history" +export PASSWORD_STORE_DIR="$XDG_DATA_HOME/pass" +export PYTHONSTARTUP="$XDG_CONFIG_HOME/python/pythonrc" +export PSQLRC="$XDG_CONFIG_HOME/psql/psqlrc" +export SSB_HOME="$XDG_DATA_HOME"/zoom +export VIMINIT="source $XDG_CONFIG_HOME/vim/vimrc" + + +# Generic shell configs export EDITOR=vim export PAGER='less --chop-long-lines --ignore-case --LONG-PROMPT --no-init --status-column --quit-if-one-screen' export TERM=xterm-256color export TZ='Europe/Berlin' export VISUAL=$EDITOR + +# Convenience variables for easier access of some locations export REPOS="$HOME/repos" -export BAT_CONFIG_PATH="$HOME/.config/bat/config" - -export LESSHISTFILE="$HOME/.lesshst" +# Python-specific configs export PYENV_ROOT="$HOME/.pyenv" # No need for *.pyc files on a dev machine export PYTHONDONTWRITEBYTECODE=1 -export PSQLRC="$HOME/.psqlrc" - - +# Put local binaries on the $PATH prepend-to-path () { # if not already there if [ -d "$1" ] ; then case :$PATH: in @@ -38,8 +60,11 @@ prepend-to-path "$PYENV_ROOT/bin" # Shell-specific stuff + # zsh-specific stuff is automatically sourced from -# ~/.zshenv, ~/.zprofile, ~/.zlogin, and ~/.zshrc +# $XDG_CONFIG_HOME/zsh/.zshenv, $XDG_CONFIG_HOME/zsh/.zprofile, +# $XDG_CONFIG_HOME/zsh/.zlogin, and $XDG_CONFIG_HOME/.zshrc + # Source ~/.bashrc if we are running inside a bash shell # because it is NOT automatically sourced by bash