Last active
August 17, 2018 23:10
-
-
Save Eihen/7fececcfe9abfb55bddfcc8bf99e37c1 to your computer and use it in GitHub Desktop.
Git Bash for Windows script for SSH Agent and Keys management
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# REQUIREMENTS | |
# 1) Understanding that this script is provided as-is and I have no responsibility for whatever damage occurs | |
# That said, if the script was strictly tested and no problems should arise if you use it without any modifications | |
# of areas which not states that can be modified | |
# Also if you find any problems let me know to see if I can help you (and/or fix the script) | |
# Put this at the end of your ~/.bashrc if you already have one or just throw it in your home directory if you don't | |
# Make sure there are no other scripts starting ssh-agents or adding keys | |
# This assumes you have https://github.com/magicmonty/bash-git-prompt in your home directory | |
# If it's in another directory just change the "source $DIRECTORY" line accordingly | |
# Enable only on git repositories | |
GIT_PROMPT_ONLY_IN_REPO=1 | |
# Source the gitprompt file | |
source ~/bash-git-prompt/gitprompt.sh | |
# Check if there's any running instance of ssh-agent for the current user | |
if ! ps -u $(whoami) | grep 'ssh-agent' | grep -oE '^\s*\S*' > /dev/null; then | |
# If no instance is found | |
# Start ssh-agent and dump output to .ssh-agent-thing | |
ssh-agent > ~/.ssh-agent-thing | |
# Eval the dumped agent for the current bash | |
eval "$(<~/.ssh-agent-thing)" | |
# Add the keys from ~/.ssh ending with .key since the ssh-agent was just started | |
ssh-add $HOME/.ssh/*.key | |
# If there's a running instance check if it was already evaled for the current bash | |
elif [[ "$SSH_AGENT_PID" == "" ]]; then | |
# If no ssh-agent was evaled | |
# Eval the existing ssh-agent instance for the current bash | |
eval "$(<~/.ssh-agent-thing)" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Known Issues: