From 4a5b97a865f614b4aebf93a2d04bb6616c7d864d Mon Sep 17 00:00:00 2001 From: Hugues Hiegel Date: Fri, 30 Jan 2009 16:39:25 +0100 Subject: [PROMPT] SSH agent key listing, and GnuPG agent better managment --- 11_Colors.zsh | 5 +++-- 12_Prompts.zsh | 24 +++++++++++++++++------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/11_Colors.zsh b/11_Colors.zsh index d9b1e8f..0ca3f52 100644 --- a/11_Colors.zsh +++ b/11_Colors.zsh @@ -7,7 +7,7 @@ ## You are encouraged to use, modify, and redistribute ## these files with or without this notice. ## -typeset -A prompt_colors git_colors mail_colors correct_colors battery_colors date_colors +typeset -A prompt_colors git_colors mail_colors correct_colors battery_colors date_colors agent_colors # I hate kik00l0l colorized prompts, so I'm using a way to # give a dominant color for each part of the prompt, each of @@ -79,7 +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 - prompt_colors[agents]="$prompt_colors[bold_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 8a8d5d1..364c22c 100644 --- a/12_Prompts.zsh +++ b/12_Prompts.zsh @@ -111,16 +111,26 @@ update_prompt() AGENTS="" if [ "$SSH_AGENT_PID" -gt 0 -a -e /proc/$SSH_AGENT_PID/cmdline ] then - [ "`strings /proc/$SSH_AGENT_PID/cmdline | head -n1`" = "ssh-agent" ] && \ - AGENTS=$C_$prompt_colors[agents]$_C"★" + if [ "`strings /proc/$SSH_AGENT_PID/cmdline | head -n1`" = "ssh-agent" ] + 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\} .* (.*)$" )" != "" ] + then + AGENTCOLOR="has_keys" + else + AGENTCOLOR="empty" + fi + AGENTS=$C_$agent_colors[$AGENTCOLOR]$_C"★" + fi fi - if [ "$GPG_AGENT_INFO" != "" ] + GPG_AGENT_PID="$(echo $GPG_AGENT_INFO | cut -d: -f2)" + if [ "$GPG_AGENT_PID" != "" -a -e /proc/$GPG_AGENT_PID/cmdline ] then - GPG_AGENT_PID="$(echo $GPG_AGENT_INFO | cut -d: -f2)" - if [ -e /proc/$GPG_AGENT_PID/cmdline ] + if [ "`strings /proc/$GPG_AGENT_PID/cmdline | head -n1`" = "gpg-agent" ] then - [ "`strings /proc/$GPG_AGENT_PID/cmdline | head -n1`" = "gpg-agent" ] && \ - AGENTS=$AGENTS$C_$prompt_colors[agents]$_C"☆" + AGENTCOLOR="has_keys" + AGENTS=$AGENTS$C_$agent_colors[$AGENTCOLOR]$_C"☆" fi fi AGENTS=${AGENTS:+$SEPARATOR$AGENTS} -- cgit v1.2.3