From 78cd1d64224f9814c7de43f5262498e50c9f6fef Mon Sep 17 00:00:00 2001 From: pika Date: Mon, 28 Oct 2024 10:59:26 +0100 Subject: [PATCH] addet keychain plugins --- .zsh/custom/agent.zsh | 50 +++++++++++++++++++++++++++++++++++++++++++ .zshrc | 2 ++ 2 files changed, 52 insertions(+) create mode 100644 .zsh/custom/agent.zsh diff --git a/.zsh/custom/agent.zsh b/.zsh/custom/agent.zsh new file mode 100644 index 0000000..5c20e90 --- /dev/null +++ b/.zsh/custom/agent.zsh @@ -0,0 +1,50 @@ +export GPG_TTY=$TTY + +# Fix for passphrase prompt on the correct tty +# See https://www.gnupg.org/documentation/manuals/gnupg/Agent-Options.html#option-_002d_002denable_002dssh_002dsupport +function _gpg-agent_update-tty_preexec { + gpg-connect-agent updatestartuptty /bye &>/dev/null +} +autoload -U add-zsh-hook +add-zsh-hook preexec _gpg-agent_update-tty_preexec + +# If enable-ssh-support is set, fix ssh agent integration +if [[ $(gpgconf --list-options gpg-agent 2>/dev/null | awk -F: '$1=="enable-ssh-support" {print $10}') = 1 ]]; then + unset SSH_AGENT_PID + if [[ "${gnupg_SSH_AUTH_SOCK_by:-0}" -ne $$ ]]; then + export SSH_AUTH_SOCK="$(gpgconf --list-dirs agent-ssh-socket)" + fi +fi + +(( $+commands[keychain] )) || return + +# Define SHORT_HOST if not defined (%m = host name up to first .) +SHORT_HOST=${SHORT_HOST:-${(%):-%m}} + +function { + local agents + local -a identities + local -a options + local _keychain_env_sh + local _keychain_env_sh_gpg + + # load agents to start. + zstyle -s :omz:plugins:keychain agents agents + + # load identities to manage. + zstyle -a :omz:plugins:keychain identities identities + + # load additional options + zstyle -a :omz:plugins:keychain options options + + # start keychain... + keychain ${^options:-} --agents ${agents:-gpg} ${^identities} --host $SHORT_HOST + + # Get the filenames to store/lookup the environment from + _keychain_env_sh="$HOME/.keychain/$SHORT_HOST-sh" + _keychain_env_sh_gpg="$HOME/.keychain/$SHORT_HOST-sh-gpg" + + # Source environment settings. + [ -f "$_keychain_env_sh" ] && . "$_keychain_env_sh" + [ -f "$_keychain_env_sh_gpg" ] && . "$_keychain_env_sh_gpg" +} diff --git a/.zshrc b/.zshrc index 7e6d8f2..8f327d0 100644 --- a/.zshrc +++ b/.zshrc @@ -153,6 +153,7 @@ _init (){ local zTruecolor="$zconf/custom/256color.zsh" local zAutopairs="$zconf/autopairs/autopair.zsh" local zFzfCd="$zconf/custom/zsh-interactive-cd.plugin.zsh" + local zAgentManagement="$zconf/custom/agent.zsh" local _pluginlist=( "$zAutosg" @@ -160,6 +161,7 @@ _init (){ "$zTruecolor" "$zAutopairs" "$zFzfCd" + "$zAgentManagement" ) DEBUG_PLUG=""