Git Product home page Git Product logo

polyglot's Introduction

Polyglot mascot

License GitHub tag GitHub Stars

Polyglot Prompt

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:

  • the username
  • whether a session is local or remote over SSH
  • an abbreviated path
  • the Git branch and status
  • the exit status of the last command, if it was not zero
  • any virtual environment created with virtualenv, venv, pipenv, poetry, or conda

Polyglot Prompt demo

Note: There is also support for color in pdksh, oksh, and osh.

Table of Contents

Basics

The central functions of the prompt are the same in all supported shells:

Polyglot working in several shells

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:

zsh line editing

See below for instructions on how to enable vi mode in your shell.

Installation

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:

. /path/to/polyglot.sh

Although no framework is required, a shim (polyglot.plugin.zsh) is provided to help with certain zsh frameworks.

Local and Remote Sessions

When a session is local, only the username is shown; when it is remote over SSH (or mosh), the hostname is also shown:

Local and remote sessions

Note: It is exceedingly difficult to determine with accuracy whether a superuser is connected over SSH or not. In the interests of providing useful and not misleading information, this prompt always displays both username and hostname for a superuser in reverse video.

Abbreviated Paths

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

/home/pi/src/neovim/config

is displayed as

~/.../neovim/config

whereas

/usr/src/sense-hat/examples

is displayed as

.../sense-hat/examples

that is, without a tilde.

If you would like to display a different number of directory elements in your Polyglot Prompt, set the environment variable $POLYGLOT_PROMPT_DIRTRIM in an rc file thus:

POLYGLOT_PROMPT_DIRTRIM=4     # Or whatever number you like

POLYGLOT_PROMPT_DIRTRIM examples

Setting POLYGLOT_PROMPT_DIRTRIM=0 disables path abbreviation, although $HOME will still be displayed as ~.

Git Branch and Status

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:

Git examples

Git Status Symbol
Diverged &*
Behind &
Ahead *
New file(s) +
Deleted x
Modified !
Renamed >
Untracked ?

POLYGLOT_SHOW_UNTRACKED

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 may 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.

Exit Status

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:

Exit status displayed in zsh, bash, and ksh

Virtual Environments

The Polyglot Prompt will display any active virtual environment created with virtualenv, venv, pipenv, poetry, or conda at the beginning of the prompt:

Virtual environments

Kubernetes Integration

If you are using the Polyglot Prompt with bash or zsh, you may add the Kubernetes context and namespace to your prompt with the add-on package polyglot-kube-ps1.

Colors in pdksh

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:

POLYGLOT_NP="\016"  # Set this variable to any value you like

If all else fails, you can set POLYGLOT_PDKSH_COLORS=0 to disable color entirely in pdksh.

Enabling vi editing mode in zsh and bash

The Polyglot Prompt does not enable vi editing mode for you. In zsh, you may add

bindkey -v

to your .zshrc; for bash, either put

set-editing-mode vi

in your .inputrc or

set -o vi

in your .bashrc.

polyglot's People

Contributors

agkozak avatar awkless avatar edklem avatar phoenix4815 avatar scuzzilla avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

polyglot's Issues

Escape codes not interpreted properly in /bin/ksh on macOS Big Sur

I'm running polyglot using ksh on macOS Big Sur v11.6.

When running it on CentOS or RHEL, the longer commands slide, so they stay on one line.

However, whether I use polyglot within wezterm or the default Terminal app, scrolling back to a long line or typing in a long line will result in the cursor jumping around. The simplest example I've been able to reproduce is executing a git command that exceeds the line length, then opening a new shell and pressing up arrow twice with the intention of re-running (or modifying) the long git command.

The result of that sequence of actions in an 80x24 Terminal is shown in the image below:

Screen Shot 2021-09-29 at 08 43 34

I also experience strange behavior when moving left and right on long commands, but I believe those are related to this issue, so will wait until we figure out how to solve this and see if the others go away.

Theme and font?

I was wondering what are the fonts and them used in the screenshots? They look v nice :)

[bug] Prompt takes long time on very large git repos

When working with very large repositories, specifically https://github.com/openbsd/ports, the prompt takes really long to show up.

This is not inherently an issue with polyglot as any git operation on that repository takes >3 seconds (even with a 24core, 32GB server).

Can polyglot make it so that it can kill the process by limiting the time spent to something like 0.1 seconds?

This is really making it impossible to use it right now ๐Ÿ˜ฟ

Relicensing as MIT

I would like to relicense the next version of the Polyglot Prompt as MIT for better compatibility with other software projects. @Phoenix4815, are you willing to license your contributions as MIT?

feature (python venv)

it would be nice to have the possibility to show if the python virtual environment is active

Simpler version

Hey, polyglot is a great idea! Could it move to a more opt-in model for the prompt elements? Like, I'd love to source polyglot and then build my own prompt with reusable functions.

In zsh when I switch to command mode the status does not reset if I hit enter or ctrl-c while still in command mode.

While in vi mode on zsh the ":" does not reset to "+" at start of the new prompt if you hit enter while still in vi cmd mode.
For example if you hit ESC and then "k" to go back through command history and just press enter to execute the command the new prompt will show a ":" even though we are back in insert mode.

I have a one line fix that would go in the zsh section. I can send a PR if you like.
Thanks.

Login fails (loop)

Hello,

I wanted to test your script and installed it as suggested by inserting the respective line in the bashrc file, but this causes a login failure (opensuse tumbleweed, kde plasma, sddm). More specifically, at the login screen I enter my username and password (which both are correct), it seems to load the kde desktop but then jumps back to the login screen. Removing the script from the bashrc allows to login correctly again.

Do you have any ideas how to make your script your in such cases, because I really like its style!

dash login shell invocation issue

On Debian, dash version 0.5.10.2-5
On macOS, brewed dash version 0.5.10.2

$ . ./polyglot.sh
-dash: 363: command: Illegal option -d
ls: : No such file or directory
Polyglot Prompt does not support your shell.

Just to make sure, dash(1)'s command in the Builtins subsection indeed does not list option -d.

polyglot/polyglot.sh

Lines 362 to 363 in 3c93f3a

_polyglot_sh_is_dash() {
case $(ls -l "$(command -v "$0")") in

$ echo $0
-dash

Dash is invoked as a login shell in my use case. -d of -dash is evaluated by command, causing the error.

$ echo ${0#-} # "Remove Smallest Prefix Pattern" as described in dash(1)
dash

Substituting "$0" with "${0#-}" fixes the issue but you may want to implement the fix in a different (or better) way and so I didn't submit a pull request.

Colors for pdksh removed

Hello agkozak,

with 550fc20 colors for pdksh were removed.

I do not challenge this decision. Care to explain why colors were are unreliable in pdksh though? I would like to have a look into it but I do not know what the actual issue was. And I want to reintroduce some colors into the drab OpenBSD world :)

Thanks!
edit: typo
edit: thanks for polyglot btw

Featre: Set title

Is there a way to have a feature flag to maybe move some of this into the title or even just duplicate some of the data into the title.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.