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