GitXplorerGitXplorer
s

eliprompt

public
1 stars
0 forks
0 issues

Commits

List of commits on branch master.
Unverified
427103366f57c43f8101315d5c2bbd8dc1ca9f75

Bump version

sstephaneyfx committed a year ago
Unverified
092fefd54bb2ad79de57e2e118d326fc8cce284a

Update dependencies

sstephaneyfx committed a year ago
Unverified
02be93ffc3a19ee3760c2469ad199f3f7931ebe5

Support no working directory

sstephaneyfx committed a year ago
Unverified
ea818686c2498063df356587efd3771124a728d8

Derive Default for enum

sstephaneyfx committed a year ago
Unverified
129dd90e231813cb4bff7e51332912fccf6f057c

Change license to MIT

sstephaneyfx committed a year ago
Unverified
23492c82927f2b4e914e0cdde3a0c5a7ec818313

Update Cargo.lock

sstephaneyfx committed 2 years ago

README

The README file for this repository.

Overview

CLI to generate a shell prompt.

Font

The default prompt configuration uses symbols from Nerd Fonts and expects one of them to be installed.

Shell support

Only zsh is supported. Please open an issue if support for another shell is desired.

Installation

cargo install eliprompt

Make sure eliprompt is in your PATH and add the following to .zshrc:

eval "$(eliprompt install --shell zsh)"

Configuration

The prompt is made of blocks. Each block contains the text to display as well as the style (foreground and background colors).

The configuration is stored in ~/.config/eliprompt/config.json. It consists of a JSON object of type Config. Config and the other JSON types involved are detailed below.

BlockProducer type

JSON object with a single field named after its type among:

Color type

String with a CSS color name (e.g. "red") or a CSS sRGB color (e.g. "#ff1000").

Config type

Root configuration object. JSON object with the following fields:

  • prompt [optional]:
  • alternative_prompt [optional]:
    • Type: BlockProducer or null
    • Alternative prompt definition to use when $TERM is linux or the environment variable ELIPROMPT_ALTERNATIVE_PROMPT is defined.
  • timeout [optional]:
    • Type: Duration
    • Maximum time allocated to build the prompt. If it takes longer, a default prompt will be shown.

Duration type

String containing a duration with unit, e.g. "3s" for 3 seconds.

Elapsed type

Shows the duration of the previous command. JSON object with the following fields:

  • style [optional]:
  • prefix [optional]:
    • Type: String
    • Text to display before the duration.
  • threshold [optional]:
    • Type: Duration
    • The duration of a command is displayed if and only if it took longer than the threshold.

ExitCode type

Shows the exit code of the previous command if it was not zero. JSON object with the following fields:

  • style [optional]:
  • prefix [optional]:
    • Type: String
    • Text to display before the exit code.

ExitStatusSymbol type

  • style [optional]:
    • Type: Style
    • Style to use when the exit status is zero.
  • error_style [optional]:
    • Type: Style
    • Style to use when the exit status is not zero.
  • contents:
    • Type: String

GitHead type

Shows the current git branch. JSON object with the following fields:

  • style [optional]:
  • prefix [optional]:
    • Type: String
    • Text to display before the git branch.

GitPath type

If the current working directory is in a git repository, it is shown relative to the root of the repository. JSON object with the following fields:

  • style [optional]:
  • prefix [optional]:
    • Type: String
    • Text to display before the path.

Hostname type

  • style [optional]:
  • prefix [optional]:
    • Type: String
    • Text to display before the hostname.

Newline type

Adds a newline character.

Or type

List of BlockProducer items. Returns blocks from the first producer that produces at least one block.

Separated type

  • separator_style [optional]:
    • Type: Style
    • Style to use for the separator.
  • separator [optional]:
    • Type: String
    • Separator to insert between groups of blocks generated by the producers.
  • producers:

Sequence type

List of BlockProducer items. Returns blocks from all producers.

Space type

Adds a space character.

Style type

JSON object with the following fields:

  • foreground [optional]:
  • background [optional]:

Styled type

  • style [optional]:
    • Type: Style
    • Default style for items that do not specify their foreground or background color.
  • producer:
    • Type: BlockProducer
    • Generator whose blocks the default style is applied to.

Text type

  • style [optional]:
  • contents:
    • Type: String

Username type

  • style [optional]:
  • prefix [optional]:
    • Type: String
    • Text to display before the username.

WorkingDirectory type

Shows the current working directory. JSON object with the following fields:

  • style [optional]:
  • home_as_tilde [optional]:
    • Type: bool
    • Indicates if the home directory should be displayed as a tilde.
  • prefix [optional]:
    • Type: String
    • Text to display before the working directory.

Example

{
  "prompt": {
    "Styled": {
      "style": {
        "foreground": "teal",
        "background": "black"
      },
      "producer": {
        "Sequence": [
          {
            "Separated": {
              "separator_style": {},
              "separator": " | ",
              "producers": [
                {
                  "Separated": {
                    "separator_style": {},
                    "separator": "@",
                    "producers": [
                      {
                        "Username": {
                          "style": {},
                          "prefix": ""
                        }
                      },
                      {
                        "Hostname": {
                          "style": {},
                          "prefix": ""
                        }
                      }
                    ]
                  }
                },
                {
                  "Or": [
                    {
                      "GitPath": {
                        "style": {},
                        "prefix": ""
                      }
                    },
                    {
                      "WorkingDirectory": {
                        "style": {},
                        "home_as_tilde": true,
                        "prefix": ""
                      }
                    }
                  ]
                },
                {
                  "GitHead": {
                    "style": {},
                    "prefix": ""
                  }
                },
                {
                  "Elapsed": {
                    "style": {},
                    "prefix": "",
                    "threshold": "2s"
                  }
                },
                {
                  "ExitCode": {
                    "style": {
                      "foreground": "crimson"
                    },
                    "prefix": ""
                  }
                }
              ]
            }
          },
          {
            "Newline": null
          },
          {
            "ExitStatusSymbol": {
              "style": {
                "foreground": "dodgerblue"
              },
              "error_style": {
                "foreground": "crimson"
              },
              "contents": ""
            }
          },
          {
            "Space": null
          }
        ]
      }
    }
  },
  "alternative_prompt": {
    "Styled": {
      "style": {
        "foreground": "teal"
      },
      "producer": {
        "Sequence": [
          {
            "Separated": {
              "separator_style": {},
              "separator": " | ",
              "producers": [
                {
                  "Separated": {
                    "separator_style": {},
                    "separator": "@",
                    "producers": [
                      {
                        "Username": {
                          "style": {},
                          "prefix": ""
                        }
                      },
                      {
                        "Hostname": {
                          "style": {},
                          "prefix": ""
                        }
                      }
                    ]
                  }
                },
                {
                  "WorkingDirectory": {
                    "style": {},
                    "home_as_tilde": true,
                    "prefix": ""
                  }
                },
                {
                  "Elapsed": {
                    "style": {},
                    "prefix": "",
                    "threshold": "2s"
                  }
                },
                {
                  "ExitCode": {
                    "style": {
                      "foreground": "crimson"
                    },
                    "prefix": ""
                  }
                }
              ]
            }
          },
          {
            "Newline": null
          },
          {
            "ExitStatusSymbol": {
              "style": {
                "foreground": "dodgerblue"
              },
              "error_style": {
                "foreground": "crimson"
              },
              "contents": ""
            }
          },
          {
            "Space": null
          }
        ]
      }
    }
  },
  "timeout": "1s"
}

Contribute

All contributions shall be licensed under the MIT license.

Related projects

starship provides more blocks and supports more shells.