Skip to content

Commit

Permalink
fix conditional expression
Browse files Browse the repository at this point in the history
  • Loading branch information
slarew committed Jul 28, 2017
1 parent 7e540ce commit 0d8d91b
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions modules/ssh/init.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ _ssh_agent_env="${_ssh_agent_env:-${TMPDIR:-/tmp}/ssh-agent.env.$UID}"

# Due to the predictability of the env file, check the env file exists and is
# owned by current EUID before trusting it.
if [ -f "$_ssh_agent_env" -a ! -O "$_ssh_agent_env" ]; then
if [[ -f "$_ssh_agent_env" && ! -O "$_ssh_agent_env" ]]; then
cat 1>&2 <<-EOF
ERROR: Cannot trust the SSH agent environment variables persistence
file because it is owned by another user.
Expand All @@ -32,32 +32,33 @@ fi
# Set the path to the persistent authentication socket.
_ssh_agent_sock="${TMPDIR:-/tmp}/ssh-agent.sock.$UID"

# Start ssh-agent if not started.
# If a socket exists at SSH_AUTH_SOCK, assume ssh-agent is already running and
# skip starting it.
if [[ ! -S "$SSH_AUTH_SOCK" ]]; then
# Export environment variables.
# Try to grab previously exported environment variables.
source "$_ssh_agent_env" 2> /dev/null

# Start ssh-agent if not started.
if ! ps -U "$LOGNAME" -o pid,ucomm | grep -q -- "${SSH_AGENT_PID:--1} ssh-agent"; then
# Do not start ssh-agent if the PID from the last start of ssh-agent exists and
# corresponds to a running ssh-agent under the current user.
if ! ps -U "$LOGNAME" -o pid,comm | grep -E -q -e "^[[:blank:]]*${SSH_AGENT_PID:--1}[[:blank:]].*ssh-agent$"; then
eval "$(ssh-agent | sed '/^echo /d' | tee "$_ssh_agent_env")"
fi
fi

# Create a persistent SSH authentication socket.
if [[ -S "$SSH_AUTH_SOCK" && "$SSH_AUTH_SOCK" != "$_ssh_agent_sock" ]]; then
ln -sf "$SSH_AUTH_SOCK" "$_ssh_agent_sock"
export SSH_AUTH_SOCK="$_ssh_agent_sock"
fi

# Load identities.
if ssh-add -l 2>&1 | grep -q 'The agent has no identities'; then
zstyle -a ':prezto:module:ssh:load' identities '_ssh_identities'
if (( ${#_ssh_identities} > 0 )); then
ssh-add "$_ssh_dir/${^_ssh_identities[@]}" < /dev/null 2> /dev/null
else
ssh-add < /dev/null 2> /dev/null
# In macOS, `ssh-add -A` will load all identities defined in Keychain
if [[ "$(uname -s)" == "Darwin" ]]; then
ssh-add -A 2> /dev/null
else
ssh-add < /dev/null 2> /dev/null
fi
fi
fi

# Clean up.
unset _ssh_{dir,identities} _ssh_agent_{env,sock}
unset _ssh_{dir,identities,agent_env}

0 comments on commit 0d8d91b

Please sign in to comment.