bash: tidy ssh-agent logic; add fig support

This commit is contained in:
2022-08-25 22:39:39 +01:00
parent c34cb696f5
commit 28afa9b569

53
bashrc
View File

@@ -1,3 +1,5 @@
# Fig pre block. Keep at the top of this file.
[[ -f "$HOME/.fig/shell/bashrc.pre.bash" ]] && . "$HOME/.fig/shell/bashrc.pre.bash"
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
@@ -106,30 +108,30 @@ if [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
SSH_AGENT_FILE=$HOME/ssh.sh
if [ -f $SSH_AGENT_FILE ] ; then
FILE_PID=$(grep SSH_AGENT_PID $SSH_AGENT_FILE | sed -e 's/^.*=//' | sed -e 's/;.*$//')
RUNNING_PID=$(pgrep -U $USER ssh-agent)
if [ "$RUNNING_PID" == "" ] ; then
# No agent running
echo Starting ssh-agent, you need to load keys though.
ssh-agent > $SSH_AGENT_FILE
. $SSH_AGENT_FILE
elif [ "$RUNNING_PID" != "$FILE_PID" ] ; then
echo Mismatch - file has $FILE_PID, system has $RUNNING_PID
echo 'File is out of date; you might need to kill things and start again.'
else
# PIDs match, let\'s use the file
. $SSH_AGENT_FILE 1>/dev/null
KEYCOUNT=$(ssh-add -l | grep -v "The agent has no identities" | wc -l)
echo Using ssh-agent $RUNNING_PID, $KEYCOUNT keys loaded
fi
else
# Assume no agent running
echo Starting ssh-agent, you need to load keys though.
ssh-agent > $SSH_AGENT_FILE
. $SSH_AGENT_FILE
fi
# SSH_AGENT_FILE=$HOME/ssh.sh
# if [ -f $SSH_AGENT_FILE ] ; then
# FILE_PID=$(grep SSH_AGENT_PID $SSH_AGENT_FILE | sed -e 's/^.*=//' | sed -e 's/;.*$//')
# RUNNING_PID=$(pgrep -U $USER ssh-agent)
# if [ "$RUNNING_PID" == "" ] ; then
# # No agent running
# echo Starting ssh-agent, you need to load keys though.
# ssh-agent > $SSH_AGENT_FILE
# . $SSH_AGENT_FILE
# elif [ "$RUNNING_PID" != "$FILE_PID" ] ; then
# echo Mismatch - file has $FILE_PID, system has $RUNNING_PID
# echo 'File is out of date; you might need to kill things and start again.'
# else
# # PIDs match, let\'s use the file
# . $SSH_AGENT_FILE 1>/dev/null
# KEYCOUNT=$(ssh-add -l | grep -v "The agent has no identities" | wc -l)
# echo Using ssh-agent $RUNNING_PID, $KEYCOUNT keys loaded
# fi
# else
# # Assume no agent running
# echo Starting ssh-agent, you need to load keys though.
# ssh-agent > $SSH_AGENT_FILE
# . $SSH_AGENT_FILE
# fi
if [ "$HOME2" != "" ] ; then
@@ -162,3 +164,6 @@ export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH"
# Fig post block. Keep at the bottom of this file.
[[ -f "$HOME/.fig/shell/bashrc.post.bash" ]] && . "$HOME/.fig/shell/bashrc.post.bash"