Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Auto-launching ssh-agent in fish shell
# content has to be in .config/fish/config.fish
# if it does not exist, create the file
setenv SSH_ENV $HOME/.ssh/environment
function start_agent
echo "Initializing new SSH agent ..."
ssh-agent -c | sed 's/^echo/#echo/' > $SSH_ENV
echo "succeeded"
chmod 600 $SSH_ENV
. $SSH_ENV > /dev/null
ssh-add
end
function test_identities
ssh-add -l | grep "The agent has no identities" > /dev/null
if [ $status -eq 0 ]
ssh-add
if [ $status -eq 2 ]
start_agent
end
end
end
if [ -n "$SSH_AGENT_PID" ]
ps -ef | grep $SSH_AGENT_PID | grep ssh-agent > /dev/null
if [ $status -eq 0 ]
test_identities
end
else
if [ -f $SSH_ENV ]
. $SSH_ENV > /dev/null
end
ps -ef | grep $SSH_AGENT_PID | grep -v grep | grep ssh-agent > /dev/null
if [ $status -eq 0 ]
test_identities
else
start_agent
end
end
@Zabanaa

This comment has been minimized.

Copy link

Zabanaa commented Dec 4, 2016

thanks a ton for this 😄

@dehein

This comment has been minimized.

Copy link

dehein commented Jan 10, 2017

What does, the ssh-add command do? normally i would think i should add my keys here like:
ssh-add ~/.ssh/id_rsa ssh-add ~/.ssh/ed_25519
or am i thinking wrong.

@denniswebb

This comment has been minimized.

Copy link

denniswebb commented Apr 12, 2017

Good work.

@MichaelKlemersson

This comment has been minimized.

Copy link

MichaelKlemersson commented Jun 30, 2017

thanks a lot :)

@csvan

This comment has been minimized.

Copy link

csvan commented Sep 16, 2017

This is perfect, thank you so much.

@kgourgou

This comment has been minimized.

Copy link

kgourgou commented Nov 14, 2017

Great stuff! 👍 👍

@kave

This comment has been minimized.

Copy link

kave commented Aug 8, 2018

just what i was looking for 👍

@noahjohn9259

This comment has been minimized.

Copy link

noahjohn9259 commented Feb 25, 2019

Great stuff!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.