-
Notifications
You must be signed in to change notification settings - Fork 0
/
profile
29 lines (28 loc) · 1.27 KB
/
profile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
SSHAGENT=/usr/bin/ssh-agent
# OSX/some DEs start an agent for you, so just take that
TARGET_SOCK="${SSH_AUTH_SOCK:-$HOME/.ssh/agent.sock}"
[[ ! -S $SSH_AUTH_SOCK ]] && unset SSH_AUTH_SOCK
[[ -r $TARGET_SOCK && -S $TARGET_SOCK && ( $SSH_AUTH_SOCK != $TARGET_SOCK || -z $SSH_AUTH_SOCK ) ]] && export SSH_AUTH_SOCK="$TARGET_SOCK"
if [[ -z $SSH_AUTH_SOCK && ! -S $TARGET_SOCK && -x $SSHAGENT ]]; then
eval `$SSHAGENT -s -a $TARGET_SOCK`
# prevent agent from dying whenever the spawning terminal is closed
#trap "kill $SSH_AGENT_PID" 0
fi
# add key only if it isnt already added. this assumes you are using rsa keys...
# TODO: determine the default key that ssh-add uses programmatically
ssh-add -l|grep -q "$(ssh-keygen -lf ~/.ssh/id_rsa|awk '{print $2}')" || ssh-add
# launch tmux session if we arent already inside one, and tmux is installed
# NOTE: this should live in .profile instead, so its only executed on login shells, not interactive
if [[ -z $TMUX ]] ; then
if type -p tmux &>/dev/null ; then
if tmux ls &>/dev/null ; then
# attach to whatever first session is available to us by default
# dont exec though, because we want to be able to launch a new session and tmux
# on a remote host
tmux a
else
# create a new session
tmux
fi
fi
fi