ssh-add

1st November 2016 at 1:26pm
BashLogout CodeSnippets

Useful when used in conjunction with BashLogout and ReusingSSHAgents.

function ssh-add () {
  if [[ $# -eq 0 ]] ; then
    declare -i endofday="$(date +"%s" -d "7pm")"
    declare -i timenow="$(date +"%s")"
    declare -i timeout="$(( endofday - timenow ))"
    [[ $timeout -lt 3600 ]] && timeout=3600
    command ssh-add -t "$timeout" "$@"
  else
    command ssh-add "$@"
  fi
}