# Functions behind the Das OS bash prompt (see dprompt). Sourced by # /etc/bash/bashrc.d/das-prompt.sh and by the prompt.sh files dprompt writes. # shellcheck shell=bash # Colors when the terminal has at least 8 of them __das_has_color() { case $TERM in *color* | xterm* | rxvt* | screen* | tmux* | linux | alacritty | foot* | kitty*) return 0 ;; esac [[ $(tput colors 2>/dev/null) -ge 8 ]] } # Sets __das_git to the branch (or short commit) and "*" when there are changes __das_git_info() { command -v git >/dev/null || return 1 local branch branch=$(git symbolic-ref --short -q HEAD 2>/dev/null || git rev-parse --short -q HEAD 2>/dev/null) || return 1 [[ -n $branch ]] || return 1 if [[ -n $(git status --porcelain -uno 2>/dev/null | head -c1) ]]; then branch+="*" fi __das_git=$branch } # Sets __das_jobs to the number of background jobs; fails when there are none __das_jobs_count() { local count='\j' __das_jobs=${count@P} ((__das_jobs > 0)) } # Runs first in PROMPT_COMMAND: keeps the exit status for the prompt and fills # the variables of its conditional parts __das_prompt_hook() { __das_rc=$? # Void's /etc/skel/.bashrc sets its own PS1 after /etc/bash/bashrc.d: put # the Das OS one back, once, unless the user has a PS1 of their own if [[ -n ${__das_ps1+set} ]]; then [[ $PS1 == '[\u@\h \W]\$ ' ]] && PS1=$__das_ps1 unset __das_ps1 fi declare -F __das_prompt_dynamic >/dev/null && __das_prompt_dynamic return "$__das_rc" } __das_prompt_install() { __das_ps1=$PS1 local cmd for cmd in "${PROMPT_COMMAND[@]}"; do [[ $cmd == __das_prompt_hook ]] && return 0 done PROMPT_COMMAND=(__das_prompt_hook "${PROMPT_COMMAND[@]}") }