aboutsummaryrefslogtreecommitdiff
path: root/functions/ssh.sh
blob: 820e787709445fed873f296d0fcea5ed59e52700 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/bin/zsh


ssh-add -l &>/dev/null
if (( ? == 2 )); then
  # Unable to contact the authentication agent
  # Load stored agent connection info
  local -r ssh_env=${HOME}/.ssh-agent
  if [[ -r ${ssh_env} ]] source ${ssh_env} >/dev/null

  ssh-add -l &>/dev/null
  if (( ? == 2 )); then
    # Start agent and store agent connection info
    (umask 066; ssh-agent >! ${ssh_env})
    source ${ssh_env} >/dev/null
  fi
fi

local ssh_bin=$(which ssh)
auto_agent_ssh() {
  # Load identities
  ssh-add -l &>/dev/null
  if (( ? == 1 )); then
    local -a zssh_ids
    zstyle -a ':zim:ssh' ids 'zssh_ids'
    if (( ${#zssh_ids} )); then
      ssh-add ${HOME}/.ssh/${^zssh_ids} 2>/dev/null
    else
      ssh-add 2>/dev/null
    fi
  fi
 $ssh_bin "$@"
}