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. # ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc) # see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples # for examples
@@ -106,30 +108,30 @@ if [ -f /etc/bash_completion ]; then
. /etc/bash_completion . /etc/bash_completion
fi fi
SSH_AGENT_FILE=$HOME/ssh.sh # SSH_AGENT_FILE=$HOME/ssh.sh
if [ -f $SSH_AGENT_FILE ] ; then # if [ -f $SSH_AGENT_FILE ] ; then
FILE_PID=$(grep SSH_AGENT_PID $SSH_AGENT_FILE | sed -e 's/^.*=//' | sed -e 's/;.*$//') # FILE_PID=$(grep SSH_AGENT_PID $SSH_AGENT_FILE | sed -e 's/^.*=//' | sed -e 's/;.*$//')
RUNNING_PID=$(pgrep -U $USER ssh-agent) # RUNNING_PID=$(pgrep -U $USER ssh-agent)
if [ "$RUNNING_PID" == "" ] ; then # if [ "$RUNNING_PID" == "" ] ; then
# No agent running # # No agent running
echo Starting ssh-agent, you need to load keys though. # echo Starting ssh-agent, you need to load keys though.
ssh-agent > $SSH_AGENT_FILE # ssh-agent > $SSH_AGENT_FILE
. $SSH_AGENT_FILE # . $SSH_AGENT_FILE
elif [ "$RUNNING_PID" != "$FILE_PID" ] ; then # elif [ "$RUNNING_PID" != "$FILE_PID" ] ; then
echo Mismatch - file has $FILE_PID, system has $RUNNING_PID # 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.' # echo 'File is out of date; you might need to kill things and start again.'
else # else
# PIDs match, let\'s use the file # # PIDs match, let\'s use the file
. $SSH_AGENT_FILE 1>/dev/null # . $SSH_AGENT_FILE 1>/dev/null
KEYCOUNT=$(ssh-add -l | grep -v "The agent has no identities" | wc -l) # KEYCOUNT=$(ssh-add -l | grep -v "The agent has no identities" | wc -l)
echo Using ssh-agent $RUNNING_PID, $KEYCOUNT keys loaded # echo Using ssh-agent $RUNNING_PID, $KEYCOUNT keys loaded
fi # fi
else # else
# Assume no agent running # # Assume no agent running
echo Starting ssh-agent, you need to load keys though. # echo Starting ssh-agent, you need to load keys though.
ssh-agent > $SSH_AGENT_FILE # ssh-agent > $SSH_AGENT_FILE
. $SSH_AGENT_FILE # . $SSH_AGENT_FILE
fi # fi
if [ "$HOME2" != "" ] ; then 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 [ -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" 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"