Repository: atuinsh/atuin (language: rust)

Issue:
Daemon socket should be in $XDG_RUNTIME_DIR
The canonical location for user service sockets (and other runtime temporary files) on systemd systems is `$XDG_RUNTIME_DIR` (typically `/run/user/$UID`). When this variable is available, Atuin should locate its daemon socket at `$XDG_RUNTIME_DIR/atuin/atuin.sock` by default.


Discussion / hints:
I run into the same issue when preparing [atuin daemon support on Gentoo](https://bugs.gentoo.org/934563). 

> When this variable is available, Atuin should locate its daemon socket at `$XDG_RUNTIME_DIR/atuin/atuin.sock` by default.

Not only when this variable (XDG_RUNTIME_DIR) is available. Even in the absence of XDG_RUNTIME_DIR from the processes' environment, atuin should default to that. The "XDG Base Directory Specification" is states that

> If $XDG_RUNTIME_DIR is not set applications should fall back to a replacement directory with similar capabilities and print a warning message. Applications should use this directory for communication and synchronization purposes and should not place larger files in it, since it might reside in runtime memory and cannot necessarily be swapped out to disk.

<sup>Source: https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html#variables</sup>

So atuin's default for `socket_path` should be, in bash variable default-value notation, `${XDG_RUNTIME_DIR:-/run/user/${UID}}/atuin.socket`.

Fix patch:
diff --git a/crates/atuin-client/src/settings.rs b/crates/atuin-client/src/settings.rs
index a34758db317..d7b03c2b003 100644
--- a/crates/atuin-client/src/settings.rs
+++ b/crates/atuin-client/src/settings.rs
@@ -667,7 +667,7 @@ impl Settings {
         let data_dir = atuin_common::utils::data_dir();
         let db_path = data_dir.join("history.db");
         let record_store_path = data_dir.join("records.db");
-        let socket_path = data_dir.join("atuin.sock");
+        let socket_path = atuin_common::utils::runtime_dir().join("atuin.sock");
 
         let key_path = data_dir.join("key");
         let session_path = data_dir.join("session");
diff --git a/crates/atuin-common/src/utils.rs b/crates/atuin-common/src/utils.rs
index 3815085ede0..65f5efc48c0 100644
--- a/crates/atuin-common/src/utils.rs
+++ b/crates/atuin-common/src/utils.rs
@@ -77,6 +77,10 @@ pub fn data_dir() -> PathBuf {
     data_dir.join("atuin")
 }
 
+pub fn runtime_dir() -> PathBuf {
+    std::env::var("XDG_RUNTIME_DIR").map_or_else(|_| data_dir(), PathBuf::from)
+}
+
 pub fn dotfiles_cache_dir() -> PathBuf {
     // In most cases, this will be  ~/.local/share/atuin/dotfiles/cache
     let data_dir = std::env::var("XDG_DATA_HOME")


Test patch: