{"id":13473358,"url":"https://github.com/icyphox/nicy","last_synced_at":"2025-04-09T16:23:54.159Z","repository":{"id":47613202,"uuid":"157363852","full_name":"icyphox/nicy","owner":"icyphox","description":":snowflake: a nice and icy zsh and bash prompt in Nim","archived":false,"fork":false,"pushed_at":"2021-08-20T08:22:28.000Z","size":154,"stargazers_count":180,"open_issues_count":3,"forks_count":8,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-10-30T06:31:29.799Z","etag":null,"topics":["bash","nim","prompt","shell","zsh"],"latest_commit_sha":null,"homepage":"https://icyphox.github.io/nicy/","language":"Nim","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/icyphox.png","metadata":{"files":{"readme":"readme.md","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}},"created_at":"2018-11-13T10:42:01.000Z","updated_at":"2024-10-03T11:41:01.000Z","dependencies_parsed_at":"2022-08-02T18:15:15.960Z","dependency_job_id":null,"html_url":"https://github.com/icyphox/nicy","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icyphox%2Fnicy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icyphox%2Fnicy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icyphox%2Fnicy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icyphox%2Fnicy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/icyphox","download_url":"https://codeload.github.com/icyphox/nicy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245151530,"owners_count":20569280,"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","nim","prompt","shell","zsh"],"created_at":"2024-07-31T16:01:02.932Z","updated_at":"2025-03-23T18:35:02.347Z","avatar_url":"https://github.com/icyphox.png","language":"Nim","funding_links":[],"categories":["Nim"],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003e                                                              \n    \u003cimg src=\"https://x.icyphox.sh/5DyAD.png\" width=\"280\"\u003e                            \n\u003c/h1\u003e\n\n\u003e A nice and icy zsh and bash prompt in Nim\n\n[![Build Status](https://travis-ci.org/icyphox/nicy.svg?branch=master)](https://travis-ci.org/icyphox/nicy)\n\n![scrot](https://x.icyphox.sh/SltdI.png)\n\n### Why?\nI’ve always wanted to minimize my reliance on frameworks like [oh-my-zsh](https://github.com/robbyrussell/oh-my-zsh), so I figured, why not write my own ZSH prompt in my new favourite language? Turned out to be a really fun exercise.\n\n### Highlights\n- Written in Nim 👑\n- Fast (in theory, since Nim compiles to C)\n- Pretty defaults.\n- Plugin-like system for prompt customization, in case you didn’t like the pretty defaults.\n- Support both zsh and bash.\n- Fun, I guess.\n\n## Installation\n**Note**: It’s probably a good idea to uninstall `oh-my-zsh`, or any other plugin framework you’re using\naltogether. It may cause conflicts.\n\n```console\n$ nimble install nicy\n```\n\nDon’t know what that is? New to Nim? Check out the Nim [docs](https://nim-lang.org/documentation.html). `nimble` is packaged with Nim by default.  \n\n## Quick start\nAdd this to your `~/.zshrc`. If you installed via `nimble`, set `PROMPT` to `$(~/.nimble/bin/nicy)`.\n\n```zsh\nautoload -Uz add-zsh-hook\n_nicy_prompt() {\n\tPROMPT=$(\"/path/to/nicy\")\n}\nadd-zsh-hook precmd _nicy_prompt\n```\nMake sure you disable all other themes.\n\nNicy supports BASH also, and you could simply add it to your `~/.bashrc` or `~/.bash_profile`:\n```bash\nfunction nicy_prompt_command {\n    PS1=$(/path/to/nicy)\n}\nPROMPT_COMMAND=\"nicy_prompt_command\"\n```\n\n## Configuration\nIf you want to configure `nicy` as it is, you’ll have to edit the `src/nicy.nim` file and recompile. Messy, I know.\n\n### Build your own prompt\nAlternatively, you can just as easily write your own prompt in Nim using `nicy`’s built-in API. Refer to the [Examples](#Examples) section for some insight.\n\nOnce you’re done, compile it and add a similar function to your `.zshrc` as above, replacing `PROMPT` with the path to your own binary.\n\n### Examples\n\n```nim\n# ‘user@host $’ prompt\n\nimport nicy, strformat\n\nlet\n  user = color(user(), green)\n  host = color(host(), red)\n  prompt = color(\"$ \", cyan)\n  at = color(\"@\", yellow)\n\necho fmt\"{user}{at}{host} {prompt}\"\n```\n\n```nim\n# fish’s default prompt '~\u003e'\n\nimport nicy, strformat\n\nlet\n  prompt = color(\"\u003e \", green)\n  tilde = tilde(getCwd())\n\necho fmt\"{tilde}{prompt}\"\n```\n\n```nim\n# pure by @sindresorhus (kinda)\n\nimport nicy, strformat\n\nlet\n  prompt = color(\"❯ \", magenta)\n  tilde = color(tilde(getCwd()), cyan)\n  git = color(gitBranch() \u0026 gitStatus(\"*\", \"\"), red)\n  nl = \"\\n\"\n\necho fmt\"{tilde}{git}{nl}{prompt}\"\n```\n\n```nim\n# switching by return code\n\nimport nicy, strformat\n\nlet\n  prompt = returnCondition(ok = \"👍\", ng = \"👎\") \u0026 \" \"\n  tilde = color(tilde(getCwd()), cyan)\n  git = color(gitBranch() \u0026 gitStatus(\"*\", \"\"), red)\n  nl = \"\\n\"\n\necho fmt\"{tilde}{git}{nl}{prompt}\"\n# ~ master\n# 👍 \n```\n\nIf you like to know more details about git status, you may want to try the following powerful example which is including the number of untracked, modified, staged, conflicted and the number of commits your local branch is ahead, behind, etc:\n```\nnim c -d:release examples/power.nim\n```\n\n### API\n\n**`zeroWidth(s: string): string`**  \nReturns the given string wrapped in zsh zero-width codes. Useful for prompt alignment and cursor positioning.  \nAll procs below return strings wrapped by this.\n\n**`foreground(s: string, color: Color): string`**  \nReturns the given string, colorized.  \nPossible colors are `black`, `red`, `green`, `blue`, `cyan`, `yellow`, `magenta`, `white`.\n\n**`background(s, color: string): string`**  \nReturns the given string with its background colorized.  \nSame possible colors as above.\n\n**`bold(s: string): string`**  \nMakes the given string bold.\n\n**`underline(s: string): string`**  \nAdds an underline to the given string.\n\n**`italics(s: string): string`**  \nItalicizes the given text. **May not work in some terminal emulators!**\n\n**`reverse(s: string): string`**  \nSwaps the foreground/background colors for the given string.\n\n**`reset(s: string): string`**  \nResets all attributes. Useful for disabling all styling.\n\n**`color*(s: string, fg, bg = Color.none, b, u, r = false): string`**  \nConvenience proc that sets all attributes to a given string.  \n`fg`: foreground, `bg`: background, `b`: bold, `u`: underline, `r`: reverse\n\n**`horizontalRule(c: char): string`**  \nReturns a string of characters `c`, having the length of the current terminal width. Useful for positioning right-side prompts.\n\n**`tilde(path: string): string`**  \nIf `path` starts with `/home/user`, it is replaced by a `~/`.\n\n**`getCwd(): string`**  \nReturns the full path of the current working directory, or returns the string `[not found]` if current path doesn’t exist. (eg: `rm -rf ../curpath`)\n\n**`virtualenv(): string`**  \nReturns the current virtualenv name if in one.\n\n**`gitBranch(): string`**  \nReturns the current git branch, if in a git directory.\n\n**`gitStatus(dirty, clean: string): string`**  \nReturns either `dirty` or `clean` if in a git repository. For example, return `•` if clean and `×` if dirty.\n\n**`user(): string`**  \nReturns the current username.\n\n**`host(): string`**  \nReturns the current hostname.\n\n**`returnCondition*(ok: string, ng: string, delimiter = \".\"): string`**  \nIf the return code is `0` then returns `ok` string, otherwise `ng`.\n\n**`returnCondition*(ok: proc(): string, ng: proc(): string, delimiter = \".\"): string`**  \nReturns result of `ok` proc or `ng` proc.\nIf the return code is `0` then this proc calls `ok` proc, otherwise calls `ng` proc.\n\n**`shellName*: string`**\nContains the name of shell in which your prompt progoram is running.\nCurrently it may be `zsh` or `bash`. \nYou can specify it during compilation using the switch `-d:zsh` or `-d:bash`, or you can let the program detect it automatically, which may slow it down by a few milliseconds.\n\n#### GitStats API\n\n**`newGitStats*(): GitStats`**  \nReturns a `GitStats` object which contains the name of the local branch, the name of remote reference, number of commits your local branch is ahead or behind remote ref, number of untracked, modified, staged, conflicted, and the number of stashed changes. \n\n**`branch*(gs: GitStats, detachedPrefix = \"\", postfix = \" \"): string`**  \nReturns the current git branch name.\n\n**`status*(gs: GitStats, ahead, behind, untracked, changed, staged, conflicted, stash: string, separator, postfix = \" \"): string`**  \nReturns the git status string.\n\n**`dirty*(gs: GitStats): bool`**  \nReturns whether the current directory has been changed.\n\n## Contributing\nBad code? New feature in mind? Open an issue. Better still, learn [Nim](https://nim-lang.org/documentation.html) and shoot a PR :sparkles:\n\n## License\nMIT © [Anirudh Oppiliappan](https://icyphox.sh)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ficyphox%2Fnicy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ficyphox%2Fnicy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ficyphox%2Fnicy/lists"}