Move everything possible into XDG directories

With the help of xdg-ninja (https://github.com/b3nj5m1n/xdg-ninja)
we move all kinds of config/cache files into the XDG directories
This commit is contained in:
Alexander Hess 2023-04-10 04:08:07 +02:00
parent 7ceed45a28
commit 13b8724696
Signed by: alexander
GPG key ID: 344EA5AB10D868E0
27 changed files with 131 additions and 42 deletions

View file

@ -40,7 +40,7 @@ shopt -s checkwinsize
# Set these environment variables here (and not in ~/.profile) # Set these environment variables here (and not in ~/.profile)
# due to conflict/overlap with zsh # 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 HISTSIZE=999999 # number of lines kept in memory
export HISTFILESIZE=999999 # number of lines kept in $HISTFILE export HISTFILESIZE=999999 # number of lines kept in $HISTFILE

View file

@ -22,7 +22,8 @@
-- Use separate history files per database and -- Use separate history files per database and
-- keep them in one folder (for easier sync with mackup) -- 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 -- Don't store the same SQL statement repeatedly
\set HISTCONTROL ignoredups \set HISTCONTROL ignoredups

33
.config/python/pythonrc Normal file
View file

@ -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)

View file

@ -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 netstat && alias ports='netstat -tulanp'
_command_exists screenfetch && alias screenfetch='screenfetch -n' _command_exists screenfetch && alias screenfetch='screenfetch -n'
alias uptime='uptime --pretty' 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 # Create shorter aliases for various utilities

View file

