This commit is contained in:
achevsmisle 2026-08-06 10:16:30 +02:00 committed by GitHub
commit 3513e1f990
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 61 additions and 1 deletions

View file

@ -99,6 +99,34 @@ ssh-add -K -c -a /run/user/1000/ssh-auth <identities>
For valid `ssh-add` arguments run `ssh-add --help` or `man ssh-add`. 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.<ppid>`.
To override the `$SSH_AUTH_SOCK` path, use `override-agent-socket-path` style.
```zsh
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.
There are few builtin defaults for Linux and MacOS, so you could simply add:
```zsh
zstyle :omz:plugins:ssh-agent override-agent-socket-path yes
```
These are the defaults:
* Linux:
The default `$SSH_AUTH_SOCK` will be `"/var/run/user/<YOUR_UID>/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 ### Powerline 10k specific settings
Powerline10k has an instant prompt setting that doesn't like when this plugin Powerline10k has an instant prompt setting that doesn't like when this plugin

View file

@ -18,13 +18,45 @@ function _start_agent() {
return 1 return 1
fi 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_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_agent_sock_path" ]]; then
if [[ "$OSTYPE" == "linux"* ]]; then
ssh_agent_sock_path="/var/run/user/$UID/ssh-agent"
elif [[ "$OSTYPE" == "darwin"* ]]; then
ssh_agent_sock_path="${TMPDIR:-/tmp}/ssh-agent.socket"
else
ssh_agent_sock_path="$HOME/.ssh/ssh-agent.socket"
fi
fi
# check the socket dir and create if needed
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 }
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_agent_sock_path")
fi
# Set a maximum lifetime for identities added to ssh-agent # Set a maximum lifetime for identities added to ssh-agent
local lifetime local lifetime
zstyle -s :omz:plugins:ssh-agent lifetime lifetime zstyle -s :omz:plugins:ssh-agent lifetime lifetime
# start ssh-agent and setup environment # start ssh-agent and setup environment
zstyle -t :omz:plugins:ssh-agent quiet || echo >&2 "Starting ssh-agent ..." 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" chmod 600 "$ssh_env_cache"
. "$ssh_env_cache" > /dev/null . "$ssh_env_cache" > /dev/null
} }