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

46 lines
983 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 {
local i cmd
i=$$ ; while : ; do
i=$(ps -o ppid= -p $i 2>/dev/null || : )
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
cmd=$(ps -o comm= -p $i 2>/dev/null || : )
[ -n "${cmd}" ] && ZSHU_PARENTS_NAME+=( "${cmd##*/}" )
done
typeset -r ZSHU_PARENTS_PID
typeset -r ZSHU_PARENTS_NAME
}
typeset -gA ZSHU_RUN
z-run-test() {
local key i
key=$1 ; shift
v=0
for i ( ${ZSHU_PARENTS_NAME} ) ; do
if (( ${+argv[(r)$i]} )) ; then
ZSHU_RUN[${key}]=1
return
fi
done
ZSHU_RUN[${key}]=0
}
z-run-test gui konsole xterm x-terminal-emulator
2021-03-22 15:32:51 +03:00
z-run-test nested screen tmux mc
z-run-test nested1 mc
2021-03-21 18:25:10 +03:00
z-run-test elevated sudo su