zsh: better remote session detection with pstree

This commit is contained in:
Erin 2023-07-19 23:03:55 -04:00
parent aeac7bb99c
commit 166fc85d47

View file

@ -1,8 +1,10 @@
# Detect if the current session is running on a remote server # Detect if the current session is running on a remote server by listing parent
# Runs first because multiple other things rely on this # processes of this shell and checking for things like sshd/tailscaled. Runs
if [ -n "$IS_REMOTE_SESSION" ] || [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then # first because multiple other things rely on this.
is_remote=1
else is_remote=""
is_remote= proctree="$(pstree -s $$)"
fi echo "$proctree" | grep "sshd" && is_remote="$is_remote sshd"
export IS_REMOTE_SESSION=$is_remote echo "$proctree" | grep "tailscaled" && is_remote="$is_remote tailscaled"
[ -n "$is_remote" ] && export IS_REMOTE_SESSION="$(echo $is_remote | xargs)"