Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
oh-my-zsh
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
github
oh-my-zsh
Commits
3f0672ff
Unverified
Commit
3f0672ff
authored
Aug 26, 2021
by
Marc Cornellà
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor(ssh-agent): clean up and reorganize code
parent
7692881d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
25 deletions
+24
-25
ssh-agent.plugin.zsh
plugins/ssh-agent/ssh-agent.plugin.zsh
+24
-25
No files found.
plugins/ssh-agent/ssh-agent.plugin.zsh
View file @
3f0672ff
# Get the filename to store/lookup the environment from
ssh_env_cache
=
"
$HOME
/.ssh/environment-
$SHORT_HOST
"
function
_start_agent
()
{
function
_start_agent
()
{
# Check if ssh-agent is already running
if
[[
-f
"
$ssh_env_cache
"
]]
;
then
.
"
$ssh_env_cache
"
>
/dev/null
{
[[
"
$USERNAME
"
=
root
]]
&&
command
ps ax
||
command
ps x
}
|
command grep
ssh-agent |
command grep
-q
$SSH_AGENT_PID
&&
return
0
fi
# Set a maximum lifetime for identities added to ssh-agent
local
lifetime
local
lifetime
zstyle
-s
:omz:plugins:ssh-agent lifetime lifetime
zstyle
-s
:omz:plugins:ssh-agent lifetime lifetime
# start ssh-agent and setup environment
# start ssh-agent and setup environment
echo
Starting ssh-agent...
echo
Starting ssh-agent...
ssh-agent
-s
${
lifetime
:+-t
}
${
lifetime
}
|
sed
'
s/^echo/#echo/'
>!
$_ssh_env_cache
ssh-agent
-s
${
lifetime
:+-t
}
${
lifetime
}
|
sed
'
/^echo/d'
>!
"
$ssh_env_cache
"
chmod
600
$_ssh_env_cache
chmod
600
"
$ssh_env_cache
"
.
$_ssh_env_cache
>
/dev/null
.
"
$ssh_env_cache
"
>
/dev/null
}
}
function
_add_identities
()
{
function
_add_identities
()
{
...
@@ -71,26 +84,12 @@ function _add_identities() {
...
@@ -71,26 +84,12 @@ function _add_identities() {
ssh-add
"
${
args
[@]
}
"
${
^not_loaded
}
ssh-add
"
${
args
[@]
}
"
${
^not_loaded
}
}
}
# Get the filename to store/lookup the environment from
_ssh_env_cache
=
"
$HOME
/.ssh/environment-
$SHORT_HOST
"
# test if agent-forwarding is enabled
# test if agent-forwarding is enabled
zstyle
-b
:omz:plugins:ssh-agent agent-forwarding _agent_forwarding
zstyle
-b
:omz:plugins:ssh-agent agent-forwarding agent_forwarding
if
[[
$_agent_forwarding
==
"yes"
&&
-n
"
$SSH_AUTH_SOCK
"
]]
;
then
# Add a nifty symlink for screen/tmux if agent forwarding
# Add a nifty symlink for screen/tmux if agent forwarding
if
[[
$agent_forwarding
=
"yes"
&&
-n
"
$SSH_AUTH_SOCK
"
&&
!
-L
"
$SSH_AUTH_SOCK
"
]]
;
then
[[
-L
$SSH_AUTH_SOCK
]]
||
ln
-sf
"
$SSH_AUTH_SOCK
"
/tmp/ssh-agent-
$USERNAME
-screen
ln
-sf
"
$SSH_AUTH_SOCK
"
/tmp/ssh-agent-
$USERNAME
-screen
elif
[[
-f
"
$_ssh_env_cache
"
]]
;
then
# Source SSH settings, if applicable
.
$_ssh_env_cache
>
/dev/null
if
[[
$USERNAME
==
"root"
]]
;
then
FILTER
=
"ax"
else
FILTER
=
"x"
fi
ps
$FILTER
|
grep
ssh-agent |
grep
-q
$SSH_AGENT_PID
||
{
_start_agent
}
else
else
_start_agent
_start_agent
fi
fi
...
@@ -104,15 +103,15 @@ fi
...
@@ -104,15 +103,15 @@ fi
ret=
\$
?
ret=
\$
?
command rm -rf '
$ZSH_CACHE_DIR
/ssh-agent.lock'
command rm -rf '
$ZSH_CACHE_DIR
/ssh-agent.lock'
unset
_agent_forwarding _
ssh_env_cache
unset
agent_forwarding
ssh_env_cache
unfunction _start_agent _add_identities 2>/dev/null
unfunction _start_agent _add_identities 2>/dev/null
return
\$
ret
return
\$
ret
"
EXIT INT QUIT
"
EXIT INT QUIT
_add_identities
_add_identities
}
}
# tidy up after ourselves
unset
agent_forwarding ssh_env_cache
unset
_agent_forwarding _ssh_env_cache
unfunction _start_agent _add_identities
unfunction _start_agent _add_identities
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment