From 064885e8b48b82c536d27a64160cce9b6e222b57 Mon Sep 17 00:00:00 2001 From: Aminda Suomalainen Date: Thu, 22 Jan 2026 09:02:28 +0200 Subject: [PATCH] {bash,zsh}rc: use user-specific runtime directory rather than /tmp for ssh-agent --- rc/bashrc | 20 +++++++++++++------- rc/zshrc | 20 +++++++++++++------- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/rc/bashrc b/rc/bashrc index 69249a17..b8425dcf 100755 --- a/rc/bashrc +++ b/rc/bashrc @@ -250,9 +250,15 @@ if [ -f ~/.gnupg/sshcontrol ]; then gpg-connect-agent updatestartuptty /bye > /dev/null 2>&1 # otherwise use the normal ssh-agent else - # if the output is going to /dev/null, it's non/existence doesn't matter - (ssh-agent -a /tmp/$USER.sshagent > /dev/null 2>&1) - export SSH_AUTH_SOCK=/tmp/$USER.sshagent + if hash xdg-user-dir 2> /dev/null; then + # if the output is going to /dev/null, it's non/existence doesn't matter + (ssh-agent -a $(xdg-user-dir RUNTIME)/sshagent > /dev/null 2>&1) + export SSH_AUTH_SOCK=$(xdg-user-dir RUNTIME)/sshagent + else + # if the output is going to /dev/null, it's non/existence doesn't matter + (ssh-agent -a /tmp/$USER.sshagent > /dev/null 2>&1) + export SSH_AUTH_SOCK=/tmp/$USER.sshagent + fi fi # OS X ls colours (copied from https://apple.stackexchange.com/questions/33677/ @@ -1027,9 +1033,9 @@ if [ -f ~/.bash_custom ]; then source ~/.bash_custom fi -# If $TMUX, then TERM is tmux-256color -#if [ -v TMUX ]; then -# TERM=tmux-256color -#fi +# Note if my xdg runtime dir setting is broken. +if ! hash xdg-user-dir 2> /dev/null; then + echo "WARNING! xdg-user-dir not found." +fi # vim: filetype=bash diff --git a/rc/zshrc b/rc/zshrc index 2b81daae..4eaeba1f 100755 --- a/rc/zshrc +++ b/rc/zshrc @@ -206,9 +206,15 @@ if [ -f ~/.gnupg/sshcontrol ]; then gpg-connect-agent updatestartuptty /bye > /dev/null 2>&1 # otherwise use the normal ssh-agent else - # if the output is going to /dev/null, it's non/existence doesn't matter - (ssh-agent -a /tmp/$USER.sshagent > /dev/null 2>&1) - export SSH_AUTH_SOCK=/tmp/$USER.sshagent + if hash xdg-user-dir 2> /dev/null; then + # if the output is going to /dev/null, it's non/existence doesn't matter + (ssh-agent -a $(xdg-user-dir RUNTIME)/sshagent > /dev/null 2>&1) + export SSH_AUTH_SOCK=$(xdg-user-dir RUNTIME)/sshagent + else + # if the output is going to /dev/null, it's non/existence doesn't matter + (ssh-agent -a /tmp/$USER.sshagent > /dev/null 2>&1) + export SSH_AUTH_SOCK=/tmp/$USER.sshagent + fi fi # If we are on Linux, enable apt progress bar and colours @@ -1019,9 +1025,9 @@ if [ -f ~/.warnings ]; then source ~/.warnings fi -# If $TMUX, then TERM is tmux-256color -#if [ -v TMUX ]; then -# TERM=tmux-256color -#fi +# Note if my xdg runtime dir setting is broken. +if ! hash xdg-user-dir 2> /dev/null; then + echo "WARNING! xdg-user-dir not found." +fi # vim: filetype=zsh