Updated fish ssh-agent to be less bloat
This commit is contained in:
parent
5f4ac03485
commit
a563d3cc4f
1 changed files with 6 additions and 73 deletions
|
@ -1,75 +1,3 @@
|
||||||
function sshagent_findsockets
|
|
||||||
find /tmp -uid (id -u) -type s -name agent.\* 2>/dev/null
|
|
||||||
end
|
|
||||||
|
|
||||||
function sshagent_testsocket
|
|
||||||
if [ ! -x (command which ssh-add) ] ;
|
|
||||||
echo "ssh-add is not available"
|
|
||||||
return 1
|
|
||||||
end
|
|
||||||
|
|
||||||
if [ X"$argv[1]" != X ] ;
|
|
||||||
set -xg SSH_AUTH_SOCK $argv[1]
|
|
||||||
end
|
|
||||||
|
|
||||||
if [ X"$SSH_AUTH_SOCK" = X ]
|
|
||||||
return 2
|
|
||||||
end
|
|
||||||
|
|
||||||
if [ -S $SSH_AUTH_SOCK ] ;
|
|
||||||
ssh-add -l > /dev/null
|
|
||||||
if [ $status = 2 ] ;
|
|
||||||
echo "Socket $SSH_AUTH_SOCK is dead! Deleting!"
|
|
||||||
rm -f $SSH_AUTH_SOCK
|
|
||||||
return 4
|
|
||||||
else ;
|
|
||||||
#echo "Found ssh-agent $SSH_AUTH_SOCK"
|
|
||||||
return 0
|
|
||||||
end
|
|
||||||
else ;
|
|
||||||
echo "$SSH_AUTH_SOCK is not a socket!"
|
|
||||||
return 3
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
function ssh_agent_init
|
|
||||||
# ssh agent sockets can be attached to a ssh daemon process or an
|
|
||||||
# ssh-agent process.
|
|
||||||
|
|
||||||
set -l AGENTFOUND 0
|
|
||||||
|
|
||||||
# Attempt to find and use the ssh-agent in the current environment
|
|
||||||
if sshagent_testsocket ;
|
|
||||||
set AGENTFOUND 1
|
|
||||||
end
|
|
||||||
|
|
||||||
# If there is no agent in the environment, search /tmp for
|
|
||||||
# possible agents to reuse before starting a fresh ssh-agent
|
|
||||||
# process.
|
|
||||||
if [ $AGENTFOUND = 0 ];
|
|
||||||
for agentsocket in (sshagent_findsockets)
|
|
||||||
if [ $AGENTFOUND != 0 ] ;
|
|
||||||
break
|
|
||||||
end
|
|
||||||
if sshagent_testsocket $agentsocket ;
|
|
||||||
set AGENTFOUND 1
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# If at this point we still haven't located an agent, it's time to
|
|
||||||
# start a new one
|
|
||||||
if [ $AGENTFOUND = 0 ] ;
|
|
||||||
echo need to start a new agent
|
|
||||||
eval (ssh-agent -c)
|
|
||||||
end
|
|
||||||
|
|
||||||
# Finally, show what keys are currently in the agent
|
|
||||||
# ssh-add -l
|
|
||||||
end
|
|
||||||
|
|
||||||
if status is-interactive
|
if status is-interactive
|
||||||
set -gx EDITOR nvim
|
set -gx EDITOR nvim
|
||||||
set -gx VISUAL nvim
|
set -gx VISUAL nvim
|
||||||
|
@ -78,5 +6,10 @@ if status is-interactive
|
||||||
set -gx MOZ_ENABLE_WAYLAND 1
|
set -gx MOZ_ENABLE_WAYLAND 1
|
||||||
set -gx _JAVA_AWT_WM_NONREPARENTING 1
|
set -gx _JAVA_AWT_WM_NONREPARENTING 1
|
||||||
|
|
||||||
ssh_agent_init
|
if not pgrep -u "$USER" ssh-agent > /dev/null;
|
||||||
|
ssh-agent -c > "$XDG_RUNTIME_DIR/ssh-agent.env"
|
||||||
|
end
|
||||||
|
if [ -z $SSH_AUTH_SOCK ]
|
||||||
|
eval "$(cat $XDG_RUNTIME_DIR/ssh-agent.env)"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue