{"id":20686936,"url":"https://github.com/fimblo/generate-prompt","last_synced_at":"2026-04-18T19:32:08.874Z","repository":{"id":189240399,"uuid":"679780459","full_name":"fimblo/generate-prompt","owner":"fimblo","description":"Simple prompt generator for bash","archived":false,"fork":false,"pushed_at":"2025-08-04T10:35:08.000Z","size":390,"stargazers_count":0,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-25T08:35:43.638Z","etag":null,"topics":["bash","cli","prompt"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fimblo.png","metadata":{"files":{"readme":"README.org","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2023-08-17T15:47:09.000Z","updated_at":"2025-08-04T10:35:11.000Z","dependencies_parsed_at":"2023-10-01T16:21:09.959Z","dependency_job_id":"e6a98bc0-5e11-43fb-a88d-63ed0502ba20","html_url":"https://github.com/fimblo/generate-prompt","commit_stats":null,"previous_names":["fimblo/git-prompt","fimblo/generate-prompt"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/fimblo/generate-prompt","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fimblo%2Fgenerate-prompt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fimblo%2Fgenerate-prompt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fimblo%2Fgenerate-prompt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fimblo%2Fgenerate-prompt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fimblo","download_url":"https://codeload.github.com/fimblo/generate-prompt/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fimblo%2Fgenerate-prompt/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31982562,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-18T17:30:12.329Z","status":"ssl_error","status_checked_at":"2026-04-18T17:29:59.069Z","response_time":103,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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","cli","prompt"],"created_at":"2024-11-16T22:37:24.549Z","updated_at":"2026-04-18T19:32:08.849Z","avatar_url":"https://github.com/fimblo.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n#+begin_comment\nTODO\n- add GP_CONFLICT_STYLE style doc\n- make better video\n- maybe rename most of the styles to formats?\n#+end_comment\n\n\n\n* generate-prompt\n[[https://github.com/fimblo/generate-prompt/actions/workflows/c.yml/badge.svg]]\n\nSimple and fast prompt for bash which can show git repo status.\n\nNote: This is my first attempt at writing a prompt generator. For a\nmore feature-complete and less spaghetti solution, check the [[https://github.com/fimblo/prompt2][prompt2]]\nproject.\n\n\n\n** What does generate-prompt do?\n- It prints a useful prompt, for easy plugging into PS1.\n- It can tell if you're standing in a git repo or if you're outside of\n  one. Depending on the situation, it will use one of the two main\n  prompt types.\n\n[[file:recording.gif]]\n\n** I wrote this because\n- I'm a bash user, and\n- bash functions to update the prompt when standing in a git repo is\n  just too slow\n\n** Usage (basic)\nSource the contents of =profile= into your bash shell. There's a lot\nof stuff in there, mostly commented, but the core of it is:\n\n#+begin_src bash\n  prompt_cmd() {\n    PS1=\"$(/path/to/generate-prompt)\"\n  }\n  PROMPT_COMMAND=prompt_cmd\n#+end_src\n\n** Usage (More fun)\nGenerate-prompt was designed to be configured. The defaults should\nwork well enough, but if you want to modify the look of the prompt,\nread on.\n\n*** Instructions\n\n#+begin_src bash\nexport GP_GIT_PROMPT=\"[\\pR][\\pL][\\pC]\\n$ \"\n#+end_src\n\nThe strings in the example above which begin with =\\p= are\nthree-character Instructions which generate-prompt looks for. These,\nif found, are replaced with other content.\n\nFor example, =\\pC= is replaced with the name of the current working\ndirectory you're standing in.\n\nCurrently supported Instructions:\n- =\\pR= replaced with the git repo name*\n- =\\pL= replaced with the local branch name*\n- =\\pC= replaced with the current working directory(cwd)*\n- =\\pa= replaced with number of commits local is ahead of upstream              \n- =\\pb= replaced with number of commits local is behind of upstream\n- =\\pd= replaced with combination of =\\pa= and =\\pb=. \"=(a:-b)=\"\n- =\\pK= replaced with warning about conflicts in git repo, if there are any*\n- =\\pi= replaced with \"(interactive rebase)\" if in that state.\n- =\\pP= replaced with prompt symbol # or $ depending on user*\n\n\\* =\\pr=, =\\pl=, =\\pc=, =\\pk=, =\\pp= for uncoloured versions of the above\n\n\nNote that upper-case Instructions are decorated with Pre- and postfix\npatterns (see below)\n\n*** Instruction Styles\nInstructions can be further configured using Styles. \n\n**** Current working directory (=\\pC=) Styles\nThe part of the prompt which shows the current working directory, is\ngoverned by the =\\pC= Instruction. To change its style, you\ncan set the environment variable =GP_WD_STYLE= to one of styles\nbelow.\n\n- If unset or set to =basename=, =\\pC= will output the basename of CWD.\n- If set to =cwd=, output the full path from the user's =$HOME=.\n- If set to =gitrelpath_inclusive=, output the full path from\n  git-root, including the project name\n- If set to =gitrelpath_exclusive=, output the full path from\n  git-root, excluding the project name. This is nice in that it\n  doesn't repeat the name of the project when standing at the root of\n  the repo, but then there is no text to colour when the repo is not\n  in up-to-date state. To address this, there's an environment\n  variable you can use to set what is written at the root of the repo:\n  =GP_WD_STYLE_GITRELPATH_EXCLUSIVE=.\n\n  For example:\n  #+begin_src bash\n    export GP_WD_STYLE=gitrelpath_exclusive\n    export GP_WD_STYLE_GITRELPATH_EXCLUSIVE='☃️'\n  #+end_src\n\n  This would make =\\pC= expand to the complete path from the root of\n  the git repo to the directory you're standing in, and replace the\n  name of the repo with ☃️.\n  \n**** Interactive rebase (=\\pi=) Style\nYou can override the default string used to indicate an ongoing\ninteractive rebase by setting the =GP_REBASE_STYLE= environment\nvariable.\n\nFor example:\n#+begin_src bash\n  export GP_REBASE_STYLE=\"(interactive rebase)\"\n#+end_src\n\nThis would make the prompt show the string \"(interactive rebase)\" when\nthe repo you're standing in is in the interactive rebase state.\n\n**** Upstream divergence (=\\pa=, =\\pb=, and =\\pd=) Styles\nGenerate-prompt can tell when the local repo has diverged from the\nupstream ref. What is shown in the prompt in these situations is\ngoverned by the three Instructions =\\pa= (ahead), =\\pb= (behind), and\n=\\pd= (both ahead and behind of upstream ref). To change what these\nlook like, set one or all of the following environment variables:\n\n- =GP_A_DIVERGENCE_STYLE=\n- =GP_B_DIVERGENCE_STYLE=\n- =GP_AB_DIVERGENCE_STYLE=\n\nThese are used directly as printf formats, so you'll need to set =%d=\nin them to specify where the diffs should be displayed.\n\nFor example, if we're behind by 1 and ahead by 2, and you set these like so:\n#+begin_src bash\n  export GP_A_DIVERGENCE_STYLE=\"(%d)\"\n  export GP_B_DIVERGENCE_STYLE=\"(-%d)\"\n  export GP_AB_DIVERGENCE_STYLE=\"(%d,-%d)\"\n#+end_src\n\nThen =\\pa= will expand to \"(1)\", =\\pb= will expand to \"(-2)\", and\n=\\pd= will expand to \"(1,-2)\".\n\n*** Patterns\nThese are environment variables which override some particular part of\nthe default look of generate-prompt.\n\nGenerate-prompt will look for Instructions (see above) inside\nof these patterns, and replace them with specific strings which depend\non the current context.\n\n**** The default prompt pattern\n=GP_DEFAULT_PROMPT= is a pattern which overrides the hard-coded prompt\nyou see when not in a git repo. It is passed as-is to stdout, so your\nnormal PS1 prompt can be set here.\n\nExample:\n#+begin_src bash\nexport GP_DEFAULT_PROMPT=\"\\[\\033[01;32m\\]\\u@\\h\\[\\033[00m\\] \\[\\033[01;34m\\]\\W\\[\\033[00m\\] $ \"\n#+end_src\n\n**** The git prompt pattern\n=GP_GIT_PROMPT= pattern overrides the hard-coded git prompt you see\nwhen in a git repo. After some string replacements are done, it is\npassed to stdout like it does with the default prompt.\n\nExample:\n#+begin_src bash\nexport GP_GIT_PROMPT=\"[\\pR][\\pL][\\pC]\\n$ \"\n#+end_src\n\nYou may have noticed that there are three peculiar substrings in the\nexample above, which start with a =\\p=, followed by a character. These\nare the [[#instructions][Instructions]] mentioned above.\n\n\n**** Pre- and postfix patterns\nSome Instructions will decorate the output with colours,\ndepending on context.\n\nFor example, if you are standing in a git repo and change a tracked\nfile, then the current working directory Instruction (=\\pC=) will\nchange the colour of its output to indicate a status change. Once the\nchange is staged, it will once again revert to its original colour.\n\nPrefix patterns:\n#+begin_src bash\n export GP_UP_TO_DATE=\"\\033[0;32m\"\n export GP_MODIFIED=\"\\033[0;33m\"\n export GP_CONFLICT=\"\\033[0;31m\"\n export GP_NO_DATA=\"\\033[0;37m\"\n#+end_src\n\nPostfix patterns:\n#+begin_src bash\n export GP_RESET=\"\\033[0m\"\n#+end_src\n\nThough these are all currently used for colours, one can use these for\narbitrary text.\n\n**** Other patterns\n- =GP_WD_STYLE_GITRELPATH_EXCLUSIVE= ([[#current-working-directory-pc-styles][sic]])\n\n\n** Dependencies\n- [[https://github.com/libgit2/libgit2][libgit2]]\n- [[https://github.com/bats-core/bats-core][bats-core]]\n\n** Install\n\n- Install dependencies:\n  - With homebrew: =brew install libgit2 bats-core=\n  - With apt: =sudo apt install libgit2-dev bats=\n- Run =make= to build generate-prompt. (tested on mac and ubuntu)\n- =make local-install= installs at ~/bin\n- =sudo make install= installs at /usr/local/bin\n- =make clean= cleans things up.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffimblo%2Fgenerate-prompt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffimblo%2Fgenerate-prompt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffimblo%2Fgenerate-prompt/lists"}