better ssh

This commit is contained in:
2025-09-30 01:41:20 +02:00
parent 73e220479a
commit 012ff152c6
2 changed files with 28 additions and 16 deletions

27
.scripts/ssh-init Executable file
View File

@@ -0,0 +1,27 @@
#!/bin/sh
# shellcheck disable=SC1091
mkdir -p "$HOME/.local/state"
agent_file="$HOME/.local/state/ssh-agent"
if [ -z "$SSH_AUTH_SOCK" ]; then
if [ -f "$agent_file" ] && [ -r "$agent_file" ]; then
. "$agent_file" > /dev/null 2>&1
# check if the socket is actually working
if [ "$(ssh-add -l > /dev/null 2>&1; echo $?)" -eq 2 ]; then
unset SSH_AUTH_SOCK
fi
fi
if [ -z "$SSH_AUTH_SOCK" ]; then
rm -f "$agent_file"
eval "$(ssh-agent -s | tee "$agent_file")" > /dev/null 2>&1
fi
[ -f "$agent_file" ] && (
cat "$agent_file"
exit 0
)
fi
echo "true"