alpha
Login
or
Join now
lass.pds.lassul.us
/
superconfig
Star
0
Fork
1
Atom
Configure Feed
Issues
Pull Requests
Commits
Tags
Feed URL
Select the types of activity you want to include in your feed.
This repository has no description
Star
0
Fork
1
Atom
Configure Feed
Issues
Pull Requests
Commits
Tags
Feed URL
Select the types of activity you want to include in your feed.
Overview
Issues
Pulls
1
Pipelines
tools.ssh-agent-pick: init
author
lassulus
date
2 weeks ago
(Oct 3, 2026, 10:55 AM CEST)
commit
7bfe22b3
7bfe22b371f6785c5a2805fe9009ea8d45d08beb
parent
f0f41c1f
f0f41c1f4c16215a7442bc5e7e51ebdb37b6ab52
+70
3 changed files
Expand all
Collapse all
Unified
Split
tools
ssh-agent-pick
flake-module.nix
ssh-agent-pick.sh
usage.kdl
+20
tools/ssh-agent-pick/flake-module.nix
View file
Reviewed
···
1
1
+
{ ... }:
2
2
+
{
3
3
+
perSystem =
4
4
+
{ pkgs, ... }:
5
5
+
{
6
6
+
packages.ssh-agent-pick =
7
7
+
(pkgs.writeShellApplication {
8
8
+
name = "ssh-agent-pick";
9
9
+
runtimeInputs = [
10
10
+
pkgs.coreutils
11
11
+
pkgs.findutils
12
12
+
pkgs.fzf
13
13
+
pkgs.gawk
14
14
+
pkgs.openssh
15
15
+
];
16
16
+
text = builtins.readFile ./ssh-agent-pick.sh;
17
17
+
}).overrideAttrs
18
18
+
{ passthru.usage = builtins.readFile ./usage.kdl; };
19
19
+
};
20
20
+
}
+48
tools/ssh-agent-pick/ssh-agent-pick.sh
View file
Reviewed
···
1
1
+
#!/usr/bin/env bash
2
2
+
# Pick one of your live forwarded SSH agents and print an export line.
3
3
+
# Usage: eval "$(ssh-agent-pick)"
4
4
+
5
5
+
uid=$(id -u)
6
6
+
cands=()
7
7
+
labels=()
8
8
+
9
9
+
# newest first: sshd creates the socket when the connection is established
10
10
+
while IFS= read -r -d '' line; do
11
11
+
sock=${line#* }
12
12
+
[ -S "$sock" ] || continue
13
13
+
[ "$(stat -c %u "$sock")" = "$uid" ] || continue
14
14
+
rc=0
15
15
+
keys=$(SSH_AUTH_SOCK=$sock ssh-add -l 2>/dev/null) || rc=$?
16
16
+
[ "$rc" -le 1 ] || continue # 2 = cannot connect (stale)
17
17
+
if [ "$rc" -eq 1 ]; then
18
18
+
keys="(no identities)"
19
19
+
else
20
20
+
keys=$(printf '%s\n' "$keys" | awk '{ $1 = $2 = ""; $NF = ""; sub(/^ +/, ""); sub(/ +$/, ""); print }' | paste -sd, -)
21
21
+
fi
22
22
+
since=$(date -d "@${line%% *}" '+%F %T')
23
23
+
cands+=("$sock")
24
24
+
labels+=("$since $keys $sock")
25
25
+
done < <(find /tmp/ssh-* "$HOME/.ssh/agent" -maxdepth 1 -type s \( -name 'agent.*' -o -name '*.sshd.*' \) \
26
26
+
-printf '%T@ %p\0' 2>/dev/null | sort -zrn)
27
27
+
28
28
+
if [ ${#cands[@]} -eq 0 ]; then
29
29
+
echo "ssh-agent-pick: no live forwarded agent found" >&2
30
30
+
exit 1
31
31
+
fi
32
32
+
33
33
+
if [ ${#cands[@]} -eq 1 ]; then
34
34
+
choice=${cands[0]}
35
35
+
elif [ -t 2 ]; then
36
36
+
sel=$(printf '%s\n' "${labels[@]}" | fzf --height=~10 --reverse --prompt='agent> ') || exit 1
37
37
+
choice=${sel##* }
38
38
+
else
39
39
+
PS3='agent> '
40
40
+
select _ in "${labels[@]}"; do
41
41
+
[ -n "${REPLY:-}" ] && [ "$REPLY" -ge 1 ] 2>/dev/null && [ "$REPLY" -le ${#cands[@]} ] || continue
42
42
+
choice=${cands[REPLY - 1]}
43
43
+
break
44
44
+
done
45
45
+
fi
46
46
+
47
47
+
[ -n "${choice:-}" ] || exit 1
48
48
+
printf "export SSH_AUTH_SOCK='%s'\n" "$choice"
+2
tools/ssh-agent-pick/usage.kdl
View file
Reviewed
···
1
1
+
bin "ssh-agent-pick"
2
2
+
about "Choose one of your live forwarded SSH agents (newest first) and print an `export SSH_AUTH_SOCK=...` line; use as eval \"$(ssh-agent-pick)\""