zsh: better remote session detection with pstree
This commit is contained in:
parent
aeac7bb99c
commit
166fc85d47
|
@ -1,8 +1,10 @@
|
|||
# Detect if the current session is running on a remote server
|
||||
# Runs first because multiple other things rely on this
|
||||
if [ -n "$IS_REMOTE_SESSION" ] || [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then
|
||||
is_remote=1
|
||||
else
|
||||
is_remote=
|
||||
fi
|
||||
export IS_REMOTE_SESSION=$is_remote
|
||||
# Detect if the current session is running on a remote server by listing parent
|
||||
# processes of this shell and checking for things like sshd/tailscaled. Runs
|
||||
# first because multiple other things rely on this.
|
||||
|
||||
is_remote=""
|
||||
proctree="$(pstree -s $$)"
|
||||
echo "$proctree" | grep "sshd" && is_remote="$is_remote sshd"
|
||||
echo "$proctree" | grep "tailscaled" && is_remote="$is_remote tailscaled"
|
||||
|
||||
[ -n "$is_remote" ] && export IS_REMOTE_SESSION="$(echo $is_remote | xargs)"
|
||||
|
|
Loading…
Reference in a new issue