dotfiles.2022/_home/dot_sz.shrc.d/02_shlvl

24 lines
657 B
Plaintext

function shlvl() {
local SHLVL_VAR="SHLVL_${SFP##*.}"
local SHELLS=$( \
cat /etc/shells \
| tail +2 \
| sed 's/.*\///' \
| sort -u \
| grep -v tmux \
| paste -sd '|' \
)
local SHLVL_VAL=$(eval "printf '%s' \"\$$SHLVL_VAR\"")
if [[ -z "$SHLVL_VAL" ]]; then
SHLVL_VAL=$(( $( \
pstree -s $$ \
| head -1 \
| sed -r 's/-\+-/---/g; s/-[^-]+---oh-my-posh---.*/-/; s/---/\n/g;' \
| grep -Ec "^($SHELLS)$"
) - ${1:-1} ))
eval "export $SHLVL_VAR=$SHLVL_VAL"
fi
echo $SHLVL_VAL
}
shlvl > /dev/null