1
0
dotfiles/.config/zsh/lib/pswalk.zsh

42 lines
809 B
Bash
Raw Normal View History

2021-03-21 18:25:10 +03:00
#!/bin/zsh
typeset -Uga ZSHU_PARENTS_PID
typeset -ga ZSHU_PARENTS_NAME
function {
2024-02-28 23:22:33 +03:00
local i c g
2021-03-21 18:25:10 +03:00
2024-02-28 23:22:33 +03:00
i=${PPID}
while : ; do
[ -n "$i" ] || break
2021-04-07 15:51:49 +03:00
## don't deal with PID1
2024-02-28 23:22:33 +03:00
[ "$i" = 1 ] && break
2021-03-21 18:25:10 +03:00
2024-02-28 23:22:33 +03:00
ZSHU_PARENTS_PID+=( $i )
read -r i c g <<< $(ps -o 'ppid=,comm=' -p "$i" 2>/dev/null)
[ -n "$c" ] && ZSHU_PARENTS_NAME+=( "${c:t}" )
2021-03-21 18:25:10 +03:00
done
2024-02-28 23:22:33 +03:00
typeset -r ZSHU_PARENTS_PID ZSHU_PARENTS_NAME
2021-03-21 18:25:10 +03:00
}
typeset -gA ZSHU_RUN
z-run-test() {
2024-01-16 02:55:39 +03:00
local k i
2022-07-19 02:41:45 +03:00
2024-01-16 02:55:39 +03:00
k=$1 ; shift
2021-03-21 18:25:10 +03:00
for i ( ${ZSHU_PARENTS_NAME} ) ; do
2024-01-16 02:55:39 +03:00
(( ${+argv[(r)$i]} )) || continue
ZSHU_RUN[$k]=1
return
2021-03-21 18:25:10 +03:00
done
2024-01-16 02:55:39 +03:00
ZSHU_RUN[$k]=0
2021-03-21 18:25:10 +03:00
}
z-run-test gui konsole xterm x-terminal-emulator
2021-03-22 15:32:51 +03:00
z-run-test nested screen tmux mc
2024-01-16 02:55:39 +03:00
z-run-test nested1L mc
2021-03-21 18:25:10 +03:00
z-run-test elevated sudo su