Source

dotfiles / .bashrc.d / 10_ssh.sh

Full commit
#/bin/bash

if [ "${UNAME}" != "SunOS" ]; then
	AGENT_FILE=$HOME/.ssh-agent.sh
	if ps aux | awk -v USER=$(id -un) -v UID=$(id -u) 'BEGIN {exitcode=0}; ($1 ~ USER || $1 ~ UID) && $0 ~ "ssh-agent" && $0 !~ "awk" && $0 !~ "<defunct>" {exitcode++}; END {exit exitcode}'; then
	    rm -f $AGENT_FILE
	    ssh-agent | grep -v echo >&$AGENT_FILE
	fi

	sss() {
	# Solaris specific ssh, we want a terminal environment that is understod on said platform.

	    TERM=xterm ssh "$@"

	}

	shopt -u hostcomplete && AddArrayCompletion _ssh sss

	if [[ -n "${SSH_AUTH_SOCK}" && -n "${SSH_AGENT_PID}" ]]; then
		if ! Quiet grep -F "${SSH_AUTH_SOCK}" "${AGENT_FILE}" || \
		   ! Quiet grep -F "${SSH_AGENT_PID}" "${AGENT_FILE}"; then
			cat <<EOS >$AGENT_FILE 
SSH_AUTH_SOCK=${SSH_AUTH_SOCK}; export SSH_AUTH_SOCK;
SSH_AGENT_PID=${SSH_AGENT_PID}; export SSH_AGENT_PID;
EOS
		fi
	fi

	AddRc $AGENT_FILE
fi
# EOF