Skip to content

Instantly share code, notes, and snippets.

@james-huston
Last active January 2, 2016 11:59
Show Gist options
  • Save james-huston/8300742 to your computer and use it in GitHub Desktop.
Save james-huston/8300742 to your computer and use it in GitHub Desktop.
Some bash alias trickery for firing up ssh-agent and adding your keys on a mac
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
PATH=$PATH:$HOME/bin
# source ~/.profile, if available
if [[ -r ~/.profile ]]; then
. ~/.profile
fi
agent_started=0
if ! env | grep -q SSH_AGENT_PID >/dev/null; then
echo "Starting ssh agent"
eval $(ssh-agent -s)
agent_started=1
fi
function deploy() {
if ! ssh-add -l >/dev/null 2>&-; then
ssh-add ~/.ssh/id_rsa
fi
/path/to/deploy "$@"
}
export -f deploy
function ssh() {
if ! ssh-add -l >/dev/null 2>&-; then
ssh-add ~/.ssh/id_rsa
fi
/usr/bin/ssh "$@"
}
export -f ssh
function git() {
if ! ssh-add -l >/dev/null 2>&-; then
ssh-add ~/.ssh/id_rsa
fi
/usr/bin/git "$@"
}
export -f git
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment