diff --git a/zsh/.config/zsh/config.d/00_detect_remote.zsh b/zsh/.config/zsh/config.d/00_detect_remote.zsh index 5f83d78..827620c 100644 --- a/zsh/.config/zsh/config.d/00_detect_remote.zsh +++ b/zsh/.config/zsh/config.d/00_detect_remote.zsh @@ -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)"