├── .github └── FUNDING.yml ├── .gitignore ├── .vimrc.local ├── LICENSE ├── README.md ├── img ├── POLYGLOT_PROMPT_DIRTRIM_examples.png ├── abbreviated_paths_1.png ├── abbreviated_paths_2.png ├── demo.gif ├── exit-status.png ├── git-examples.png ├── local-and-remote-sessions.png ├── mit_license.svg ├── polyglot-with-several-shells.png ├── polyglot_mascot.png ├── venv.png └── zsh-line-editing.png ├── polyglot.plugin.zsh └── polyglot.sh /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: agkozak 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: [ "https://www.paypal.me/agkozak" ] 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.zwc 2 | Thumbs.db 3 | tags 4 | ._zplugin 5 | .zplugin_lstupd 6 | .*.swp 7 | ._zinit/ 8 | -------------------------------------------------------------------------------- /.vimrc.local: -------------------------------------------------------------------------------- 1 | let g:is_posix=1 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2017-2024 Alexandros Kozak 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | Polyglot mascot 3 |

4 | 5 | [![License](img/mit_license.svg)](https://opensource.org/licenses/MIT) 6 | [![GitHub tag](https://img.shields.io/github/tag/agkozak/polyglot.svg)](https://GitHub.com/agkozak/polyglot/tags/) 7 | [![GitHub Stars](https://img.shields.io/github/stars/agkozak/polyglot.svg)](https://github.com/agkozak/agkozak-zsh-theme/stargazers) 8 | 9 | # Polyglot Prompt 10 | 11 | The **Polyglot Prompt** is a dynamic prompt for Zsh, `bash`, `ksh93`, `mksh`, `pdksh`, `oksh`, `dash`, `yash`, `busybox ash`, and `osh` that uses basic ASCII symbols (and color, when possible) to show: 12 | 13 | * the username 14 | * whether a session is local or remote over SSH 15 | * an abbreviated path 16 | * the Git branch and status 17 | * the exit status of the last command, if it was not zero 18 | * any virtual environment created with `virtualenv`, `venv`, `pipenv`, `poetry`, or `conda` 19 | 20 | ![Polyglot Prompt demo](img/demo.gif) 21 | 22 | *Note: There is also support for color in `pdksh`, `oksh`, and `osh`.* 23 | 24 | ## Table of Contents 25 | 26 | - [Basics](#basics) 27 | - [Installation](#installation) 28 | - [Local and Remote Sessions](#local-and-remote-sessions) 29 | - [Abbreviated Paths](#abbreviated-paths) 30 | - [Git Branch and Status](#git-branch-and-status) 31 | + [`POLYGLOT_SHOW_UNTRACKED`](#polyglot_show_untracked) 32 | - [Exit Status](#exit-status) 33 | - [Virtual Environments](#virtual-environments) 34 | - [Kubernetes Integration](#kubernetes-integration) 35 | - [Colors in `pdksh`](#colors-in-pdksh) 36 | - [Enabling `vi` editing mode in Zsh and `bash`](#enabling-vi-editing-mode-in-zsh-and-bash) 37 | 38 | ## Basics 39 | 40 | The central functions of the prompt are the same in all supported shells: 41 | 42 | ![Polyglot working in several shells](img/polyglot-with-several-shells.png) 43 | 44 | Additionally, in Zsh and in `bash` v4.3 and higher, the Polyglot Prompt indicates `vi` insert mode with a `+`, and command mode with a `:`, at the beginning of the prompt: 45 | 46 | ![Zsh line editing](img/zsh-line-editing.png) 47 | 48 | [See below](#enabling-vi-editing-mode-in-zsh-and-bash) for instructions on how to enable `vi` mode in your shell. 49 | 50 | ## Installation 51 | 52 | The Polyglot Prompt uses one script (`polyglot.sh`) that can be sourced from the `rc` file (`.zshrc`, `.bashrc`, `.kshrc`, `.shrc`, `.mkshrc`, `.yashrc`, or `.config/oil/oshrc`) of any supported shell: 53 | 54 | . /path/to/polyglot.sh 55 | 56 | Although no framework is required, a shim (`polyglot.plugin.zsh`) is provided to help with certain Zsh frameworks. 57 | 58 | ## Local and Remote Sessions 59 | 60 | When a session is local, only the username is shown; when it is remote over SSH (or `mosh`), the hostname is also shown: 61 | 62 | ![Local and remote sessions](img/local-and-remote-sessions.png) 63 | 64 | *Note: It is exceedingly difficult to determine with accuracy whether a superuser is connected over SSH or not. In the interest of providing useful and not misleading information, this prompt always displays both username and hostname for a superuser in reverse video.* 65 | 66 | ## Abbreviated Paths 67 | 68 | In all shells, by default the Polyglot Prompt emulates the behavior that `bash` uses when `PROMPT_DIRTRIM` is set to `2`: a tilde (`~`) is prepended if the working directory is under the user's home directory, and then if more than two directory elements need to be shown, only the last two are displayed, along with an ellipsis, so that 69 | 70 | /home/pi/src/neovim/config 71 | 72 | is displayed as 73 | 74 | ![~/.../neovim/config](img/abbreviated_paths_1.png) 75 | 76 | whereas 77 | 78 | /usr/src/sense-hat/examples 79 | 80 | is displayed as 81 | 82 | ![.../sense-hat/examples](img/abbreviated_paths_2.png) 83 | 84 | that is, without a tilde. 85 | 86 | If you want to display a different number of directory elements in your Polyglot Prompt, set the environment variable `$POLYGLOT_PROMPT_DIRTRIM` in an *rc* file thus: 87 | 88 | POLYGLOT_PROMPT_DIRTRIM=4 # Or whatever number you like 89 | 90 | ![POLYGLOT_PROMPT_DIRTRIM examples](img/POLYGLOT_PROMPT_DIRTRIM_examples.png) 91 | 92 | Setting `POLYGLOT_PROMPT_DIRTRIM=0` disables path abbreviation, although `$HOME` will still be displayed as `~`. 93 | 94 | ## Git Branch and Status 95 | 96 | If the current directory contains a Git repository, the Polyglot Prompt displays the name of the working branch, along with some symbols to show changes to its status: 97 | 98 | ![Git examples](img/git-examples.png) 99 | 100 | Git Status | Symbol 101 | --- | --- 102 | Diverged | &\* 103 | Behind | & 104 | Ahead | \* 105 | New file(s) | + 106 | Deleted | x 107 | Modified | ! 108 | Renamed | > 109 | Untracked | ? 110 | 111 | ### `POLYGLOT_SHOW_UNTRACKED` 112 | 113 | If you are working on an extremely large Git repository, such as an operating system kernel, calculating the Git status can be very slow. If you need to, you can set `POLYGLOT_SHOW_UNTRACKED=0`, which will cause the Polyglot Prompt to ignore the Git status for untracked files. This will have the effect of speeding up the display of the prompt considerably. 114 | 115 | ## Exit Status 116 | 117 | If the exit status of the most recently executed command is other than zero (zero indicating success), the exit status will be displayed to the left of the prompt: 118 | 119 | ![Exit status displayed in Zsh, `bash`, and `ksh`](img/exit-status.png) 120 | 121 | ## Virtual Environments 122 | 123 | The Polyglot Prompt will display any active virtual environment created with `virtualenv`, `venv`, `pipenv`, `poetry`, or `conda` at the beginning of the prompt: 124 | 125 | ![Virtual environments](img/venv.png) 126 | 127 | ## Kubernetes Integration 128 | 129 | If you are using the Polyglot Prompt with `bash` or Zsh, you can add the Kubernetes context and namespace to your prompt with the add-on package [polyglot-kube-ps1](https://github.com/agkozak/polyglot-kube-ps1). 130 | 131 | ## Colors in `pdksh` 132 | 133 | `pdksh` supports the use of color in prompts by allowing the programmer to choose a non-printing character and to use it to delimit color escape sequences. In practice, however, there is no one non-printing character that will work perfectly for all operating systems and terminals. The Polyglot Prompt defaults to `\021` for NetBSD and OpenBSD and to `\016` for everything else. If you want to try using your own non-printing character, you can specify it with the environment variable `POLYGLOT_NP`: 134 | 135 | POLYGLOT_NP="\016" # Set this variable to any value you like 136 | 137 | If all else fails, you can set `POLYGLOT_PDKSH_COLORS=0` to disable color entirely in `pdksh`. 138 | 139 | ## Enabling `vi` editing mode in Zsh and `bash` 140 | 141 | The Polyglot Prompt does not enable `vi` editing mode for you. In Zsh, you can add 142 | 143 | bindkey -v 144 | 145 | to your `.zshrc`; for `bash`, either put 146 | 147 | set-editing-mode vi 148 | 149 | in your `.inputrc` or 150 | 151 | set -o vi 152 | 153 | in your `.bashrc`. 154 | -------------------------------------------------------------------------------- /img/POLYGLOT_PROMPT_DIRTRIM_examples.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/agkozak/polyglot/7d0a5f2dc2e50a866350ec89e09041e3aea991ac/img/POLYGLOT_PROMPT_DIRTRIM_examples.png -------------------------------------------------------------------------------- /img/abbreviated_paths_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/agkozak/polyglot/7d0a5f2dc2e50a866350ec89e09041e3aea991ac/img/abbreviated_paths_1.png -------------------------------------------------------------------------------- /img/abbreviated_paths_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/agkozak/polyglot/7d0a5f2dc2e50a866350ec89e09041e3aea991ac/img/abbreviated_paths_2.png -------------------------------------------------------------------------------- /img/demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/agkozak/polyglot/7d0a5f2dc2e50a866350ec89e09041e3aea991ac/img/demo.gif -------------------------------------------------------------------------------- /img/exit-status.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/agkozak/polyglot/7d0a5f2dc2e50a866350ec89e09041e3aea991ac/img/exit-status.png -------------------------------------------------------------------------------- /img/git-examples.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/agkozak/polyglot/7d0a5f2dc2e50a866350ec89e09041e3aea991ac/img/git-examples.png -------------------------------------------------------------------------------- /img/local-and-remote-sessions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/agkozak/polyglot/7d0a5f2dc2e50a866350ec89e09041e3aea991ac/img/local-and-remote-sessions.png -------------------------------------------------------------------------------- /img/mit_license.svg: -------------------------------------------------------------------------------- 1 | licenselicenseMITMIT -------------------------------------------------------------------------------- /img/polyglot-with-several-shells.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/agkozak/polyglot/7d0a5f2dc2e50a866350ec89e09041e3aea991ac/img/polyglot-with-several-shells.png -------------------------------------------------------------------------------- /img/polyglot_mascot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/agkozak/polyglot/7d0a5f2dc2e50a866350ec89e09041e3aea991ac/img/polyglot_mascot.png -------------------------------------------------------------------------------- /img/venv.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/agkozak/polyglot/7d0a5f2dc2e50a866350ec89e09041e3aea991ac/img/venv.png -------------------------------------------------------------------------------- /img/zsh-line-editing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/agkozak/polyglot/7d0a5f2dc2e50a866350ec89e09041e3aea991ac/img/zsh-line-editing.png -------------------------------------------------------------------------------- /polyglot.plugin.zsh: -------------------------------------------------------------------------------- 1 | # Polyglot Prompt shim for zsh frameworks 2 | 3 | # shellcheck disable=SC2148 4 | 5 | # Compile polyglot.sh with zcompile when necessary 6 | if [[ ${0:A:h}/polyglot.sh -nt ${0:A:h}/polyglot.sh.zwc ]] || [[ ! -e ${0:A:h}/polyglot.sh.zwc ]]; then 7 | zcompile -R "${0:A:h}/polyglot.sh" 8 | fi 9 | 10 | #shellcheck source=/dev/null 11 | . "${0:A:h}/polyglot.sh" 12 | -------------------------------------------------------------------------------- /polyglot.sh: -------------------------------------------------------------------------------- 1 | # _ _ _ 2 | # _ __ ___ | |_ _ __ _| | ___ | |_ 3 | # | '_ \ / _ \| | | | |/ _` | |/ _ \| __| 4 | # | |_) | (_) | | |_| | (_| | | (_) | |_ 5 | # | .__/ \___/|_|\__, |\__, |_|\___/ \__| 6 | # |_| |___/ |___/ 7 | # 8 | # Polyglot Prompt 9 | # 10 | # A dynamic color Git prompt for zsh, bash, ksh93, mksh, pdksh, oksh, dash, 11 | # yash,busybox ash, and osh 12 | # 13 | # 14 | # Source this file from a relevant dotfile (e.g. .zshrc, .bashrc, .shrc, .kshrc, 15 | # .mkshrc, .yashrc, or ~/.config/oil/oshrc) thus: 16 | # 17 | # . /path/to/polyglot.sh 18 | # 19 | # Set $POLYGLOT_PROMPT_DIRTRIM to the number of directory elements you would 20 | # like to have displayed in your prompt (the default is 2). For example, 21 | # 22 | # POLYGLOT_PROMPT_DIRTRIM=3 23 | # 24 | # results in 25 | # 26 | # ~/foo/bar/bat/quux 27 | # 28 | # displaying as 29 | # 30 | # ~/.../bar/bat/quux 31 | # 32 | # 33 | # Copyright 2017-2024 Alexandros Kozak 34 | # 35 | # Permission is hereby granted, free of charge, to any person obtaining a copy 36 | # of this software and associated documentation files (the "Software"), to 37 | # deal in the Software without restriction, including without limitation the 38 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 39 | # sell copies of the Software, and to permit persons to whom the Software is 40 | # furnished to do so, subject to the following conditions: 41 | # 42 | # The above copyright notice and this permission notice shall be included in 43 | # all copies or substantial portions of the Software. 44 | # 45 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 46 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 47 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 48 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 49 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 50 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 51 | # IN THE SOFTWARE. 52 | # 53 | # 54 | # https://github.com/agkozak/polyglot 55 | # 56 | 57 | # shellcheck shell=ksh 58 | # shellcheck disable=SC2016,SC2034,SC2088,SC3024 59 | 60 | # Only run in interactive shells 61 | case $- in 62 | *i*) ;; 63 | *) return ;; 64 | esac 65 | 66 | # Bail if the shell doesn't have command 67 | if ! type command > /dev/null 2>&1; then 68 | printf '%s\n' 'Polyglot Prompt does not support your shell.' >&2 69 | return 1 70 | fi 71 | 72 | # Don't let virtual env active scripts alter prompt 73 | VIRTUAL_ENV_DISABLE_PROMPT=1 74 | 75 | ############################################################ 76 | # Display non-zero exit status 77 | # 78 | # Arguments: 79 | # $1 exit status of last command (always $?) 80 | ############################################################ 81 | _polyglot_exit_status() { 82 | case $1 in 83 | 0) return ;; 84 | *) printf '(%d) ' "$1" ;; 85 | esac 86 | } 87 | 88 | ########################################################### 89 | # Is the user connected via SSH? 90 | ########################################################### 91 | _polyglot_is_ssh() { 92 | [ -n "${SSH_CONNECTION-}${SSH_CLIENT-}${SSH_TTY-}" ] 93 | } 94 | 95 | ########################################################### 96 | # Provide the effective user ID 97 | ########################################################### 98 | _polyglot_euid() { 99 | case ${POLYGLOT_UNAME:=$(uname -s)} in 100 | SunOS) /usr/xpg4/bin/id -u ;; 101 | *) id -u ;; 102 | esac 103 | } 104 | 105 | ########################################################### 106 | # Is the user a superuser? 107 | ########################################################### 108 | _polyglot_is_superuser() { 109 | # shellcheck disable=SC3028 110 | [ ${EUID:-$(_polyglot_euid)} -eq 0 ] 111 | } 112 | 113 | ########################################################### 114 | # Does the terminal support enough colors? 115 | ########################################################### 116 | _polyglot_has_colors() { 117 | [ -n "$ZSH_VERSION" ] && setopt LOCAL_OPTIONS NO_WARN_CREATE_GLOBAL 118 | 119 | # The DragonFly BSD system console has trouble displaying colors in pdksh 120 | case ${POLYGLOT_UNAME:=$(uname -s)} in 121 | DragonFly) 122 | case $(who am i) in *ttyv*) return 1 ;; esac 123 | ;; 124 | esac 125 | 126 | case $TERM in 127 | *-256color) POLYGLOT_TERM_COLORS=256 ;; 128 | vt100|dumb) POLYGLOT_TERM_COLORS=-1 ;; 129 | *) 130 | if command -v tput > /dev/null 2>&1; then 131 | case ${POLYGLOT_UNAME:=$(uname -s)} in 132 | FreeBSD|DragonFly) POLYGLOT_TERM_COLORS=$(tput Co) ;; 133 | UWIN*) POLYGLOT_TERM_COLORS=$(tput cols) ;; 134 | *) POLYGLOT_TERM_COLORS=$(tput colors) ;; 135 | esac 136 | else 137 | POLYGLOT_TERM_COLORS=-1 138 | fi 139 | ;; 140 | esac 141 | if [ "${POLYGLOT_TERM_COLORS:-0}" -ge 8 ]; then 142 | unset POLYGLOT_TERM_COLORS 143 | return 0 144 | else 145 | unset POLYGLOT_TERM_COLORS 146 | return 1 147 | fi 148 | } 149 | 150 | ############################################################ 151 | # Emulation of bash's PROMPT_DIRTRIM for all other shells 152 | # and for bash before v4.0 153 | # 154 | # In $PWD, substitute $HOME with ~; if the remainder of the 155 | # $PWD has more than a certain number of directory elements 156 | # to display (default: 2), abbreviate it with '...', e.g. 157 | # 158 | # $HOME/dotfiles/polyglot/img 159 | # 160 | # will be displayed as 161 | # 162 | # ~/.../polyglot/img 163 | # 164 | # If $1 is 0, no abbreviation will occur other than that 165 | # $HOME will be displayed as ~. 166 | # 167 | # Arguments: 168 | # $1 Number of directory elements to display 169 | ############################################################ 170 | _polyglot_prompt_dirtrim() { 171 | # Necessary for set -- $1 to undergo field separation in zsh 172 | [ -n "$ZSH_VERSION" ] && setopt LOCAL_OPTIONS SH_WORD_SPLIT \ 173 | NO_WARN_CREATE_GLOBAL NO_WARN_NESTED_VAR 2> /dev/null 174 | 175 | POLYGLOT_DIRTRIM_ELEMENTS="${1:-2}" 176 | 177 | # If root has / as $HOME, print /, not ~ 178 | [ "$PWD" = '/' ] && printf '%s' '/' && return 179 | [ "$PWD" = "$HOME" ] && printf '%s' '~' && return 180 | 181 | case $HOME in 182 | /) POLYGLOT_PWD_MINUS_HOME="$PWD" ;; # In case root's $HOME is / 183 | *) POLYGLOT_PWD_MINUS_HOME="${PWD#"$HOME"}" ;; 184 | esac 185 | 186 | if [ "$POLYGLOT_DIRTRIM_ELEMENTS" -eq 0 ]; then 187 | [ "$HOME" = '/' ] && printf '%s' "$PWD" && return 188 | case $PWD in 189 | ${HOME}*) printf '~%s' "$POLYGLOT_PWD_MINUS_HOME" ;; 190 | *) printf '%s' "$PWD" ;; 191 | esac 192 | else 193 | # Calculate the part of $PWD that will be displayed in the prompt 194 | POLYGLOT_OLD_IFS="$IFS" 195 | IFS='/' 196 | # shellcheck disable=SC2086 197 | set -- $POLYGLOT_PWD_MINUS_HOME 198 | shift # Discard empty first field preceding / 199 | 200 | # Discard path elements > $POLYGLOT_PROMPT_DIRTRIM 201 | while [ $# -gt "$POLYGLOT_DIRTRIM_ELEMENTS" ]; do 202 | shift 203 | done 204 | 205 | # Reassemble the remaining path elements with slashes 206 | while [ $# -ne 0 ]; do 207 | POLYGLOT_ABBREVIATED_PATH="${POLYGLOT_ABBREVIATED_PATH}/$1" 208 | shift 209 | done 210 | 211 | IFS="$POLYGLOT_OLD_IFS" 212 | 213 | # If the working directory has not been abbreviated, display it thus 214 | if [ "$POLYGLOT_ABBREVIATED_PATH" = "${POLYGLOT_PWD_MINUS_HOME}" ]; then 215 | if [ "$HOME" = '/' ]; then 216 | printf '%s' "$PWD" 217 | else 218 | case $PWD in 219 | ${HOME}*) printf '~%s' "${POLYGLOT_PWD_MINUS_HOME}" ;; 220 | *) printf '%s' "$PWD" ;; 221 | esac 222 | fi 223 | # Otherwise include an ellipsis to show that abbreviation has taken place 224 | else 225 | if [ "$HOME" = '/' ]; then 226 | printf '...%s' "$POLYGLOT_ABBREVIATED_PATH" 227 | else 228 | case $PWD in 229 | ${HOME}*) printf '~/...%s' "$POLYGLOT_ABBREVIATED_PATH" ;; 230 | *) printf '...%s' "$POLYGLOT_ABBREVIATED_PATH" ;; 231 | esac 232 | fi 233 | fi 234 | fi 235 | 236 | unset POLYGLOT_DIRTRIM_ELEMENTS POLYGLOT_PWD_MINUS_HOME POLYGLOT_OLD_IFS \ 237 | POLYGLOT_ABBREVIATED_PATH 238 | } 239 | 240 | ########################################################### 241 | # Display current branch name, followed by symbols 242 | # representing changes to the working copy 243 | # 244 | # Arguments: 245 | # $1 If ksh, escape ! as !! 246 | # 247 | # shellcheck disable=SC2120 248 | ########################################################### 249 | _polyglot_branch_status() { 250 | [ -n "$ZSH_VERSION" ] && setopt LOCAL_OPTIONS NO_WARN_CREATE_GLOBAL \ 251 | NO_WARN_NESTED_VAR > /dev/null 2>&1 252 | 253 | POLYGLOT_REF="$(env git symbolic-ref --quiet HEAD 2> /dev/null)" 254 | case $? in # See what the exit code is. 255 | 0) ;; # $POLYGLOT_REF contains the name of a checked-out branch. 256 | 128) return ;; # No Git repository here. 257 | # Otherwise, see if HEAD is in a detached state. 258 | *) POLYGLOT_REF="$(env git rev-parse --short HEAD 2> /dev/null)" || return ;; 259 | esac 260 | 261 | if [ -n "$POLYGLOT_REF" ]; then 262 | if [ "${POLYGLOT_SHOW_UNTRACKED:-1}" -eq 0 ]; then 263 | POLYGLOT_GIT_STATUS=$(LC_ALL=C GIT_OPTIONAL_LOCKS=0 env git status -uno 2>&1) 264 | else 265 | POLYGLOT_GIT_STATUS=$(LC_ALL=C GIT_OPTIONAL_LOCKS=0 env git status 2>&1) 266 | fi 267 | 268 | POLYGLOT_SYMBOLS='' 269 | 270 | case $POLYGLOT_GIT_STATUS in 271 | *' have diverged,'*) POLYGLOT_SYMBOLS="${POLYGLOT_SYMBOLS}&*" ;; 272 | esac 273 | case $POLYGLOT_GIT_STATUS in 274 | *'Your branch is behind '*) POLYGLOT_SYMBOLS="${POLYGLOT_SYMBOLS}&" ;; 275 | esac 276 | case $POLYGLOT_GIT_STATUS in 277 | *'Your branch is ahead of '*) POLYGLOT_SYMBOLS="${POLYGLOT_SYMBOLS}*" ;; 278 | esac 279 | case $POLYGLOT_GIT_STATUS in 280 | *'new file: '*) POLYGLOT_SYMBOLS="${POLYGLOT_SYMBOLS}+" ;; 281 | esac 282 | case $POLYGLOT_GIT_STATUS in 283 | *'deleted: '*) POLYGLOT_SYMBOLS="${POLYGLOT_SYMBOLS}x" ;; 284 | esac 285 | case $POLYGLOT_GIT_STATUS in 286 | *'modified: '*) 287 | if [ "$1" = 'ksh' ]; then 288 | POLYGLOT_SYMBOLS="${POLYGLOT_SYMBOLS}!!" 289 | else 290 | POLYGLOT_SYMBOLS="${POLYGLOT_SYMBOLS}!" 291 | fi 292 | ;; 293 | esac 294 | case $POLYGLOT_GIT_STATUS in 295 | *'renamed: '*) POLYGLOT_SYMBOLS="${POLYGLOT_SYMBOLS}>" ;; 296 | esac 297 | case $POLYGLOT_GIT_STATUS in 298 | *'Untracked files:'*) POLYGLOT_SYMBOLS="${POLYGLOT_SYMBOLS}?" ;; 299 | esac 300 | 301 | [ -n "$POLYGLOT_SYMBOLS" ] && POLYGLOT_SYMBOLS=" $POLYGLOT_SYMBOLS" 302 | 303 | printf ' (%s%s)' "${POLYGLOT_REF#refs/heads/}" "$POLYGLOT_SYMBOLS" 304 | fi 305 | 306 | unset POLYGLOT_REF POLYGLOT_GIT_STATUS POLYGLOT_SYMBOLS 307 | } 308 | 309 | ########################################################### 310 | # Native sh alternative to basename. See 311 | # https://github.com/dylanaraps/pure-sh-bible 312 | # 313 | # Arguments: 314 | # $1 Filename 315 | # $2 Suffix 316 | ########################################################### 317 | _polyglot_basename() { 318 | POLYGLOT_BASENAME_DIR=${1%"${1##*[!/]}"} 319 | POLYGLOT_BASENAME_DIR=${POLYGLOT_BASENAME_DIR##*/} 320 | POLYGLOT_BASENAME_DIR=${POLYGLOT_BASENAME_DIR%"$2"} 321 | 322 | printf '%s\n' "${POLYGLOT_BASENAME_DIR:-/}" 323 | 324 | unset POLYGLOT_BASENAME_DIR 325 | } 326 | 327 | ########################################################### 328 | # Tests to see if the current shell is busybox ash 329 | ########################################################### 330 | _polyglot_is_busybox() { 331 | case $(help 2> /dev/null) in 332 | 'Built-in commands:'*) return 0 ;; 333 | *) return 1 ;; 334 | esac 335 | } 336 | 337 | ########################################################### 338 | # Test to see if the current shell is pdksh or oksh 339 | ########################################################### 340 | _polyglot_is_pdksh() { 341 | case $KSH_VERSION in 342 | *'PD KSH'*) 343 | if [ "${POLYGLOT_UNAME:=$(uname -s)}" = 'OpenBSD' ] || 344 | [ "${0#-}" = 'oksh' ]; then 345 | POLYGLOT_KSH_BANG='ksh' 346 | fi 347 | return 0 348 | ;; 349 | *) return 1 ;; 350 | esac 351 | } 352 | 353 | ########################################################### 354 | # Test to see if the current shell is dtksh (Desktop Korn 355 | # Shell). 356 | ########################################################### 357 | _polyglot_is_dtksh() { 358 | case ${0#-} in 359 | *dtksh) return 0 ;; 360 | *) return 1 ;; 361 | esac 362 | } 363 | 364 | ########################################################### 365 | # Test to see if sh is really dash 366 | ########################################################### 367 | _polyglot_sh_is_dash() { 368 | case $(ls -l "$(command -v "${0#-}")") in 369 | *dash*) return 0 ;; 370 | *) return 1 ;; 371 | esac 372 | } 373 | 374 | _polyglot_is_yash() 375 | { 376 | case "${0#-}" in 377 | *yash) return 0 ;; 378 | *) return 1 ;; 379 | esac 380 | } 381 | 382 | ########################################################### 383 | # Output virtual environment name 384 | ########################################################### 385 | _polyglot_venv() { 386 | # pipenv/poetry: when the virtualenv is in the project directory 387 | if [ "${VIRTUAL_ENV##*/}" = '.venv' ]; then 388 | POLYGLOT_VENV=${VIRTUAL_ENV%/.venv} 389 | POLYGLOT_VENV=${POLYGLOT_VENV##*/} 390 | # pipenv 391 | elif [ -n "$PIPENV_ACTIVE" ]; then 392 | POLYGLOT_VENV=${VIRTUAL_ENV%-*} 393 | POLYGLOT_VENV=${POLYGLOT_VENV##*/} 394 | # virtualenv/venv 395 | elif [ -n "$VIRTUAL_ENV" ]; then 396 | POLYGLOT_VENV=${VIRTUAL_ENV##*/} 397 | # conda 398 | elif [ -n "$CONDA_DEFAULT_ENV" ]; then 399 | POLYGLOT_VENV=$CONDA_DEFAULT_ENV 400 | fi 401 | 402 | [ -n "$POLYGLOT_VENV" ] && printf '(%s) ' "$POLYGLOT_VENV" 403 | 404 | unset POLYGLOT_VENV 405 | } 406 | 407 | ##################################################################### 408 | # zsh 409 | ##################################################################### 410 | 411 | # Make sure that ZSH is not emulating ksh or bash 412 | if [ -n "$ZSH_VERSION" ] && [ "${0#-}" != 'ksh' ] && 413 | [ "${0#-}" != 'bash' ] && [ "${0#-}" != 'sh' ]; then 414 | 415 | setopt PROMPT_SUBST 416 | 417 | ########################################################### 418 | # Runs right before the prompt is displayed 419 | # Imitates bash's PROMPT_DIRTRIM behavior and calculates 420 | # working branch and working copy status 421 | ########################################################### 422 | _polyglot_precmd() { 423 | psvar[2]=$(_polyglot_prompt_dirtrim "$POLYGLOT_PROMPT_DIRTRIM") 424 | psvar[3]=$(_polyglot_branch_status) 425 | psvar[5]=$(_polyglot_venv) 426 | 427 | PS1='' 428 | # The ZSH vi mode indicator won't work in Emacs shell (but it does in term 429 | # and ansi-term) 430 | if [ "$TERM" != 'dumb' ]; then 431 | PS1+='%(4V.:.+)' 432 | fi 433 | if _polyglot_has_colors; then 434 | PS1+='%(?..%B%F{red}(%?%)%b%f )' 435 | PS1+='%5v' 436 | PS1+='%(!.%S.%B%F{green})%n%1v%(!.%s.%f%b) ' 437 | PS1+='%B%F{blue}%2v%f%b' 438 | PS1+='%F{yellow}%3v%f %# ' 439 | else 440 | PS1+='%(?..(%?%) )' 441 | PS1+='%5v' 442 | PS1+='%(!.%S.)%n%1v%(!.%s.) ' 443 | PS1+='%2v' 444 | PS1+='%3v %# ' 445 | fi 446 | } 447 | 448 | ########################################################### 449 | # Redraw the prompt when the vi mode changes 450 | # 451 | # Whn in vi mode, the prompt will use a bash 4.3-style 452 | # mode indicator at the beginniing of the line: '+' for 453 | # insert mode; ':' for command mode 454 | # 455 | # Underscores are used in this function's name to keep 456 | # dash from choking on hyphens 457 | ########################################################### 458 | _polyglot_zle_keymap_select() { 459 | [ "$KEYMAP" = 'vicmd' ] && psvar[4]='vicmd' || psvar[4]='' 460 | zle reset-prompt 461 | zle -R 462 | } 463 | 464 | zle -N _polyglot_zle_keymap_select 465 | zle -A _polyglot_zle_keymap_select zle-keymap-select 466 | zle -A _polyglot_zle_keymap_select zle-line-init 467 | 468 | ########################################################### 469 | # Redraw prompt when terminal size changes 470 | ########################################################### 471 | TRAPWINCH() { 472 | zle && zle -R 473 | } 474 | 475 | # TODO: add-zsh-hook was added in ZSH v4.3.4. It would be nice to be 476 | # compatible with even earlier versions of ZSH, but that seems to require 477 | # use of array syntax that is incompatible with ash. 478 | autoload add-zsh-hook 479 | add-zsh-hook precmd _polyglot_precmd 480 | 481 | # Only display the $HOSTNAME for an ssh connection, except for a superuser 482 | if _polyglot_is_ssh || _polyglot_is_superuser; then 483 | psvar[1]="@${HOST%%\.*}" 484 | else 485 | psvar[1]='' 486 | fi 487 | 488 | unset RPROMPT # Clean up detritus from previously loaded prompts 489 | 490 | ##################################################################### 491 | # bash 492 | ##################################################################### 493 | elif [ -n "$BASH_VERSION" ]; then 494 | 495 | ########################################################### 496 | # Create the bash $PROMPT_COMMAND 497 | # 498 | # If $1 is 0, bash's PROMPT_DIRTRIM abbreviations will be 499 | # disabled; the only abbreviation that will occur is that 500 | # $HOME will be displayed as ~. 501 | # 502 | # Arguments: 503 | # $1 Number of directory elements to display 504 | ########################################################### 505 | _polyglot_prompt_command() { 506 | # $POLYGLOT_PROMPT_DIRTRIM must be greater than 0 and defaults to 2 507 | [ "$1" ] && PROMPT_DIRTRIM=$1 || PROMPT_DIRTRIM=2 508 | 509 | if ! _polyglot_is_superuser; then 510 | if _polyglot_has_colors; then 511 | PS1="\[\e[01;31m\]\$(_polyglot_exit_status \$?)\[\e[0m\]" 512 | PS1+="\$(_polyglot_venv)" 513 | PS1+="\[\e[01;32m\]\u$(printf '%s' "$POLYGLOT_HOSTNAME_STRING")\[\e[0m\] " 514 | case $BASH_VERSION in 515 | # bash, before v4.0, did not have $PROMPT_DIRTRIM 516 | 1.*|2.*|3.*) 517 | PS1+="\[\e[01;34m\]\$(_polyglot_prompt_dirtrim \$POLYGLOT_PROMPT_DIRTRIM)\[\e[0m\]" 518 | ;; 519 | *) PS1+="\[\e[01;34m\]\w\[\e[0m\]" ;; 520 | esac 521 | PS1+="\[\e[33m\]\$(_polyglot_branch_status)\[\e[0m\] \$ " 522 | else 523 | PS1="\$(_polyglot_exit_status \$?)" 524 | PS1+="\$(_polyglot_venv)" 525 | PS1+="\u$(printf '%s' "$POLYGLOT_HOSTNAME_STRING") " 526 | case $BASH_VERSION in 527 | 1.*|2.*|3.*) 528 | PS1="\$(_polyglot_prompt_dirtrim \$POLYGLOT_PROMPT_DIRTRIM)" 529 | ;; 530 | *) PS1+="\w" ;; 531 | esac 532 | PS1+="\$(_polyglot_branch_status) \$ " 533 | fi 534 | else # Superuser 535 | if _polyglot_has_colors; then 536 | PS1="\[\e[01;31m\]\$(_polyglot_exit_status \$?)\[\e[0m\]" 537 | PS1+="\$(_polyglot_venv)" 538 | PS1+="\[\e[7m\]\u@\h\[\e[0m\] " 539 | case $BASH_VERSION in 540 | 1.*|2.*|3.*) 541 | PS1+="\[\e[01;34m\]\$(_polyglot_prompt_dirtrim \$POLYGLOT_PROMPT_DIRTRIM)\[\e[0m\]" 542 | ;; 543 | *) PS1+="\[\e[01;34m\]\w\[\e[0m\]" ;; 544 | esac 545 | PS1+="\[\e[33m\]\$(_polyglot_branch_status)\[\e[0m\] # " 546 | else 547 | PS1="\$(_polyglot_exit_status \$?)" 548 | PS1+="\$(_polyglot_venv)" 549 | PS1+="\[\e[7m\]\u@\h\[\e[0m\] " 550 | case $BASH_VERSION in 551 | 1.*|2.*|3.*) 552 | PS1+="\$(_polyglot_prompt_dirtrim \$POLYGLOT_PROMPT_DIRTRIM)" 553 | ;; 554 | *) PS1+="\w" ;; 555 | esac 556 | PS1+="\$(_polyglot_branch_status) # " 557 | fi 558 | fi 559 | } 560 | 561 | # Only display the $HOSTNAME for an ssh connection 562 | if _polyglot_is_ssh; then 563 | POLYGLOT_HOSTNAME_STRING='@\h' 564 | else 565 | POLYGLOT_HOSTNAME_STRING='' 566 | fi 567 | 568 | PROMPT_COMMAND='_polyglot_prompt_command $POLYGLOT_PROMPT_DIRTRIM' 569 | 570 | # vi command mode 571 | if [ "$TERM" != 'dumb' ]; then # Line editing not enabled in Emacs shell 572 | bind 'set show-mode-in-prompt' # Since bash 4.3 573 | bind 'set vi-ins-mode-string "+"' 574 | bind 'set vi-cmd-mode-string ":"' 575 | fi 576 | ##################################################################### 577 | # ksh93, mksh, and zsh in bash, ksh, and sh emulation mode 578 | ##################################################################### 579 | 580 | elif [ -n "$KSH_VERSION" ] || _polyglot_is_dtksh || [ -n "$ZSH_VERSION" ] && 581 | ! _polyglot_is_pdksh ; then 582 | # Only display the $HOSTNAME for an ssh connection 583 | if _polyglot_is_ssh || _polyglot_is_superuser; then 584 | POLYGLOT_HOSTNAME_STRING=$(hostname) 585 | POLYGLOT_HOSTNAME_STRING="@${POLYGLOT_HOSTNAME_STRING%%\.*}" 586 | else 587 | POLYGLOT_HOSTNAME_STRING='' 588 | fi 589 | 590 | if [ "${0#-}" = 'bash' ] || [ "${0#-}" = 'sh' ]; then 591 | POLYGLOT_KSH_BANG='' 592 | else 593 | case $KSH_VERSION in 594 | *MIRBSD*) POLYGLOT_KSH_BANG='' ;; 595 | *) POLYGLOT_KSH_BANG='ksh' ;; 596 | esac 597 | fi 598 | 599 | case $KSH_VERSION in 600 | *MIRBSD*) 601 | # To know how long the prompt is, and thus to know how far it is to the 602 | # edge of the screen, mksh requires an otherwise unused character (in this 603 | # case \001) followed by a carriage return at the beginning of the 604 | # prompt, which is then used to mark off escape sequences as zero-length. 605 | # See https://www.mirbsd.org/htman/i386/man1/mksh.htm 606 | if ! _polyglot_is_superuser; then 607 | if _polyglot_has_colors; then 608 | PS1=$(print "\001\r\001\E[31;1m\001") 609 | PS1+='$(_polyglot_exit_status $?)' 610 | PS1+=$(print "\001\E[0m") 611 | PS1+='$(_polyglot_venv)' 612 | PS1+=$(print "\E[32;1m\001") 613 | PS1+='${LOGNAME:-$(logname)}$POLYGLOT_HOSTNAME_STRING' 614 | PS1+=$(print "\001\E[0m\001") 615 | PS1+=' ' 616 | PS1+=$(print "\001\E[34;1m\001") 617 | PS1+='$(_polyglot_prompt_dirtrim "$POLYGLOT_PROMPT_DIRTRIM")' 618 | PS1+=$(print "\001\E[0m\E[33m\001") 619 | PS1+='$(_polyglot_branch_status $POLYGLOT_KSH_BANG)' 620 | PS1+=$(print "\001\E[0m\001") 621 | PS1+=' \$ ' 622 | else 623 | PS1='$(_polyglot_exit_status $?)' 624 | PS1+='$(_polyglot_venv)' 625 | PS1+='${LOGNAME:-$(logname)}$POLYGLOT_HOSTNAME_STRING ' 626 | PS1+='$(_polyglot_prompt_dirtrim "$POLYGLOT_PROMPT_DIRTRIM")' 627 | PS1+='$(_polyglot_branch_status $POLYGLOT_KSH_BANG)' 628 | PS1+=' \$ ' 629 | fi 630 | else # Superuser 631 | if _polyglot_has_colors; then 632 | PS1=$(print "\001\r\001\E[31;1m\001") 633 | PS1+='$(_polyglot_exit_status $?)' 634 | PS1+=$(print "\001\E[0m") 635 | PS1+='$(_polyglot_venv)' 636 | PS1+=$(print "\E[7m\001") 637 | PS1+='${LOGNAME:-$(logname)}$POLYGLOT_HOSTNAME_STRING' 638 | PS1+=$(print "\001\E[0m\001") 639 | PS1+=' ' 640 | PS1+=$(print "\001\E[34;1m\001") 641 | PS1+='$(_polyglot_prompt_dirtrim "$POLYGLOT_PROMPT_DIRTRIM")' 642 | PS1+=$(print "\001\E[0m\E[33m\001") 643 | PS1+='$(_polyglot_branch_status $POLYGLOT_KSH_BANG)' 644 | PS1+=$(print "\001\E[0m\001") 645 | PS1+=' # ' 646 | else 647 | PS1=$(print "\001\r") 648 | PS1+='$(_polyglot_exit_status $?)' 649 | PS1+='$(_polyglot_venv)' 650 | PS1+=$(print "\001\E[7m\001") 651 | PS1+='${LOGNAME:-$(logname)}$POLYGLOT_HOSTNAME_STRING' 652 | PS1+=$(print "\001\E[0m\001") 653 | PS1+=' ' 654 | PS1+='$(_polyglot_prompt_dirtrim "$POLYGLOT_PROMPT_DIRTRIM")' 655 | PS1+='$(_polyglot_branch_status $POLYGLOT_KSH_BANG)' 656 | PS1+=' # ' 657 | fi 658 | fi 659 | ;; 660 | *) 661 | if ! _polyglot_is_superuser; then 662 | # zsh emulating other shells doesn't handle colors well 663 | if _polyglot_has_colors && [ -z "$ZSH_VERSION" ]; then 664 | # FreeBSD sh chokes on ANSI C quoting, so I'll avoid it 665 | PS1="$(print '\E[31;1m$(_polyglot_exit_status $?)\E[0m$(_polyglot_venv)\E[32;1m${LOGNAME:-$(logname)}$POLYGLOT_HOSTNAME_STRING\E[0m \E[34;1m$(_polyglot_prompt_dirtrim "$POLYGLOT_PROMPT_DIRTRIM")\E[0m\E[33m$(_polyglot_branch_status $POLYGLOT_KSH_BANG)\E[0m \$ ')" 666 | else 667 | PS1='$(_polyglot_exit_status $?)$(_polyglot_venv)${LOGNAME:-$(logname)}$POLYGLOT_HOSTNAME_STRING $(_polyglot_prompt_dirtrim "$POLYGLOT_PROMPT_DIRTRIM")$(_polyglot_branch_status $POLYGLOT_KSH_BANG) \$ ' 668 | fi 669 | else # Superuser 670 | if _polyglot_has_colors && [ -z "$ZSH_VERSION" ]; then 671 | PS1="$(print '\E[31;1m$(_polyglot_exit_status $?)\E[0m$(_polyglot_venv)\E[7m${LOGNAME:-$(logname)}$POLYGLOT_HOSTNAME_STRING\E[0m \E[34;1m$(_polyglot_prompt_dirtrim "$POLYGLOT_PROMPT_DIRTRIM")\E[0m\E[33m$(_polyglot_branch_status $POLYGLOT_KSH_BANG)\E[0m\E[0m # ')" 672 | else 673 | PS1="$(print '$(_polyglot_exit_status $?)$(_polyglot_venv)\E[7m${LOGNAME:-$(logname)}$POLYGLOT_HOSTNAME_STRING\E[0m $(_polyglot_prompt_dirtrim "$POLYGLOT_PROMPT_DIRTRIM")$(_polyglot_branch_status $POLYGLOT_KSH_BANG) # ')" 674 | fi 675 | fi 676 | ;; 677 | esac 678 | 679 | #################################################################### 680 | # pdksh, oksh, dash, busybox ash, yash, osh, 681 | # and zsh in sh emulation mode 682 | #################################################################### 683 | 684 | elif _polyglot_is_pdksh || [ "${0#-}" = 'dash' ] || _polyglot_is_busybox || 685 | _polyglot_is_yash || _polyglot_sh_is_dash || [ "${0#-}" = 'osh' ]; then 686 | 687 | # Only display the $HOSTNAME for an ssh connection 688 | if _polyglot_is_ssh || _polyglot_is_superuser; then 689 | POLYGLOT_HOSTNAME_STRING=$(hostname) 690 | POLYGLOT_HOSTNAME_STRING="@${POLYGLOT_HOSTNAME_STRING%%\.*}" 691 | else 692 | POLYGLOT_HOSTNAME_STRING='' 693 | fi 694 | 695 | # pdksh uses an arbitrary non-printing character to delimit color escape 696 | # sequences in the prompt. In practice, however, it is impossible to find 697 | # one single non-printing character that will work with all operating systems 698 | # and terminals. The Polyglot Prompt defaults to \021 for OpenBSD/NetBSD 699 | # and \016 for everything else. If you want to specify your own non-printing 700 | # character, do so thus: 701 | # 702 | # POLYGLOT_NP="\016" # Set this variable to whatever value you like 703 | # 704 | # Or set POLYGLOT_PDKSH_COLORS=0 to disable color entirely in pdksh. 705 | 706 | case ${POLYGLOT_UNAME} in 707 | NetBSD*|OpenBSD*) POLYGLOT_NP=${POLYGLOT_NP:-"\021"} ;; 708 | *) POLYGLOT_NP=${POLYGLOT_NP:-"\016"} ;; 709 | esac 710 | 711 | if _polyglot_is_pdksh && 712 | _polyglot_has_colors && 713 | [ ${POLYGLOT_PDKSH_COLORS:-1} -ne 0 ]; then 714 | 715 | PS1=$(print "$POLYGLOT_NP\r") 716 | case $POLYGLOT_UNAME in 717 | NetBSD*|OpenBSD*) PS1=$PS1$(print "$POLYGLOT_NP") ;; 718 | esac 719 | PS1=$PS1$(print "\033[31;1m$POLYGLOT_NP") 720 | PS1=$PS1'$(_polyglot_exit_status $?)' 721 | PS1=$PS1$(print "$POLYGLOT_NP\033[0m$POLYGLOT_NP") 722 | PS1=$PS1'$(_polyglot_venv)' 723 | if ! _polyglot_is_superuser; then 724 | PS1=$PS1$(print "$POLYGLOT_NP\033[32;1m$POLYGLOT_NP") 725 | else 726 | PS1=$PS1$(print "$POLYGLOT_NP\033[7m$POLYGLOT_NP") 727 | fi 728 | PS1=$PS1'${LOGNAME:-$(logname)}$POLYGLOT_HOSTNAME_STRING' 729 | PS1=$PS1$(print "$POLYGLOT_NP\033[0m$POLYGLOT_NP") 730 | PS1=$PS1' ' 731 | PS1=$PS1$(print "$POLYGLOT_NP\033[34;1m$POLYGLOT_NP") 732 | PS1=$PS1'$(_polyglot_prompt_dirtrim "$POLYGLOT_PROMPT_DIRTRIM")' 733 | PS1=$PS1$(print "$POLYGLOT_NP\033[0m\033[33m$POLYGLOT_NP") 734 | PS1=$PS1'$(_polyglot_branch_status $POLYGLOT_KSH_BANG)' 735 | PS1=$PS1$(print "$POLYGLOT_NP\033[0m$POLYGLOT_NP") 736 | PS1=$PS1' \$ ' 737 | 738 | elif _polyglot_is_yash || [ "${0#-}" = 'osh' ] && _polyglot_has_colors; then 739 | PS1='\[\e[01;31m\]$(_polyglot_exit_status $?)\[\e[0m\]' 740 | PS1=$PS1'$(_polyglot_venv)' 741 | if ! _polyglot_is_superuser; then 742 | PS1=$PS1'\[\e[01;32m\]${LOGNAME:-$(logname)}$POLYGLOT_HOSTNAME_STRING\[\e[0m\] ' 743 | else 744 | PS1=$PS1'\[\e[7m\]${LOGNAME:-$(logname)}$POLYGLOT_HOSTNAME_STRING\[\e[0m\] ' 745 | fi 746 | PS1=$PS1'\[\e[01;34m\]$(_polyglot_prompt_dirtrim "$POLYGLOT_PROMPT_DIRTRIM")\[\e[0m\]' 747 | PS1=$PS1'\[\e[33m\]$(_polyglot_branch_status $POLYGLOT_KSH_BANG)\[\e[0m\] \$ ' 748 | else 749 | PS1='$(_polyglot_exit_status $?)$(_polyglot_venv)${LOGNAME:-$(logname)}$POLYGLOT_HOSTNAME_STRING $(_polyglot_prompt_dirtrim "$POLYGLOT_PROMPT_DIRTRIM")$(_polyglot_branch_status $POLYGLOT_KSH_BANG) ' 750 | if ! _polyglot_is_superuser; then 751 | PS1=$PS1'$ ' 752 | else 753 | PS1=$PS1'# ' 754 | fi 755 | fi 756 | else 757 | printf '%s\n' 'Polyglot Prompt does not support your shell.' >&2 758 | fi 759 | 760 | # Clean up environment 761 | unset -f _polyglot_is_ssh _polyglot_basename _polyglot_is_busybox \ 762 | _polyglot_is_dtksh _polyglot_is_pdksh _polyglot_sh_is_dash 763 | 764 | # vim: ts=2:et:sts=2:sw=2 765 | --------------------------------------------------------------------------------