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:
parent
7ceed45a28
commit
13b8724696
27 changed files with 131 additions and 42 deletions
2
.bashrc
2
.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
|
||||
|
||||
|
|
|
@ -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
|
33
.config/python/pythonrc
Normal file
33
.config/python/pythonrc
Normal 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)
|
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
@ -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 <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
|
||||
# Source: https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/dotenv
|
||||
export ZSH_DOTENV_FILE=".env"
|
||||
|
|
@ -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
|
0
.local/state/less/.gitkeep
Normal file
0
.local/state/less/.gitkeep
Normal file
0
.local/state/python/.gitkeep
Normal file
0
.local/state/python/.gitkeep
Normal file
0
.local/state/vim/backup/.gitkeep
Normal file
0
.local/state/vim/backup/.gitkeep
Normal file
0
.local/state/vim/swap/.gitkeep
Normal file
0
.local/state/vim/swap/.gitkeep
Normal file
0
.local/state/vim/undo/.gitkeep
Normal file
0
.local/state/vim/undo/.gitkeep
Normal file
0
.local/state/wget/.gitkeep
Normal file
0
.local/state/wget/.gitkeep
Normal file
0
.local/state/zsh/.gitkeep
Normal file
0
.local/state/zsh/.gitkeep
Normal file
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
39
.profile
39
.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
|
||||
|
|
Loading…
Reference in a new issue