stuff
This commit is contained in:
parent
cd140b9a5e
commit
2ad0fa2288
2 changed files with 32 additions and 0 deletions
31
zsh/files/sshagent.zsh
Normal file
31
zsh/files/sshagent.zsh
Normal file
|
@ -0,0 +1,31 @@
|
|||
SSH_ENV="$HOME/.ssh/environment"
|
||||
KEY="$HOME/.ssh/id_rsa"
|
||||
|
||||
function start_agent () {
|
||||
ssh-agent -s | sed 's/^echo/#echo/' > "$SSH_ENV"
|
||||
chmod 600 "$SSH_ENV"
|
||||
. "$SSH_ENV" > /dev/null
|
||||
}
|
||||
|
||||
function add_identities () {
|
||||
ssh-add -l | grep "The agent has no identities" > /dev/null
|
||||
if [ $? -eq 0 ]; then
|
||||
ssh-add $KEY &> /dev/null
|
||||
fi
|
||||
}
|
||||
|
||||
function is_ssh_agent_pid_valid () {
|
||||
ps -ef | grep $1 | grep -v grep | grep ssh-agent > /dev/null
|
||||
}
|
||||
|
||||
if [ -n "$SSH_AGENT_PID" ] && is_ssh_agent_pid_valid $SSH_AGENT_PID; then
|
||||
add_identities
|
||||
else
|
||||
if [ -f "$SSH_ENV" ]; then
|
||||
. "$SSH_ENV" > /dev/null
|
||||
fi
|
||||
if ! is_ssh_agent_pid_valid $SSH_AGENT_PID; then
|
||||
start_agent
|
||||
fi
|
||||
add_identities
|
||||
fi
|
|
@ -45,6 +45,7 @@ setopt inc_append_history
|
|||
source $ZDOTDIR/files/dircolor.zsh
|
||||
source $ZDOTDIR/files/aliases.zsh
|
||||
source $ZDOTDIR/files/direnv.zsh
|
||||
source $ZDOTDIR/files/sshagent.zsh
|
||||
zinit snippet OMZL::history.zsh
|
||||
zinit snippet OMZL::functions.zsh
|
||||
zinit snippet OMZL::completion.zsh
|
||||
|
|
Loading…
Add table
Reference in a new issue