Skip to content

Instantly share code, notes, and snippets.

@RaitoBezarius
Created December 28, 2016 17:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RaitoBezarius/2de1ab8ad155d6644d198594dfe9a117 to your computer and use it in GitHub Desktop.
Save RaitoBezarius/2de1ab8ad155d6644d198594dfe9a117 to your computer and use it in GitHub Desktop.
Boot a SSH agent for Fish
set -gx SSH_ENV $HOME/.ssh/environment
function boot_new_agent
echo "Initializing new SSH agent..."
ssh-agent -c | sed 's/^echo/#echo/' > $SSH_ENV
echo "SSH agent initialized, ready to roll."
chmod 600 $SSH_ENV
. $SSH_ENV > /dev/null
ssh-add
end
function start_agent
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
boot_new_agent
end
end
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
function fish_title
if [ $_ = 'fish' ]
echo (prompt_pwd)
else
echo $_
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment