From 690df57f008cd9621efd6155350c475b0134e3be Mon Sep 17 00:00:00 2001 From: Danielle McLean Date: Mon, 11 Jul 2022 17:45:18 +1000 Subject: [PATCH 1/5] Set compromise XDG_RUNTIME_DIR if necessary It's not ideal to set XDG_RUNTIME_DIR in your shell environment, rather than from your session manager (or systemd, or whatever), since then you can't reliably provide the same lifetime guarantees that XDG_RUNTIME_DIR is supposed to have? But this is still preferable to not having an XDG_RUNTIME_DIR at all, so I'm gonna go with it. --- zshenv | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/zshenv b/zshenv index a156484..fa2dd21 100644 --- a/zshenv +++ b/zshenv @@ -6,6 +6,26 @@ export XDG_CONFIG_HOME XDG_CACHE_HOME XDG_DATA_HOME XDG_STATE_HOME +# The other four XDG directories are very easy, but XDG_RUNTIME_DIR is +# complicated. It kinda needs to be managed by a systemwide supervisor, like +# systemd, in order to meet all of the XDG Base Directory specification's +# requirements? In particular, the directory is supposed to come into being +# when you log in, live as long as you have any active sessions, and be +# destroyed when you log out - none of this can easily be done from the shell +# environment alone, especially on an operating system like macOS where your +# graphical session wasn't spawned from a shell using something like .xinitrc. +# +# We're going to assume XDG_RUNTIME_DIR will have already be set by a +# systemwide supervisor if it can possibly have been. If it hasn't - say, +# because we're on macOS - we'll compromise by using TMPDIR. Since TMPDIR has +# a different lifetime than XDG_RUNTIME_DIR is supposed to, this is an +# imperfect solution, but it's the best we can do. +if [[ ! -d $XDG_RUNTIME_DIR ]] && [[ -d $TMPDIR ]]; then + export XDG_RUNTIME_DIR=${TMPDIR}xdg-$UID + mkdir -p $XDG_RUNTIME_DIR + chmod 0700 $XDG_RUNTIME_DIR +fi + # The real zsh config lives in XDG_CONFIG_HOME! ;) : ${ZDOTDIR:=$XDG_CONFIG_HOME/zsh} source $ZDOTDIR/zshenv From c55664cce3c520f570b85b56a0d4971730e78e7d Mon Sep 17 00:00:00 2001 From: Danielle McLean Date: Tue, 12 Jul 2022 11:03:43 +1000 Subject: [PATCH 2/5] Move GOPATH into XDG_DATA_HOME --- config/zsh/login/langs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/zsh/login/langs b/config/zsh/login/langs index 4a123b7..883e413 100644 --- a/config/zsh/login/langs +++ b/config/zsh/login/langs @@ -3,8 +3,8 @@ local -a newbins # go -[[ -z $GOPATH ]] && export GOPATH=~/.go -newbins+=(~/.go/bin) +[[ -z $GOPATH ]] && export GOPATH=$XDG_DATA_HOME/go +newbins+=($XDG_DATA_HOME/go/bin) # haskell newbins+=(~/.cabal/bin ~/Library/Haskell/bin) From 8bbc4bd3f2d998ee932fd0b2b41dcacc6a3ec0ce Mon Sep 17 00:00:00 2001 From: Danielle McLean Date: Tue, 12 Jul 2022 11:04:09 +1000 Subject: [PATCH 3/5] Push Docker config into XDG_CONFIG_HOME --- config/zsh/login/langs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/config/zsh/login/langs b/config/zsh/login/langs index 883e413..c7a524c 100644 --- a/config/zsh/login/langs +++ b/config/zsh/login/langs @@ -2,6 +2,9 @@ local -a newbins +# docker +export DOCKER_CONFIG=$XDG_CONFIG_HOME/docker + # go [[ -z $GOPATH ]] && export GOPATH=$XDG_DATA_HOME/go newbins+=($XDG_DATA_HOME/go/bin) From efb24fc3f6cd74a61f2aef3ed9ac1cdc6db08f70 Mon Sep 17 00:00:00 2001 From: Danielle McLean Date: Tue, 12 Jul 2022 11:04:31 +1000 Subject: [PATCH 4/5] Push Ruby Bundler directories into XDG dirs --- config/zsh/login/langs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/config/zsh/login/langs b/config/zsh/login/langs index c7a524c..76d94cf 100644 --- a/config/zsh/login/langs +++ b/config/zsh/login/langs @@ -26,6 +26,9 @@ fi # ruby newbins+=(~/.gem/ruby/*/bin(N) /usr/local/opt/ruby/bin /usr/local/lib/ruby/gems/*/bin(N)) +export BUNDLE_USER_CONFIG=$XDG_CONFIG_HOME/bundle +export BUNDLE_USER_CACHE=$XDG_CACHE_HOME/bundle +export BUNDLE_USER_PLUGIN=$XDG_DATA_HOME/bundle # rust export CARGO_HOME=$XDG_DATA_HOME/cargo From 3eec1572850ba128906ce9e8baa63ae3f0b21474 Mon Sep 17 00:00:00 2001 From: Danielle McLean Date: Tue, 12 Jul 2022 11:04:56 +1000 Subject: [PATCH 5/5] Shift lots of shells' history into XDG_DATA_HOME --- config/zsh/login/langs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/config/zsh/login/langs b/config/zsh/login/langs index 76d94cf..24e9141 100644 --- a/config/zsh/login/langs +++ b/config/zsh/login/langs @@ -13,6 +13,13 @@ newbins+=($XDG_DATA_HOME/go/bin) newbins+=(~/.cabal/bin ~/Library/Haskell/bin) export STACK_ROOT=$XDG_DATA_HOME/stack +# less +# not exactly a 'lang' but still +export LESSHISTFILE=$XDG_DATA_HOME/less/history + +# mysql +export MYSQL_HISTFILE=$XDG_DATA_HOME/mysql/history + # o'caml export OPAMROOT=$XDG_DATA_HOME/opam [[ -f $OPAMROOT/opam-init/init.zsh ]] && source $OPAMROOT/opam-init/init.zsh @@ -51,6 +58,9 @@ export PHIVE_HOME=$XDG_DATA_HOME/phive # there you go, I guess. newbins+=($XDG_CONFIG_HOME/composer/vendor/bin) +# postgres +export PSQL_HISTORY=$XDG_DATA_HOME/psql/history + # python export -UT PYTHONPATH pythonpath newbins+=(~/Library/Python/*/bin(N)) @@ -60,4 +70,10 @@ export PYENV_ROOT=$XDG_DATA_HOME/pyenv export PYENV_SHELL=zsh newbins+=($XDG_DATA_HOME/pyenv/shims $HOME/.poetry/bin) +# redis +export REDISCLI_HISTFILE=$XDG_DATA_HOME/redis/rediscli_history + +# sqlite +export SQLITE_HISTORY=$XDG_DATA_HOME/sqlite/history + path=($newbins $path)