From d9de394d9645f65712c7d712ebfbc322fd5c8d48 Mon Sep 17 00:00:00 2001 From: Hugues Hiegel Date: Mon, 2 Feb 2009 12:59:10 +0100 Subject: [KEYCHAIN] meilleure gestion au login et à chaque prompt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .zlogin | 5 ++--- 10_Environment.zsh | 10 ++-------- 11_Colors.zsh | 2 +- 12_Prompts.zsh | 40 +++++++++++++++++++++++++++------------- 4 files changed, 32 insertions(+), 25 deletions(-) diff --git a/.zlogin b/.zlogin index 753030b..e5910e7 100644 --- a/.zlogin +++ b/.zlogin @@ -27,9 +27,8 @@ screen -list #[ -x ~/sbin//calendrier ] && ~/sbin/calendrier #cmd_exists remind && remind -n -# -#cmd_exists keychain && eval $(keychain --eval --quiet --quick --inherit any-once --stop others) -#cmd_exists keychain && keychain --quiet --quick --clear + +cmd_exists keychain && eval $(keychain --eval --inherit any-once --stop others) #keychain id_dsa 593F1F92 chpwd diff --git a/10_Environment.zsh b/10_Environment.zsh index 502f325..158aae3 100644 --- a/10_Environment.zsh +++ b/10_Environment.zsh @@ -19,14 +19,8 @@ export SHELL=`which zsh` ## Agent de clefs SSH/GPG -if [ "$SUDO_USER" = "" ] -then - KEYCHAIN=~/.keychain/$(hostname)-sh - for file in $(find $KEYCHAIN:h -name "$(hostname)-sh" -o -name "$(hostname)-sh-*") - do - source $file - done -fi +KEYCHAIN=~/.keychain/$(hostname)-sh + ## Colors autoload colors && colors diff --git a/11_Colors.zsh b/11_Colors.zsh index 0ca3f52..00d405d 100644 --- a/11_Colors.zsh +++ b/11_Colors.zsh @@ -79,8 +79,8 @@ set_prompt_colors () mail_colors[unread]="$color[yellow];$color[bold]" # mail received mail_colors[listes]="$my_generic;$color[bold]" # less important mail received + agent_colors[empty]="$prompt_colors[soft_generic]" agent_colors[has_keys]="$color[bold];$color[yellow]" - agent_colors[empty]="$prompt_colors[bold_generic]" prompt_colors[up_to_date]="$my_generic" # up-to-date prompt_colors[not_up_to_date]="$color[green];$color[bold]" # not up to date diff --git a/12_Prompts.zsh b/12_Prompts.zsh index 364c22c..9927b88 100644 --- a/12_Prompts.zsh +++ b/12_Prompts.zsh @@ -101,29 +101,43 @@ update_prompt() set_prompt_date # GPG/SSH agents - - KEYCHAIN=~/.keychain/$(hostname)-sh - for file in $(find $KEYCHAIN:h -name "$(hostname)-sh" -o -name "$(hostname)-sh-*") - do - source $file - done - AGENTS="" - if [ "$SSH_AGENT_PID" -gt 0 -a -e /proc/$SSH_AGENT_PID/cmdline ] + [ -f ${KEYCHAIN} ] && source ${KEYCHAIN} + [ -f ${KEYCHAIN}-gpg ] && source ${KEYCHAIN}-gpg + + # Check ssh-agent only if the env socket has been set and is accessible + if [ -S "$SSH_AUTH_SOCK" ] then - if [ "`strings /proc/$SSH_AGENT_PID/cmdline | head -n1`" = "ssh-agent" ] + # Get keylist + SSH_AGENT_KEYLIST="$( ssh-add -l | grep "^[[:digit:]]\+ \([[:digit:]a-f]\{2\}:\)\{15\}[[:digit:]a-f]\{2\} .* (.*)$" )" + + # Check if it is a forwarded agent + if [ "$SSH_AGENT_PID" -gt 0 -a -e /proc/$SSH_AGENT_PID/cmdline ] then - ## We have a running ssh agent - # get list of keys - if [ "$( ssh-add -l | grep "^[[:digit:]]\+ \([[:digit:]a-f]\{2\}:\)\{15\}[[:digit:]a-f]\{2\} .* (.*)$" )" != "" ] + # That's a local agent + if [ "$SSH_AGENT_KEYLIST" != "" ] + then + AGENTCOLOR="has_keys" + AGENTCHAR="★" + else + AGENTCOLOR="empty" + AGENTCHAR="☆" + fi + else + # That's a forwarded agent + if [ "$SSH_AGENT_KEYLIST" != "" ] then AGENTCOLOR="has_keys" + AGENTCHAR="●" else AGENTCOLOR="empty" + AGENTCHAR="○" fi - AGENTS=$C_$agent_colors[$AGENTCOLOR]$_C"★" fi + + AGENTS=$C_$agent_colors[$AGENTCOLOR]$_C"$AGENTCHAR" fi + GPG_AGENT_PID="$(echo $GPG_AGENT_INFO | cut -d: -f2)" if [ "$GPG_AGENT_PID" != "" -a -e /proc/$GPG_AGENT_PID/cmdline ] then -- cgit v1.2.3