diff options
Diffstat (limited to 'bash/bashrc.d')
-rw-r--r-- | bash/bashrc.d/prompt.bash | 34 |
1 files changed, 26 insertions, 8 deletions
diff --git a/bash/bashrc.d/prompt.bash b/bash/bashrc.d/prompt.bash index f9678f20..e0a03438 100644 --- a/bash/bashrc.d/prompt.bash +++ b/bash/bashrc.d/prompt.bash @@ -7,29 +7,32 @@ prompt() { # Turn complex, colored PS1 and debugging PS4 prompts on on) # Set up pre-prompt command - PROMPT_COMMAND='history -a' + PROMPT_COMMAND='PROMPT_RETURN=$?;history -a' # If Bash 4.0 is available, trim very long paths in prompt if ((BASH_VERSINFO[0] >= 4)) ; then PROMPT_DIRTRIM=4 fi - # Basic prompt shape depends on whether we're in SSH or not + # Prompt has hostname via SSH outside of screen/tmux PS1= - if [[ -n $SSH_CLIENT || -n $SSH_CONNECTION ]] ; then + if [[ -n $SSH_CLIENT && -z $STY && -z $TMUX ]] ; then PS1=$PS1'\h:' fi PS1=$PS1'\w' - # Add sub-commands; VCS, job, and return status checks - PS1=$PS1'$(ret=$?;prompt vcs;prompt job;prompt ret)' - # Add a helpful prefix if this shell appears to be exotic case ${SHELL##*/} in (bash) ;; (*) PS1=bash:$PS1 ;; esac + # Add sub-commands: + ## Preload libraries as prefix + PS1='$(prompt preload)'$PS1 + ## VCS, job, and return status checks as suffixes + PS1=$PS1'$(prompt vcs;prompt job;prompt ret)' + # Add prefix and suffix PS1='${PROMPT_PREFIX}'$PS1'${PROMPT_SUFFIX}' @@ -92,6 +95,21 @@ prompt() { fi ;; + # Analyze LD_PRELOAD to see if we should report anything loaded + preload) + printf '%s:' "$LD_PRELOAD" | + while read -d : -r ; do + case $REPLY in + (*/libip2unix.so) + printf '[IP2Unix]' + ;; + (*/libtorsocks.so) + printf '[Tor]' + ;; + esac + done + ;; + # Git prompt function git) @@ -249,8 +267,8 @@ prompt() { # Show return status of previous command in angle brackets, if not zero ret) # shellcheck disable=SC2154 - ((ret)) || return - printf '<%u>' "${ret//\\/\\\\}" + ((PROMPT_RETURN)) || return + printf '<%u>' "${PROMPT_RETURN//\\/\\\\}" ;; # Show the count of background jobs in curly brackets, if not zero |