mirror of
https://github.com/lloeki/dotfiles.git
synced 2025-12-06 07:24:39 +01:00
57 lines
1.5 KiB
Bash
Executable file
57 lines
1.5 KiB
Bash
Executable file
# start ssh agent, if no agent set
|
|
if [[ -n "${XDG_RUNTIME_DIR}" && -z "${SSH_AUTH_SOCK}" ]]; then
|
|
# XDG should make this linux only
|
|
# macOS starts its own agent, so, doubly so
|
|
|
|
if ! pgrep -u "$USER" ssh-agent > /dev/null; then
|
|
ssh-agent -t 24h > "${XDG_RUNTIME_DIR}/ssh-agent.env"
|
|
fi
|
|
|
|
if [[ ! -S "${SSH_AUTH_SOCK}" ]] && [[ -f "${XDG_RUNTIME_DIR}/ssh-agent.env" ]]; then
|
|
source "${XDG_RUNTIME_DIR}/ssh-agent.env" > /dev/null
|
|
fi
|
|
fi
|
|
|
|
# autoload keys if there's an agent
|
|
if [[ -n "${SSH_AUTH_SOCK}" ]]; then
|
|
if ! command ssh-add -l > /dev/null; then
|
|
case "${OSTYPE}" in
|
|
linux*)
|
|
# TODO: unsure yet
|
|
# maybe:
|
|
# ssh-add ~/.ssh/id_*[!.pub]
|
|
# or on demand:
|
|
# see ssh_config(5) AddKeysToAgent yes or ask
|
|
# see ssh(1) SSH_ASKPASS=/path/to/ask / SSH_ASKPASS_REQUIRE=prefer
|
|
:
|
|
;;
|
|
darwin*)
|
|
ssh-add -q --apple-load-keychain
|
|
;;
|
|
*)
|
|
:
|
|
;;
|
|
esac
|
|
fi
|
|
|
|
case "${OSTYPE}" in
|
|
linux*)
|
|
SSH_ASKPASS="${DOTFILES_BIN_DIR}/ssh-askpass-rofi"
|
|
SSH_ASKPASS_REQUIRE='prefer'
|
|
export SSH_ASKPASS SSH_ASKPASS_REQUIRE
|
|
;;
|
|
*)
|
|
:
|
|
;;
|
|
esac
|
|
fi
|
|
|
|
function ssh-add() {
|
|
if [[ $# -eq 0 ]]; then
|
|
command ssh-add ~/.ssh/id_*[!.pub]
|
|
else
|
|
command ssh-add "$@"
|
|
fi
|
|
}
|
|
|
|
# vim: ft=bash
|