├── screenshot.png ├── arch └── PKGBUILD ├── package.json ├── purity.zsh └── readme.md /screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/therealklanni/purity/HEAD/screenshot.png -------------------------------------------------------------------------------- /arch/PKGBUILD: -------------------------------------------------------------------------------- 1 | # Author: Sindre Sorhus 2 | # Maintainer: Pat Brisbin 3 | # Contributor: Emil Falk 4 | pkgname=zsh-pure-prompt-git 5 | pkgver=r61.7d3b317 6 | pkgrel=1 7 | pkgdesc='A minimal and pure prompt for zsh.' 8 | arch=('any') 9 | url='https://github.com/sindresorhus/pure' 10 | license=('MIT') 11 | depends=('zsh' 'git') 12 | source=("$pkgname::git://github.com/sindresorhus/pure.git") 13 | sha256sums=('SKIP') 14 | 15 | pkgver() { 16 | cd $srcdir/$pkgname 17 | printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)" 18 | } 19 | 20 | package() { 21 | cd $srcdir/$pkgname 22 | install -Dm644 pure.zsh \ 23 | "$pkgdir/usr/share/zsh/functions/Prompts/prompt_pure_setup" 24 | } 25 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "purity-prompt", 3 | "version": "0.2.3", 4 | "description": "Pretty, minimal and fast ZSH prompt", 5 | "license": "MIT", 6 | "repository": "therealklanni/purity", 7 | "author": { 8 | "name": "Kevin Lanni", 9 | "email": "therealklanni@gmail.com", 10 | "url": "https://github.com/therealklanni" 11 | }, 12 | "engines": { 13 | "node": ">=0.10.0" 14 | }, 15 | "scripts": { 16 | "postinstall": "dest=/usr/local/share/zsh/site-functions/; mkdir -p $dest && ln -sf \"$PWD/purity.zsh\" $dest/prompt_purity_setup || echo 'Could not automagically symlink the prompt. Check out the readme on how to do it manually: https://github.com/sindresorhus/purity#manually'" 17 | }, 18 | "files": [ 19 | "purity.zsh" 20 | ], 21 | "keywords": [ 22 | "zsh", 23 | "oh-my-zsh", 24 | "sh", 25 | "shell", 26 | "bash", 27 | "purity", 28 | "prompt", 29 | "theme" 30 | ] 31 | } 32 | -------------------------------------------------------------------------------- /purity.zsh: -------------------------------------------------------------------------------- 1 | # Purity 2 | # by Kevin Lanni 3 | # https://github.com/therealklanni/purity 4 | # MIT License 5 | 6 | # For my own and others sanity 7 | # git: 8 | # %b => current branch 9 | # %a => current action (rebase/merge) 10 | # prompt: 11 | # %F => color dict 12 | # %f => reset color 13 | # %~ => current path 14 | # %* => time 15 | # %n => username 16 | # %m => shortname host 17 | # %(?..) => prompt conditional - %(condition.true.false) 18 | 19 | 20 | # turns seconds into human readable time 21 | # 165392 => 1d 21h 56m 32s 22 | prompt_purity_human_time() { 23 | local tmp=$1 24 | local days=$(( tmp / 60 / 60 / 24 )) 25 | local hours=$(( tmp / 60 / 60 % 24 )) 26 | local minutes=$(( tmp / 60 % 60 )) 27 | local seconds=$(( tmp % 60 )) 28 | echo -n "⌚︎ " 29 | (( $days > 0 )) && echo -n "${days}d " 30 | (( $hours > 0 )) && echo -n "${hours}h " 31 | (( $minutes > 0 )) && echo -n "${minutes}m " 32 | echo "${seconds}s" 33 | } 34 | 35 | # displays the exec time of the last command if set threshold was exceeded 36 | prompt_purity_cmd_exec_time() { 37 | local stop=$EPOCHSECONDS 38 | local start=${cmd_timestamp:-$stop} 39 | integer elapsed=$stop-$start 40 | (($elapsed > ${PURITY_CMD_MAX_EXEC_TIME:=5})) && prompt_purity_human_time $elapsed 41 | } 42 | 43 | prompt_purity_preexec() { 44 | cmd_timestamp=$EPOCHSECONDS 45 | 46 | # shows the current dir and executed command in the title when a process is active 47 | print -Pn "\e]0;" 48 | echo -nE "$PWD:t: $2" 49 | print -Pn "\a" 50 | } 51 | 52 | # string length ignoring ansi escapes 53 | prompt_purity_string_length() { 54 | echo ${#${(S%%)1//(\%([KF1]|)\{*\}|\%[Bbkf])}} 55 | } 56 | 57 | prompt_purity_precmd() { 58 | # shows the full path in the title 59 | print -Pn '\e]0;%~\a' 60 | 61 | local prompt_purity_preprompt="%c$(git_prompt_info) $(git_prompt_status)" 62 | print -P ' %F{yellow}`prompt_purity_cmd_exec_time`%f' 63 | 64 | # check async if there is anything to pull 65 | (( ${PURITY_GIT_PULL:-1} )) && { 66 | # check if we're in a git repo 67 | command git rev-parse --is-inside-work-tree &>/dev/null && 68 | # check check if there is anything to pull 69 | command git fetch &>/dev/null && 70 | # check if there is an upstream configured for this branch 71 | command git rev-parse --abbrev-ref @'{u}' &>/dev/null && 72 | (( $(command git rev-list --right-only --count HEAD...@'{u}' 2>/dev/null) > 0 )) && 73 | # some crazy ansi magic to inject the symbol into the previous line 74 | print -Pn "\e7\e[0G\e[`prompt_purity_string_length $prompt_purity_preprompt`C%F{cyan}⇣%f\e8" 75 | } &! 76 | 77 | # reset value since `preexec` isn't always triggered 78 | unset cmd_timestamp 79 | } 80 | 81 | 82 | prompt_purity_setup() { 83 | # prevent percentage showing up 84 | # if output doesn't end with a newline 85 | export PROMPT_EOL_MARK='' 86 | 87 | prompt_opts=(cr subst percent) 88 | 89 | zmodload zsh/datetime 90 | autoload -Uz add-zsh-hook 91 | autoload -Uz vcs_info 92 | 93 | add-zsh-hook precmd prompt_purity_precmd 94 | add-zsh-hook preexec prompt_purity_preexec 95 | 96 | # show username@host if logged in through SSH 97 | [[ "$SSH_CONNECTION" != '' ]] && prompt_purity_username='%n@%m ' 98 | 99 | ZSH_THEME_GIT_PROMPT_PREFIX=" %F{cyan}git:%f%F{yellow}" 100 | ZSH_THEME_GIT_PROMPT_SUFFIX="%b" 101 | ZSH_THEME_GIT_PROMPT_DIRTY="" 102 | ZSH_THEME_GIT_PROMPT_CLEAN="" 103 | 104 | ZSH_THEME_GIT_PROMPT_ADDED="%F{green}✓%f " 105 | ZSH_THEME_GIT_PROMPT_MODIFIED="%F{blue}✶%f " 106 | ZSH_THEME_GIT_PROMPT_DELETED="%F{red}✗%f " 107 | ZSH_THEME_GIT_PROMPT_RENAMED="%F{magenta}➜%f " 108 | ZSH_THEME_GIT_PROMPT_UNMERGED="%F{yellow}═%f " 109 | ZSH_THEME_GIT_PROMPT_UNTRACKED="%F{cyan}✩%f " 110 | 111 | # prompt turns red if the previous command didn't exit with 0 112 | PROMPT='%F{blue}%c$(git_prompt_info) $(git_prompt_status) %(?.%F{green}.%F{red})❯%f ' 113 | RPROMPT='%F{red}%(?..⏎)%f' 114 | } 115 | 116 | prompt_purity_setup "$@" 117 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Purity 2 | 3 | > Pretty, minimal and fast ZSH prompt 4 | 5 | ![screenshot](https://raw.githubusercontent.com/therealklanni/purity/master/screenshot.png) 6 | > Git status indicators will appear before the prompt terminator, view the source for details 7 | 8 | ## Overview 9 | 10 | Most prompts are cluttered, ugly and slow. I wanted something visually pleasing that stayed out of my way. 11 | 12 | ### Why? 13 | 14 | - Comes with the perfect prompt character. Author went through the whole Unicode range to find it. 15 | - Shows `git` status info. 16 | - Prompt character turns red if the last command didn't exit with `0`. 17 | - Command execution time will be displayed if it exceeds the set threshold. 18 | - Username and host only displayed when in an SSH session. 19 | - Shows the current path in the title and the current directory and command when a process is running. 20 | - Makes an excellent starting point for your own custom prompt. 21 | 22 | 23 | ## Install 24 | 25 | Can be installed with `npm` or manually. 26 | 27 | > **Please note** that plain ZSH and some frameworks (such as Zim) do not include the lib for Git prompt details. As such, you may be required to install this lib separately in those cases. *More information on manually installing the Git lib will be included when it becomes available.* [[2]](https://github.com/therealklanni/purity/issues/2) 28 | 29 | ### npm 30 | 31 | ```sh 32 | $ npm install --global purity-prompt 33 | ``` 34 | 35 | That's it. Skip to [Getting started](#getting-started). 36 | 37 | ### Manually 38 | 39 | 1. Either… 40 | - Clone this repo 41 | - add it as a submodule, or 42 | - just download `purity.zsh` 43 | 44 | 2. Symlink `purity.zsh` to somewhere in [`$fpath`](http://www.refining-linux.org/archives/46/ZSH-Gem-12-Autoloading-functions/) with the name `prompt_purity_setup`. 45 | 46 | #### Example 47 | 48 | ```sh 49 | $ ln -s "$PWD/purity.zsh" /usr/local/share/zsh/site-functions/prompt_purity_setup 50 | ``` 51 | *Run `echo $fpath` to see possible locations.* 52 | 53 | For a user-specific installation (which would not require escalated privileges), simply add a directory to `$fpath` for that user: 54 | 55 | ```sh 56 | # .zshenv or .zshrc 57 | fpath=( "$HOME/.zfunctions" $fpath ) 58 | ``` 59 | 60 | Then install the theme there: 61 | 62 | ```sh 63 | $ ln -s "$PWD/purity.zsh" "$HOME/.zfunctions/prompt_purity_setup" 64 | ``` 65 | 66 | 67 | ## Getting started 68 | 69 | Initialize the prompt system (if not so already) and choose `purity`: 70 | 71 | ```sh 72 | # .zshrc 73 | autoload -U promptinit && promptinit 74 | prompt purity 75 | ``` 76 | 77 | 78 | ## Options 79 | 80 | ### `PURITY_CMD_MAX_EXEC_TIME` 81 | 82 | The max execution time of a process before its run time is shown when it exits. Defaults to `5` seconds. 83 | 84 | ### `PURITY_GIT_PULL` 85 | 86 | Set `PURITY_GIT_PULL=0` to prevent Purity from checking whether the current Git remote has been updated. 87 | 88 | ## Example 89 | 90 | ```sh 91 | # .zshrc 92 | 93 | autoload -U promptinit && promptinit 94 | 95 | # optionally define some options 96 | PURITY_CMD_MAX_EXEC_TIME=10 97 | 98 | prompt purity 99 | ``` 100 | 101 | 102 | ## Tips 103 | 104 | [Solarized](http://ethanschoonover.com/solarized) theme with the [Source Code Pro](https://github.com/adobe/source-code-pro) font (12pt) is a beautiful combination, as seen in the screenshot above. Just make sure you have anti-aliasing enabled in your Terminal. 105 | 106 | 107 | ## Integration 108 | 109 | ### [oh-my-zsh](https://github.com/robbyrussell/oh-my-zsh) 110 | 111 | Symlink (or copy) `purity.zsh` to `~/.oh-my-zsh/custom/purity.zsh-theme` and add `ZSH_THEME="purity"` to your `.zshrc` file. 112 | 113 | ### [prezto](https://github.com/sorin-ionescu/prezto) 114 | 115 | Symlink (or copy) `purity.zsh` to `~/.zprezto/modules/prompt/functions/prompt_purity_setup` alongside Prezto's other prompts. Then `set zstyle ':prezto:module:prompt' theme 'purity'` in `~/.zpreztorc`. 116 | 117 | ### [antigen](https://github.com/zsh-users/antigen) 118 | 119 | Add `antigen bundle therealklanni/purity` to your .zshrc file (do not use the `antigen theme` function). 120 | 121 | 122 | ## License 123 | 124 | [MIT](http://opensource.org/licenses/MIT) © [Kevin Lanni](https://github.com/therealklanni) 125 | --------------------------------------------------------------------------------