diff options
author | Mike Crute <mike@crute.us> | 2020-10-09 13:10:16 -0700 |
---|---|---|
committer | Mike Crute <mike@crute.us> | 2020-10-09 13:10:16 -0700 |
commit | bd0b9fc249ae53f041818f95c9aafd0e21b7827c (patch) | |
tree | e643d26c3282e10be31c72f48695af9aea4501b7 /.bashrc | |
parent | ca943bbb12799cf0266c75d0e49f10d8c34083e6 (diff) | |
download | dotfiles-bd0b9fc249ae53f041818f95c9aafd0e21b7827c.tar.bz2 dotfiles-bd0b9fc249ae53f041818f95c9aafd0e21b7827c.tar.xz dotfiles-bd0b9fc249ae53f041818f95c9aafd0e21b7827c.zip |
bash: be aware of existing ssh agents
Diffstat (limited to '.bashrc')
-rw-r--r-- | .bashrc | 26 |
1 files changed, 19 insertions, 7 deletions
@@ -598,11 +598,28 @@ function get_ssh_agent | |||
598 | done | 598 | done |
599 | 599 | ||
600 | local agent_out="$HOME/.ssh/agent.out-$(hostname)" | 600 | local agent_out="$HOME/.ssh/agent.out-$(hostname)" |
601 | source $agent_out &>/dev/null | ||
602 | 601 | ||
602 | # Check if agent is already started. This often happens early in | ||
603 | # the startup process for X11 (see /etc/X11/xinit/xinitrc-common). | ||
604 | # If the agent was already started then our local state file is | ||
605 | # probably out of date with our environment file, update it so that | ||
606 | # other sessions in other shells that may not be connected to this | ||
607 | # X11 session use the same agent. | ||
608 | ssh-add -l &>/dev/null | ||
609 | if [[ $? -ne 2 ]]; then | ||
610 | echo "SSH_AUTH_SOCK=${SSH_AUTH_SOCK}; export SSH_AUTH_SOCK;" > "$agent_out" | ||
611 | echo "SSH_AGENT_PID=${SSH_AGENT_PID}; export SSH_AGENT_PID;" >> "$agent_out" | ||
612 | echo "echo Agent pid ${SSH_AGENT_PID};" >> "$agent_out" | ||
613 | fi | ||
614 | |||
615 | source "$agent_out" &>/dev/null | ||
616 | |||
617 | # If the agent still isn't connected after sourcing our local agent | ||
618 | # state file then it probably isn't running at all. Start a new | ||
619 | # agent and update the state file. | ||
603 | ssh-add -l &>/dev/null | 620 | ssh-add -l &>/dev/null |
604 | if [[ $? -eq 2 && -n "$start_agent" ]]; then | 621 | if [[ $? -eq 2 && -n "$start_agent" ]]; then |
605 | eval $(ssh-agent | tee $agent_out) &>/dev/null | 622 | eval $(ssh-agent | tee "$agent_out") &>/dev/null |
606 | fi | 623 | fi |
607 | 624 | ||
608 | if [[ -n "$load_keys" ]]; then | 625 | if [[ -n "$load_keys" ]]; then |
@@ -699,8 +716,3 @@ done | |||
699 | 716 | ||
700 | [[ -r ~/.homebrew_github_api_token ]] && export HOMEBREW_GITHUB_API_TOKEN=$(cat ~/.homebrew_github_api_token) | 717 | [[ -r ~/.homebrew_github_api_token ]] && export HOMEBREW_GITHUB_API_TOKEN=$(cat ~/.homebrew_github_api_token) |
701 | [[ -f ~/.bashrc_local ]] && source ~/.bashrc_local | 718 | [[ -f ~/.bashrc_local ]] && source ~/.bashrc_local |
702 | |||
703 | # | ||
704 | # FINALIZATION | ||
705 | # | ||
706 | get_ssh_agent -s | ||