{"id":16542404,"url":"https://github.com/ms140569/prompter","last_synced_at":"2025-03-04T06:11:52.599Z","repository":{"id":83736352,"uuid":"183754836","full_name":"ms140569/prompter","owner":"ms140569","description":"Reimplementation of prompt generator powerline-shell in Rust","archived":false,"fork":false,"pushed_at":"2019-04-29T19:39:35.000Z","size":48,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-14T10:18:40.383Z","etag":null,"topics":["bash","developer-tools","rust","shell"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ms140569.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-04-27T09:42:43.000Z","updated_at":"2022-10-01T18:26:57.000Z","dependencies_parsed_at":null,"dependency_job_id":"7364f366-0ae7-4a34-9354-5fe5ebf159c4","html_url":"https://github.com/ms140569/prompter","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ms140569%2Fprompter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ms140569%2Fprompter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ms140569%2Fprompter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ms140569%2Fprompter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ms140569","download_url":"https://codeload.github.com/ms140569/prompter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241794138,"owners_count":20021192,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bash","developer-tools","rust","shell"],"created_at":"2024-10-11T18:57:25.800Z","updated_at":"2025-03-04T06:11:52.593Z","avatar_url":"https://github.com/ms140569.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Prompter - a prompt generator for Bash\n\nThis is a reimplementation of the great prompt generator [powerline-shell](https://github.com/b-ryan/powerline-shell) in the Rust programming language.\n\nThis is how it looks like:\n\n![screenshot](doc/screenshot.png)\n\nIt uses the **very same** configuration files as powerline-shell and implements many of the segment modules. Some are missing and I am happy to get pull requests. \n\nAs of now it's limited to the Bash shell (since that's what I am using), but Pull-Requests for other shells are welcome.\n\n- Shows some important details about the git branch (see below)\n- Changes color if the last command exited with a failure code\n- If you're too deep into a directory tree, shortens the displayed path with an ellipsis\n- Very easy to customize and extend.\n- Runs orders of magnitude faster than it's predecessor.\n\n\u003c!-- START doctoc generated TOC please keep comment here to allow auto update --\u003e\n\u003c!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --\u003e\n**Table of Contents**  *generated with [DocToc](https://github.com/thlorenz/doctoc)*\n\n- [Installation](#installation)\n  - [Linux/Debian package](#linuxdebian-package)\n  - [Mac OS X, brew installation](#mac-os-x-brew-installation)\n  - [Install from the git repository:](#install-from-the-git-repository)\n- [Git Version Control](#git-version-control)\n- [Setup](#setup)\n  - [Bash](#bash)\n- [Customization](#customization)\n  - [Config File](#config-file)\n  - [Adding, Removing and Re-arranging segments](#adding-removing-and-re-arranging-segments)\n  - [Generic Segments](#generic-segments)\n  - [Segment Separator](#segment-separator)\n  - [Themes](#themes)\n  - [Segment Configuration](#segment-configuration)\n- [Troubleshooting](#troubleshooting)\n\n\u003c!-- END doctoc generated TOC please keep comment here to allow auto update --\u003e\n\n## Installation\n\n### Linux/Debian package\n\nTODO\n\n### Mac OS X, brew installation\n\nTODO\n\n### Install from the git repository:\n\n```\ngit clone https://github.com/ms140569/prompter\ncd prompter\nmake release\ncp target/release/prompter \u003csomewhere on your $PATH\u003e\n```\n\n## Git Version Control\n\nThe git module gives you the following features:\n\n- The current branch is displayed and changes background color when the\n  branch is dirty.\n- When the local branch differs from the remote, the difference in number\n  of commits is shown along with `⇡` or `⇣` indicating whether a git push\n  or pull is pending.\n\nIf files are modified or in conflict, the situation is summarized with the\nfollowing symbols:\n\n- `✎` -- a file has been modified (but not staged for commit, in git)\n- `✔` -- a file is staged for commit (git) or added for tracking\n- `✼` -- a file has conflicts\n- `?` -- a file is untracked\n\nEach of these will have a number next to it if more than one file matches.\n\nThe segment can start with a symbol representing the version control system in\nuse. To show that symbol, the configuration file must have a variable `vcs`\nwith an option `show_symbol` set to `true` (see\n[Segment Configuration](#segment-configuration)).\n\n## Setup\n\nThis script uses ANSI color codes to display colors in a terminal. These are\nnotoriously non-portable, so may not work for you out of the box, but try\nsetting your $TERM to `xterm-256color`.\n\n- Patch the font you use for your terminal: see\n  [powerline-fonts](https://github.com/Lokaltog/powerline-fonts)\n  - If you struggle too much to get working fonts in your terminal, you can use\n    \"compatible\" mode.\n\n- Setup your shell prompt using the instructions for your shell below.\n\n### Bash\n\nAdd the following to your `.bashrc` file:\n\n```\nfunction _update_ps1() { PS1=$(prompter $?); }\n\nif [[ $TERM != linux \u0026\u0026 ! $PROMPT_COMMAND =~ _update_ps1 ]]; then\n    PROMPT_COMMAND=\"_update_ps1; $PROMPT_COMMAND\"\nfi\n```\n\n**Note:** On macOS, you must add this to one of `.bash_profile`, `.bash_login`,\nor `.profile`. macOS will execute the files in the aforementioned order and\nwill stop execution at the first file it finds. For more information on the\norder of precedence, see the section **INVOCATION** in `man bash`.\n\n## Customization\n\n### Config File\n\nPrompter could be customized with a JSON file configuring the order and setup \nof the path segments. The configfile lookup-order and their names are:\n\n1. $PWD/prompter.json\n2. $HOME/.prompter.json\n3. XDG_CONFIG_HOME/prompter/config.json\n4. $HOME/.config/prompter/config.json\n\nI this fails, the following default configuration will be used:\n\n```\n{                                                                                              \n       \"segments\": [                              \n           \"username\",                                                                                                                                                                           \n           \"hostname\",                                                                            \n           \"exit_code\",                                                                                                                                                                          \n           \"cwd\",                                                                                                                                                                                \n           \"git\",                              \n           \"jobs\",                                                                                                                                                                               \n           \"root\"                                 \n       ]                                                                                          \n   } \n```\n\nYou can dump-out this configuration into a file and use it as a template for further modifications: \n\n```\nprompter --generate-config \u003e ~/.prompter.json\n```\n\nYou can find some example configurations in the sources.\n\n### Adding, Removing and Re-arranging segments\n\nOnce you have generated your config file, you can now start adding or removing\n\"segments\" - the building blocks of your shell. The list of segments available\ncan be seen\n[here](src/segments).\n\nYou can also create custom segments. Start by copying an existing, simple segment like\n[hostname](src/segments/hostname.rs).\n\nTODO: description how to hook-up new segment.\n\n\n### Generic Segments\n\nThere are two special segments available. `stdout` accepts an arbitrary command\nand the output of the command will be put into your prompt. `env` takes an\nenvironment variable and the value of the variable will be set in your prompt.\nFor example, your config could look like this:\n\n```\n{\n  \"segments\": [\n    \"cwd\",\n    \"git\",\n    {\n      \"type\": \"stdout\",\n      \"command\": [\"echo\", \"hi\"],\n      \"fg_color\": 22,\n      \"bg_color\": 161\n    },\n    {\n      \"type\": \"env\",\n      \"var\": \"DOCKER_MACHINE_NAME\",\n    },\n  ]\n}\n```\n\n### Segment Separator\n\nBy default, a unicode character (resembling the \u003e symbol) is used to separate\neach segment. This can be changed by changing the \"mode\" option in the config\nfile. The available modes are:\n\n- `patched` - The default.\n- `compatible` - Attempts to use characters that may already be available using\n  your chosen font.\n- `flat` - No separator is used between segments, giving each segment a\n  rectangular appearance (and also saves space).\n\n### Themes\n\nThe `src/themes` directory stores themes for your prompt, which are\nbasically color values used by segments. The `default.rs` defines a default\ntheme.\n\nTODO: Description how to hook-up another theme.\n\n\nYou can then modify the color codes to your liking. Theme colors are specified\nusing [Xterm-256 color codes](https://jonasjacek.github.io/colors/).\n\nA script for testing color combinations is provided at `colortest.py`: \n\n```\n./colortest.py 150 154  344  366 STRING\n```\n\nNote that the colors you see may vary depending on your terminal. When designing a\ntheme, please test your theme on multiple terminals, especially with default\nsettings.\n\n### Segment Configuration\n\nSome segments support additional configuration. The options for the segment are\nnested under the name of the segment itself. For example, all of the options\nfor the `cwd` segment are set in `~/.prompter.json` like:\n\n```\n{\n    \"segments\": [...],\n    \"cwd\": {\n        options go here\n    }\n    \"theme\": \"theme-name\",\n    \"vcs\": {\n        options go here\n    }\n}\n```\n\nThe options for the `cwd` segment are:\n\n- `mode`: If `plain`, then simple text will be used to show the cwd. If\n  `dironly`, only the current directory will be shown. Otherwise expands the\n  cwd into individual directories.\n- `max_depth`: Maximum number of directories to show in path.\n- `max_dir_size`: Maximum number of characters displayed for each directory in\n  the path.\n- `full_cwd`: If true, the last directory will not be shortened when\n  `max_dir_size` is used.\n\n## Troubleshooting\n\nRun the debug build of prompter:\n\n```\nmake test \u0026\u0026 make build\n```\n\nAnd run it like this:\n\n```\nRUST_LOG=debug RUST_BACKTRACE=1 target/debug/prompter 0\n```\n\nIf you are facing issues, file them [HERE](https://github.com/ms140569/prompter/issues/new).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fms140569%2Fprompter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fms140569%2Fprompter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fms140569%2Fprompter/lists"}