I've been using Tailscale both at work and at home for a few years. Since
I'm logged into both tailnets at once and tailscale switch between them,
I changed my bash prompt to quickly show me which one I'm currently on.
This is the function I defined in my ~/.bashrc:
# Prompt includes currently active tailnet
__maybe_tailnet_ps1 () {
[ -S /run/tailscale/tailscaled.sock ] || return 0
case "$(tailscale status --json --peers=false | jq -r .CurrentTailnet.Name)" in
fmarier*) printf '[fm]' ;;
tailscale.com) printf '[ts]' ;;
esac
} 2>/dev/null
TSPS1='$(__maybe_tailnet_ps1)'
and then I refer to it like this:
PS1="${debian_chroot:+($debian_chroot)}\u@\h${TSPS1}:\w\$ "
The most important part in there is the socket check. Without that, the
prompt will hang if tailscaled is not running for some reason.
Add a comment