dotfiles/config/shell/shenv

48 lines
1 KiB
Plaintext
Raw Normal View History

2019-04-14 19:41:33 +02:00
#!/usr/bin/env sh
#
# Shell common environment variables and functions (BusyBox compatible)
#
# Favourite commands
2019-04-25 22:54:51 +02:00
# And for the rest, see aliases
2019-04-25 22:54:51 +02:00
direnv JUNKHOME "$HOME/.cache/junkhome"
2020-08-20 21:38:48 +02:00
# SSH Agent
2021-06-29 20:54:25 +02:00
2020-08-20 21:38:48 +02:00
# If GPG agent is configured for SSH
if grep -q ^enable-ssh-support$ $GNUPGHOME/gpg-agent.conf 2> /dev/null
then
2020-08-20 21:38:48 +02:00
# Load GPG agent
unset SSH_AGENT_PID
if [ "${gnupg_SSH_AUTH_SOCK_by:-0}" -ne $$ ]; then
export SSH_AUTH_SOCK="$(gpgconf --list-dirs agent-ssh-socket)"
fi
else
# Start regular SSH agent if not already started
2021-07-04 11:48:00 +02:00
SSH_ENV="$HOME/.ssh/agent"
start_agent() {
ssh-agent > "${SSH_ENV}"
chmod 600 "${SSH_ENV}"
. "${SSH_ENV}" > /dev/null
}
if [ -f "${SSH_ENV}" ]
then
. "${SSH_ENV}" > /dev/null
if [ ! -d "/proc/${SSH_AGENT_PID}" ] || [ "$(cat "/proc/${SSH_AGENT_PID}/comm")" != "ssh-agent" ]
then
start_agent
fi
else
start_agent
fi
fi
2021-06-29 20:54:25 +02:00
# TODO Service sytem that works without systemd,
# and can stop processes on logout