@ -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() { _command_exists() {
@ -14,14 +18,27 @@ rm -rf "$HOME/.dotfiles" >/dev/null
git clone --bare https://code.webartifex.biz/alexander/dotfiles.git "$HOME/.dotfiles" git clone --bare https://code.webartifex.biz/alexander/dotfiles.git "$HOME/.dotfiles"
# Distribute the dotfiles in $HOME # Distribute the dotfiles in $HOME
git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME checkout --force git --git-dir=$XDG_DATA_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 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 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 # (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 rm -rf $ZSH >/dev/null
# Let's NOT use the main repository but our personal fork # 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 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 cd $HOME
# (Re-)Install zplug # (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 rm -rf $ZPLUG_HOME >/dev/null
git clone https://github.com/zplug/zplug $ZPLUG_HOME git clone https://github.com/zplug/zplug $ZPLUG_HOME
# Set up all the zplug plugins (-i so that the new $XDG_CONFIG_HOME/zsh/.zshrc is sourced)
# Set up all the zplug plugins (-i so that the new ~/.zshrc is sourced)
zsh -i -c "zplug install" zsh -i -c "zplug install"
fi fi
# Disable the creation of ~/.sudo_as_admin_successful
echo 'Defaults !admin_flag' | sudo tee /etc/sudoers.d/disable_admin_note
echo echo
echo "Probably it's a good idea to restart the shell" 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" echo "Make sure to start bash or zsh as a login shell the next time"

View file

@ -57,7 +57,7 @@ _update_repositories() {
ZSH_DOTENV_FILE='.env' 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 _update_dotfiles
cd $cwd cd $cwd

View file

@ -5,8 +5,9 @@
" Use VIM improved mode " Use VIM improved mode
set nocompatible set nocompatible
" Set environment variables for convenient usage " Set environment variables for convenient usage
let $RC="$HOME/.vim/vimrc" let $RC="$XDG_CONFIG_HOME/vim/vimrc"
let $RTP=split(&runtimepath, ',')[0] let $RTP=split(&runtimepath, ',')[0]
" Disable VIM's startup message " Disable VIM's startup message
@ -39,13 +40,13 @@ set hidden
set path=.,** set path=.,**
" Store all vim-related working files in the ~/.vim folder " Store all vim-related working files in the ~/.local/state/vim folder
set viminfo+=n~/.vim/viminfo set viminfo+=n$XDG_STATE_HOME/vim/viminfo
" Use dedicated folders to store temporary backup, swap, and undo files " Use dedicated folders to store temporary backup, swap, and undo files
" (the // means that VIM adapts names automatically to avoid duplicates) " (the // means that VIM adapts names automatically to avoid duplicates)
set backupdir=~/.vim/backup// set backupdir=$XDG_STATE_HOME/vim/backup//
set directory=~/.vim/swap// set directory=$XDG_STATE_HOME/vim/swap//
set undodir=~/.vim/undo// set undodir=$XDG_STATE_HOME/vim/undo//
" To disable any of the temporary files, uncomment one of the following " To disable any of the temporary files, uncomment one of the following
" set nobackup " set nobackup
@ -54,6 +55,9 @@ set undodir=~/.vim/undo//
" set noundofile " 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 " Show the filename in the terminal window's title bar
set title set title

View file

@ -2,8 +2,14 @@
# (it's kind of a zsh-only ~/.profile file) # (it's kind of a zsh-only ~/.profile file)
export ZSH="$HOME/.oh-my-zsh" export XDG_CONFIG_HOME="$HOME/.config"
export ZPLUG_HOME="$HOME/.zplug" 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 <Up> key to auto-complete a partially typed command # Use <Up> 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 # Automatically source ".env" files in folders
# Source: https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/dotenv # Source: https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/dotenv
export ZSH_DOTENV_FILE=".env" export ZSH_DOTENV_FILE=".env"

View file

@ -52,8 +52,8 @@ unalias -a
# Set these environment variables here (and not in ~/.profile) # Set these environment variables here (and not in ~/.profile)
# due to conflict/overlap with bash # due to conflict/overlap with bash
# Can NOT be $HOME/.zhistory as zsh destroys mackup's symbolic link # Note: This file is NOT synced by mackup as zsh destroys the symbolic link
export HISTFILE="$HOME/data/getraenkemarkt/mackup/.zhistory" export HISTFILE="$XDG_STATE_HOME/zsh/history"
export HISTSIZE=999999 # number of lines kept in memory export HISTSIZE=999999 # number of lines kept in memory
export SAVEHIST=999999 # number of lines kept in $HISTFILE export SAVEHIST=999999 # number of lines kept in $HISTFILE
@ -84,7 +84,7 @@ source "$ZSH/oh-my-zsh.sh"
# Initialize zplug's plugins # 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 # Must use double quotes in this section
# Source: https://github.com/zplug/zplug#example # Source: https://github.com/zplug/zplug#example
@ -178,4 +178,4 @@ bindkey -M vicmd 'j' history-substring-search-down
# Enable Powerlevel10k "full" prompt # Enable Powerlevel10k "full" prompt
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh [[ ! -f $XDG_CONFIG_HOME/zsh/.p10k.zsh ]] || source $XDG_CONFIG_HOME/zsh/.p10k.zsh

View file

View file

View file

View file

View file

View file

View file

View file

@ -5,7 +5,7 @@ directory = mackup
[applications_to_ignore] [applications_to_ignore]
# Do not sync configuration files managed by # Do not sync configuration files managed by
# https://gitlab.webartifex.biz/alexander/dotfiles # https://code.webartifex.biz/alexander/dotfiles
alacritty alacritty
bash bash
@ -21,6 +21,6 @@ ssh
vim vim
zsh 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 # that Nextcloud does NOT support
pass pass

View file

@ -2,12 +2,13 @@
name = various history files name = various history files
[configuration_files] [configuration_files]
.bash_history # Note: $XDG_STATE_HOME => ~/.local/state
# .lesshst -> less overwrites the symlink unfortunately .local/state/bash/history
.python_history # .local/state/less/history -> less overwrites the symlink unfortunately
.tig_history .local/state/python/history
.zhistory # tig only supports $XDG_DATA_HOME
.local/share/tig/history
[xdg_configuration_files] # entire folder as $XDG_CONFIG_HOME/psql/psqlrc sets one history file per database
# ~/.config/psql is set in ~/.psqlrc for all history files .local/state/psql
psql .local/state/wget/history
# .local/state/zsh/history -> zsh overwrites the symlink unfortunately

View file

@ -1,26 +1,48 @@
# Executed by a login shell (e.g., bash, sh, or zsh) during start-up # 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 EDITOR=vim
export PAGER='less --chop-long-lines --ignore-case --LONG-PROMPT --no-init --status-column --quit-if-one-screen' export PAGER='less --chop-long-lines --ignore-case --LONG-PROMPT --no-init --status-column --quit-if-one-screen'
export TERM=xterm-256color export TERM=xterm-256color
export TZ='Europe/Berlin' export TZ='Europe/Berlin'
export VISUAL=$EDITOR export VISUAL=$EDITOR
# Convenience variables for easier access of some locations
export REPOS="$HOME/repos" export REPOS="$HOME/repos"
export BAT_CONFIG_PATH="$HOME/.config/bat/config"
export LESSHISTFILE="$HOME/.lesshst"
# Python-specific configs
export PYENV_ROOT="$HOME/.pyenv" export PYENV_ROOT="$HOME/.pyenv"
# No need for *.pyc files on a dev machine # No need for *.pyc files on a dev machine
export PYTHONDONTWRITEBYTECODE=1 export PYTHONDONTWRITEBYTECODE=1
export PSQLRC="$HOME/.psqlrc"
# Put local binaries on the $PATH
prepend-to-path () { # if not already there prepend-to-path () { # if not already there
if [ -d "$1" ] ; then if [ -d "$1" ] ; then
case :$PATH: in case :$PATH: in
@ -38,8 +60,11 @@ prepend-to-path "$PYENV_ROOT/bin"
# Shell-specific stuff # Shell-specific stuff
# zsh-specific stuff is automatically sourced from # 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 # Source ~/.bashrc if we are running inside a bash shell
# because it is NOT automatically sourced by bash # because it is NOT automatically sourced by bash