From e66afbb5da01ac961c848757242200a1e51e39e5 Mon Sep 17 00:00:00 2001 From: achevsmisle <94835056+achevsmisle@users.noreply.github.com> Date: Wed, 17 Jun 2026 10:49:03 +0300 Subject: [PATCH 1/4] feat(ssh-agent): add option to override `$SSH_AUTH_SOCK` Primary goal: integration with private key managers/keyrings. Make the `$SSH_AUTH_SOCK` constant and set use it in another tool. Includes default fallback values for Linux/MacOS (and fallback for fallback in `~/.ssh/`) --- plugins/ssh-agent/ssh-agent.plugin.zsh | 36 +++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/plugins/ssh-agent/ssh-agent.plugin.zsh b/plugins/ssh-agent/ssh-agent.plugin.zsh index 83548648b..116f3de45 100644 --- a/plugins/ssh-agent/ssh-agent.plugin.zsh +++ b/plugins/ssh-agent/ssh-agent.plugin.zsh @@ -18,13 +18,47 @@ function _start_agent() { return 1 fi + # ssh-agent extra launch flags + local -a agent_extra_flags + + # override $SSH_AUTH_SOCK path option + if zstyle -t :omz:plugins:ssh-agent override-agent-socket-path; then + local ssh_auth_sock_path + local sock_path_reply + zstyle -g sock_path_reply :omz:plugins:ssh-agent override-agent-socket-path + ssh_auth_sock_path="$sock_path_reply" + + # set fallback path by $OSTYPE + if [[ -z "$ssh_auth_sock_path" ]]; then + if [[ "$OSTYPE" == "linux"* ]]; then + ssh_auth_sock_path="/var/run/user/$UID/ssh-agent" + elif [[ "$OSTYPE" == "darwin"* ]]; then + ssh_auth_sock_path="${TMPDIR:-/tmp}/ssh-agent.socket" + else + ssh_auth_sock_path="$HOME/.ssh/ssh-agent.socket" + fi + fi + + # check the socket dir and create if needed + local socket_dir="${ssh_auth_sock_path:h}" + if [[ ! -d "$socket_dir" ]]; then + mkdir -p "$socket_dir" || \ + { echo "Error: can't create ssh socket parent directory." && return 1 } + chmod 700 "$socket_dir" || \ + { echo "Error: can't change permissions of the ssh socket parent directory." && return 1 } + fi + + # set extra flags array + agent_extra_flags=(-a "$ssh_auth_sock_path") + fi + # Set a maximum lifetime for identities added to ssh-agent local lifetime zstyle -s :omz:plugins:ssh-agent lifetime lifetime # start ssh-agent and setup environment zstyle -t :omz:plugins:ssh-agent quiet || echo >&2 "Starting ssh-agent ..." - ssh-agent -s ${lifetime:+-t} ${lifetime} | sed '/^echo/d' >! "$ssh_env_cache" + ssh-agent "${agent_extra_flags[@]}" -s ${lifetime:+-t} ${lifetime} | sed '/^echo/d' >! "$ssh_env_cache" chmod 600 "$ssh_env_cache" . "$ssh_env_cache" > /dev/null } From 06c239454456693282562f4ed99912a823550a6e Mon Sep 17 00:00:00 2001 From: achevsmisle <94835056+achevsmisle@users.noreply.github.com> Date: Wed, 17 Jun 2026 10:49:44 +0300 Subject: [PATCH 2/4] docs(ssh-agent): describe `override-agent-socket-path` option --- plugins/ssh-agent/README.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/plugins/ssh-agent/README.md b/plugins/ssh-agent/README.md index 0afa80cc8..4efc6b1cd 100644 --- a/plugins/ssh-agent/README.md +++ b/plugins/ssh-agent/README.md @@ -99,6 +99,33 @@ ssh-add -K -c -a /run/user/1000/ssh-auth For valid `ssh-add` arguments run `ssh-add --help` or `man ssh-add`. +### `override-agent-socket-path` + +If you want to say goodbye to (for example) gnome-keyring, you will need a fixed, +constant path to SSH-agent socket. +By default its name is randomly generated in form of `$TMPDIR/ssh-XXXXXXXXXX/agent.`. + +To override the `$SSH_AUTH_SOCK` path, use `override-agent-socket-path` style. + +```zsh +zstyle :omz:plugins:ssh-agent override-agent-socket-path "/your/custom/path/socket_name" +``` + +Of course you should double-quote the path itself. +Also there are few builtin default for Linux and MacOS, so you could simply add: + +```zsh +zstyle :omz:plugins:ssh-agent override-agent-socket-path +``` + +These are the defaults: +* Linux: + The default `$SSH_AUTH_SOCK` will be `"/var/run/user//ssh-agent"` +* MacOS: + The default `$SSH_AUTH_SOCK` will be `$TMPDIR/ssh-agent.socket"` or `/tmp/ssh-agent.socket"` if `$TMPDIR` is not set for some reason. +* On other systems the socket file will be placed in `"$HOME/.ssh/ssh-agent.socket"` + + ### Powerline 10k specific settings Powerline10k has an instant prompt setting that doesn't like when this plugin From f0fda90a247a23b93e0f523dd35e2d59aa36bdbf Mon Sep 17 00:00:00 2001 From: achevsmisle <94835056+achevsmisle@users.noreply.github.com> Date: Sat, 20 Jun 2026 18:54:31 +0300 Subject: [PATCH 3/4] fix(ssh-agent): change input processing --- plugins/ssh-agent/ssh-agent.plugin.zsh | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/plugins/ssh-agent/ssh-agent.plugin.zsh b/plugins/ssh-agent/ssh-agent.plugin.zsh index 116f3de45..86bffd391 100644 --- a/plugins/ssh-agent/ssh-agent.plugin.zsh +++ b/plugins/ssh-agent/ssh-agent.plugin.zsh @@ -23,24 +23,22 @@ function _start_agent() { # override $SSH_AUTH_SOCK path option if zstyle -t :omz:plugins:ssh-agent override-agent-socket-path; then - local ssh_auth_sock_path - local sock_path_reply - zstyle -g sock_path_reply :omz:plugins:ssh-agent override-agent-socket-path - ssh_auth_sock_path="$sock_path_reply" + local ssh_agent_sock_path + zstyle -s :omz:plugins:ssh-agent ssh_agent_sock_path ssh_agent_sock_path # set fallback path by $OSTYPE - if [[ -z "$ssh_auth_sock_path" ]]; then + if [[ -z "$ssh_agent_sock_path" ]]; then if [[ "$OSTYPE" == "linux"* ]]; then - ssh_auth_sock_path="/var/run/user/$UID/ssh-agent" + ssh_agent_sock_path="/var/run/user/$UID/ssh-agent" elif [[ "$OSTYPE" == "darwin"* ]]; then - ssh_auth_sock_path="${TMPDIR:-/tmp}/ssh-agent.socket" + ssh_agent_sock_path="${TMPDIR:-/tmp}/ssh-agent.socket" else - ssh_auth_sock_path="$HOME/.ssh/ssh-agent.socket" + ssh_agent_sock_path="$HOME/.ssh/ssh-agent.socket" fi fi # check the socket dir and create if needed - local socket_dir="${ssh_auth_sock_path:h}" + local socket_dir="${ssh_agent_sock_path:h}" if [[ ! -d "$socket_dir" ]]; then mkdir -p "$socket_dir" || \ { echo "Error: can't create ssh socket parent directory." && return 1 } @@ -49,7 +47,7 @@ function _start_agent() { fi # set extra flags array - agent_extra_flags=(-a "$ssh_auth_sock_path") + agent_extra_flags=(-a "$ssh_agent_sock_path") fi # Set a maximum lifetime for identities added to ssh-agent From 2d32d82e7672959a4aec387e7f2350aa35e1df61 Mon Sep 17 00:00:00 2001 From: achevsmisle <94835056+achevsmisle@users.noreply.github.com> Date: Sat, 20 Jun 2026 18:58:58 +0300 Subject: [PATCH 4/4] docs(ssh-agent): correct the description to new behaviour --- plugins/ssh-agent/README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/plugins/ssh-agent/README.md b/plugins/ssh-agent/README.md index 4efc6b1cd..a9d8c068f 100644 --- a/plugins/ssh-agent/README.md +++ b/plugins/ssh-agent/README.md @@ -108,14 +108,15 @@ By default its name is randomly generated in form of `$TMPDIR/ssh-XXXXXXXXXX/age To override the `$SSH_AUTH_SOCK` path, use `override-agent-socket-path` style. ```zsh -zstyle :omz:plugins:ssh-agent override-agent-socket-path "/your/custom/path/socket_name" +zstyle :omz:plugins:ssh-agent override-agent-socket-path yes +zstyle :omz:plugins:ssh-agent ssh_agent_sock_path "YOUR_CUSTOM_SOCKET_PATH" ``` Of course you should double-quote the path itself. -Also there are few builtin default for Linux and MacOS, so you could simply add: +There are few builtin defaults for Linux and MacOS, so you could simply add: ```zsh -zstyle :omz:plugins:ssh-agent override-agent-socket-path +zstyle :omz:plugins:ssh-agent override-agent-socket-path yes ``` These are the defaults: