diff options
Diffstat (limited to 'zsh/zshrc.d/prompt.zsh')
-rw-r--r-- | zsh/zshrc.d/prompt.zsh | 39 |
1 files changed, 24 insertions, 15 deletions
diff --git a/zsh/zshrc.d/prompt.zsh b/zsh/zshrc.d/prompt.zsh index 898031ea..b612c704 100644 --- a/zsh/zshrc.d/prompt.zsh +++ b/zsh/zshrc.d/prompt.zsh @@ -11,25 +11,25 @@ prompt() { # Basic prompt shape depends on whether we're in SSH or not PS1= if [[ -n $SSH_CLIENT ]] || [[ -n $SSH_CONNECTION ]] ; then - PS1=$PS1'%n@%m:' + PS1=$PS1'%m:' fi PS1=$PS1'%~' # 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 + (zsh) ;; + (*) PS1=zsh:$PS1 ;; + esac + # Add prefix and suffix PS1='${PROMPT_PREFIX}'$PS1'${PROMPT_SUFFIX}' # Add terminating "$" or "#" sign PS1=$PS1'%#' - # Add > symbols to show nested shells - local shlvl - for ((shlvl = 1; shlvl < SHLVL; shlvl++)) ; do - PS1='>'$PS1 - done - # Bold and color the prompt if it looks like we can if (( $({ tput colors || tput Co ; } 2>/dev/null) >= 8 )) ; then PS1='%B%F{cyan}'$PS1'%f%b' @@ -44,10 +44,13 @@ prompt() { # Revert to simple inexpensive prompts off) - PS1='\$ ' + PS1='$ ' PS2='> ' PS3='? ' PS4='+ ' + if [[ -n $SSH_CLIENT || -n $SSH_CONNECTION ]] ; then + PS1=$(hostname -s)'$ ' + fi ;; # Git prompt function @@ -73,7 +76,7 @@ prompt() { git describe --tags --exact-match HEAD || git rev-parse --short HEAD ) || return - name=${name##*/} + name=${name#refs/*/} [[ -n $name ]] || return # Check various files in .git to flag processes @@ -122,7 +125,10 @@ prompt() { # Print the status in brackets; add a git: prefix only if there # might be another VCS prompt (because PROMPT_VCS is set) printf '(%s%s%s%s)' \ - "${PROMPT_VCS:+git:}" "$name" "${proc:+:"$proc"}" "$state" + "${PROMPT_VCS:+git:}" \ + "${name//\%/%%}" \ + "${proc:+:"${proc//\%/%%}"}" \ + "${state//\%/%%}" ;; # Subversion prompt function @@ -148,6 +154,7 @@ prompt() { branch=${branch#/} branch=${branch#branches/} branch=${branch%%/*} + [[ -n $branch ]] || branch=unknown # Parse the output of svn status to determine working copy state local symbol @@ -165,7 +172,9 @@ prompt() { ((untracked)) && state=${state}'?' # Print the state in brackets with an svn: prefix - printf '(svn:%s%s)' "${branch:-unknown}" "$state" + printf '(svn:%s%s)' \ + "${branch//\%/%%}" \ + "${state//\%/%%}" ;; # VCS wrapper prompt function; print the first relevant prompt, if any @@ -179,7 +188,7 @@ prompt() { # Show return status of previous command in angle brackets, if not zero ret) # shellcheck disable=SC2154 - ((ret)) && printf '<%u>' "$ret" + ((ret)) && printf '<%u>' "${ret//\%/%%}" ;; # Show the count of background jobs in curly brackets, if not zero @@ -188,7 +197,7 @@ prompt() { while read -r ; do ((jobc++)) done < <(jobs -p) - ((jobc)) && printf '{%u}' "$jobc" + ((jobc)) && printf '{%u}' "${jobc//\%/%%}" ;; # No argument given, print prompt strings and vars @@ -204,5 +213,5 @@ prompt() { esac } -# Start with full-fledged prompt -prompt on +# Default to a full-featured prompt, but use PROMPT_MODE if that's set +prompt "${PROMPT_MODE:-on}" |