zsh: detect remote cleanup

This commit is contained in:
Erin 2023-07-20 00:31:31 -04:00
parent 6061b04da4
commit 8a918a132e

View file

@ -3,16 +3,13 @@
# first because multiple other things rely on this.
# names of daemon processes a remote shell might be a child process of
declare -a remote_daemons
remote_daemons=(
sshd
tailscaled
)
declare -a is_remote
is_remote=()
parent_procs="$(pstree -s $$)"
for d in $remote_daemons[@]; [[ "$parent_procs" =~ "$d" ]] && is_remote+="$d"
proctree="$(pstree -s $$)"
for d in $remote_daemons[@]; [[ "$proctree" =~ "$d" ]] && is_remote+="$d"
[ -n "$is_remote" ] && export IS_REMOTE_SESSION="$is_remote[@]"
[ $#is_remote -gt 0 ] && export IS_REMOTE_SESSION="$is_remote[@]"