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

47 lines
951 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-01-16 02:55:39 +03:00
local i c
2021-03-21 18:25:10 +03:00
i=$$ ; while : ; do
2024-01-16 02:55:39 +03:00
i=$(ps -o ppid= -p $i 2>/dev/null) || :
2021-03-21 18:25:10 +03:00
i=${i//[^0-9]}
[[ "$i" =~ '^[1-9][0-9]*$' ]] || break
2021-04-07 15:51:49 +03:00
## don't deal with PID1
[ "$i" = 1 ] && continue
2021-03-21 18:25:10 +03:00
ZSHU_PARENTS_PID+=( $i )
done
for i ( ${ZSHU_PARENTS_PID} ) ; do
2024-01-16 02:55:39 +03:00
c=$(ps -o comm= -p $i 2>/dev/null) || :
[ -n "$c" ] || continue
2024-01-27 00:10:58 +03:00
ZSHU_PARENTS_NAME+=( "${c:t}" )
2021-03-21 18:25:10 +03:00
done
typeset -r ZSHU_PARENTS_PID
typeset -r ZSHU_PARENTS_NAME
}
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