├── .github └── workflows │ └── test.yml ├── LICENSE ├── Makefile ├── README.md ├── lean.gif ├── lean.plugin.zsh ├── prompt_lean_setup └── prompt_lean_test.zsh /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: Tests 2 | on: 3 | pull_request: 4 | types: 5 | - opened 6 | - synchronize 7 | branches: 8 | - master 9 | push: 10 | branches: 11 | - master 12 | 13 | jobs: 14 | tests: 15 | name: Run tests 16 | runs-on: ubuntu-latest 17 | steps: 18 | - name: Set up git repository 19 | uses: actions/checkout@v2 20 | - name: Install zsh 21 | run: sudo apt-get update; sudo apt-get install zsh 22 | - name: Test 23 | run: make 24 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2016-2020 The CoreDNS authors and contributors 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: test 2 | test: 3 | @zsh prompt_lean_test.zsh 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # About 2 | 3 | After having used [prompt pure](https://github.com/sindresorhus/pure) for about a year, I felt that 4 | a two-line prompt was not for me. Also not utilizing the right side of the terminal seemed a missed 5 | opportunity. Still there is much to like: the elapsed time of a process, the coloring of the prompt 6 | if the exit code of the process isn't 0, git integration. So I took "pure", mixed in my ideas of 7 | what a prompt should look like and came up with "lean" - a 1 line prompt that stays out of your 8 | face. 9 | 10 | When lean starts, only 2 characters show on the screen '%' on the left and '~' on the right. 11 | 12 | ![lean example gif](https://github.com/miekg/lean/blob/master/lean.gif "Example Session Using Lean") 13 | 14 | So lean is an evolution of pure, with the following changes: 15 | 16 | * Defaults to a very sparse setup, only showing information you need at the moment. 17 | * Comes with the perfect prompt character. Author went through the entire ASCII range to find it 18 | (and found it pretty quickly!) 19 | * Never displays your username (assuming you know who you are). 20 | * When tmux is active it shows a yellow 't' (I disabled the tmux bar, so this is some visual 21 | indication that tmux is active). If you don't want this indicator, you can always set 22 | `PROMPT_LEAN_TMUX=""` prior to loading this plugin (or prior to sourcing `zgen`, etc.). 23 | * Show remote host if logged in through SSH. 24 | * All in one line, most stuff in the right prompt, leaving the left prompt nice and clean 25 | * Shows background jobs (in the left prompt) 26 | * Show (dirty) git repos (can be disabled by setting `PROMPT_LEAN_VCS` to `0`). The branch name is 27 | truncated to 20 characters. 28 | * Shortens path if needed (longer then 70% of your screen). Two methods are provided: 'truncate' 29 | and 'shrink' (fish-style working directory). Set `PROMPT_LEAN_ABBR_METHOD` to choose the one you 30 | like the most (default is 'truncate'). Set `PROMPT_LEAN_PWD` to `0` to disable showing the path 31 | altogether. 32 | * Uses `PROMPT_LEAN_LEFT` and `PROMPT_LEAN_RIGHT` to allow customization of the left and/or right 33 | side of the prompt. 34 | * For a configurable insert-mode indicator, set the `PROMPT_LEAN_VIMODE` and 35 | `PROMPT_LEAN_VIMODE_FORMAT` variables. `PROMPT_LEAN_VIMODE_FORMAT` defaults to 36 | `"%F{red}[NORMAL]%f"` 37 | * Configurable colors to match your preferred scheme, by setting `PROMPT_LEAN_COLOR1` and 38 | `PROMPT_LEAN_COLOR2` 39 | * Use `PROMPT_LEAN_NOTITLE` to customize when the title should not be displayed. Useful for 40 | terminals that can not show title properly. 41 | * Use `PROMPT_LEAN_VCS` and `PROMPT_LEAN_PWD` to disable showing VCS info or the current working 42 | directory. 43 | 44 | # Installation 45 | 46 | ## zgen 47 | 48 | If you use [zgen](https://github.com/tarjoilija/zgen) you can add the following to your `~/.zshrc`: 49 | 50 | ~~~ 51 | zgen load miekg/lean 52 | ~~~ 53 | 54 | and force reload with `zgen reset && source ~/.zshrc`. 55 | 56 | Note you must have the option PROMPT_SUBST set, see zshoptions(1). 57 | 58 | ## prezto 59 | 60 | If you use [prezto](https://github.com/sorin-ionescu/prezto) you should do the following: 61 | 62 | ~~~ 63 | cd $ZPREZTODIR && git clone --recurse-submodules https://github.com/belak/prezto-contrib contrib 64 | ~~~ 65 | 66 | Then in `~/.zpreztorc` add `contrib-prompt` to module load list and select `lean` as a theme: 67 | 68 | ~~~ 69 | zstyle ':prezto:load' pmodule \ 70 | ... \ 71 | 'contrib-prompt' \ 72 | 'prompt' \ 73 | ... 74 | 75 | zstyle ':prezto:module:prompt' theme 'lean' 76 | ~~~ 77 | 78 | `PROMPT_LEAN_LEFT` and `PROMPT_LEAN_RIGHT` should be customized in `~/.zshrc`. The rest variables 79 | should be customized in `~/.zshenv`. 80 | 81 | # Development 82 | 83 | If you make any changes please run `make test` to ensure the (little) test suite is succesfull. 84 | -------------------------------------------------------------------------------- /lean.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/miekg/lean/bc117ce0ab2b98f20df544bbb8413e7c2dcfceec/lean.gif -------------------------------------------------------------------------------- /lean.plugin.zsh: -------------------------------------------------------------------------------- 1 | prompt_lean_setup -------------------------------------------------------------------------------- /prompt_lean_setup: -------------------------------------------------------------------------------- 1 | # lean prompt theme 2 | # by Miek Gieben: https://github.com/miekg/lean 3 | # 4 | # Based on Pure by Sindre Sorhus: https://github.com/sindresorhus/pure 5 | # Colors used: (see Vim's iceberg theme) 6 | # 242 is the gray that is used. 7 | # 110 is the blue. 8 | # 150 is the yellow. 9 | # 10 | # MIT License 11 | 12 | COLOR1=${PROMPT_LEAN_COLOR1-"242"} 13 | COLOR2=${PROMPT_LEAN_COLOR2-"110"} 14 | COLOR3=${PROMPT_LEAN_COLOR3-"150"} 15 | 16 | PROMPT_LEAN_TMUX=${PROMPT_LEAN_TMUX-"t "} 17 | PROMPT_LEAN_PATH_PERCENT=${PROMPT_LEAN_PATH_PERCENT-60} 18 | PROMPT_LEAN_NOTITLE=${PROMPT_LEAN_NOTITLE-0} 19 | PROMPT_LEAN_CMD_MAX_EXEC_TIME=5 20 | PROMPT_LEAN_ABBR_METHOD=${PROMPT_LEAN_ABBR_METHOD-"truncate"} 21 | PROMPT_LEAN_VCS=${PROMPT_LEAN_VCS-1} 22 | PROMPT_LEAN_PWD=${PROMPT_LEAN_PWD-1} 23 | 24 | prompt_lean_help() { 25 | cat <<'EOF' 26 | Lean is a one line prompt that tries to stay out of your face. It utilizes 27 | the right side prompt for most information, like the current working directory 28 | and version control system (only Git)info. The left side of the prompt is only 29 | a '%'. The only other information shown on the left are the jobs numbers of 30 | background jobs. When the exit code of a process isn't zero the prompt turns 31 | red. If a process takes more then 5 (default) seconds to run the total running 32 | time is shown in the next prompt. 33 | 34 | You can invoke it thus: 35 | 36 | prompt lean 37 | 38 | Several aspects Lean can be configured: 39 | 40 | PROMPT_LEAN_TMUX: used to indicate being in tmux, set to "t " by default 41 | PROMPT_LEAN_LEFT: executed to allow custom information in the left side 42 | PROMPT_LEAN_RIGHT: executed to allow custom information in the right side 43 | PROMPT_LEAN_COLOR1: jobs and VCS info indicator color 44 | PROMPT_LEAN_COLOR2: prompt character and directory color 45 | PROMPT_LEAN_COLOR3: elapsed time indicator color 46 | PROMPT_LEAN_VIMODE: used to determine whether or not to display indicator 47 | PROMPT_LEAN_PWD: when set to 0, disables showing CWD in the prompt 48 | PROMPT_LEAN_VCS: when set to 0, disables git details from the prompt, the 49 | branch name is truncated if it's longer than 20 50 | characters 51 | PROMPT_LEAN_VIMODE_FORMAT: 52 | defaults to "%F{red}[NORMAL]%f" 53 | PROMPT_LEAN_NOTITLE: 54 | used to determine wether or not to set title, set to 0 55 | by default 56 | PROMPT_LEAN_ABBR_METHOD: 57 | used to indicate the abbreviation method for directory 58 | paths. Set it either to 'truncate' (default) or 'shrink' 59 | (fish-style working directory) 60 | EOF 61 | } 62 | 63 | # turns seconds into human readable time, 165392 => 1d 21h 56m 32s 64 | prompt_lean_human_time() { 65 | local tmp=$1 66 | local days=$(( tmp / 60 / 60 / 24 )) 67 | local hours=$(( tmp / 60 / 60 % 24 )) 68 | local minutes=$(( tmp / 60 % 60 )) 69 | local seconds=$(( tmp % 60 )) 70 | (( $days > 0 )) && echo -n "${days}d " 71 | (( $hours > 0 )) && echo -n "${hours}h " 72 | (( $minutes > 0 )) && echo -n "${minutes}m " 73 | echo "${seconds}s " 74 | } 75 | 76 | # fastest possible way to check if repo is dirty 77 | prompt_lean_git_dirty() { 78 | if [[ $PROMPT_LEAN_VCS != 1 ]]; then 79 | return 80 | fi 81 | # check if we're in a git repo 82 | command git rev-parse --is-inside-work-tree &>/dev/null || return 83 | # check if it's dirty 84 | local umode="-uno" #|| local umode="-unormal" 85 | command test -n "$(git status --porcelain --ignore-submodules ${umode} 2>/dev/null | head -100)" 86 | 87 | (($? == 0)) && echo '+' 88 | } 89 | 90 | # displays the exec time of the last command if set threshold was exceeded 91 | prompt_lean_cmd_exec_time() { 92 | local stop=$EPOCHSECONDS 93 | local start=${cmd_timestamp:-$stop} 94 | integer elapsed=$stop-$start 95 | (($elapsed > ${PROMPT_LEAN_CMD_MAX_EXEC_TIME})) && prompt_lean_human_time $elapsed 96 | } 97 | 98 | prompt_lean_set_title() { 99 | # prints: 100 | print -Pn "\e]0;" 101 | print -Pn "%1~" 102 | [[ "$SSH_CONNECTION" != '' ]] && print -Pn " %m" 103 | print -rn " $1" 104 | print -Pn "\a" 105 | } 106 | 107 | prompt_lean_preexec() { 108 | typeset -g cmd_timestamp=$EPOCHSECONDS 109 | (($PROMPT_LEAN_NOTITLE != 1)) && prompt_lean_set_title "$1" 110 | } 111 | 112 | prompt_lean_pwd() { 113 | local lean_path="`print -Pn '%~'`" 114 | if (($#lean_path / $COLUMNS.0 * 100 > ${PROMPT_LEAN_PATH_PERCENT:=60})); then 115 | case "$PROMPT_LEAN_ABBR_METHOD" in 116 | "truncate") prompt_lean_abbr_truncate;; 117 | "shrink") prompt_lean_abbr_shrink;; 118 | esac 119 | return 120 | fi 121 | print "$lean_path" 122 | } 123 | 124 | prompt_lean_abbr_truncate() { 125 | print -Pn '...%2/' 126 | } 127 | 128 | prompt_lean_abbr_shrink() { 129 | setopt local_options extendedglob histsubstpattern 130 | 131 | local lean_path=$(print -Pn '%~') 132 | local maxlen=$((PROMPT_LEAN_PATH_PERCENT * COLUMNS / 100)) 133 | local prevlen=0 134 | 135 | # iterate until target length achieved or no more abbreviation possible 136 | while (($#lean_path > maxlen && $#lean_path != prevlen)); do 137 | prevlen=$#lean_path 138 | lean_path=${lean_path:s_(#b)([^/])([^/])##/_$match[1]/_} 139 | done 140 | 141 | echo $lean_path 142 | } 143 | 144 | prompt_lean_precmd() { 145 | [[ $PROMPT_LEAN_VCS == 1 ]] && vcs_info 2>/dev/null 146 | rehash 147 | 148 | local jobs 149 | local prompt_lean_jobs 150 | unset jobs 151 | for a (${(k)jobstates}) { 152 | j=$jobstates[$a];i='${${(@s,:,)j}[2]}' 153 | jobs+=($a${i//[^+-]/}) 154 | } 155 | # print with [ ] and comma separated 156 | prompt_lean_jobs="" 157 | [[ -n $jobs ]] && prompt_lean_jobs="%F{"$COLOR1"}["${(j:,:)jobs}"] " 158 | 159 | local lean_vimode_default="%F{red}[NORMAL]%f" 160 | #If LEAN_VIMODE is set, set lean_vimode_indicator to either PROMPT_LEAN_VIMOD_FORMAT or a default value 161 | local lean_vimode_indicator="${PROMPT_LEAN_VIMODE:+${PROMPT_LEAN_VIMODE_FORMAT:-${lean_vimode_default}}}" 162 | 163 | prompt_lean_vimode="${${KEYMAP/vicmd/$lean_vimode_indicator}/(main|viins)/}" 164 | 165 | setopt promptsubst 166 | local vcs_info_str='' 167 | [[ $PROMPT_LEAN_VCS == 1 ]] && vcs_info_str='$vcs_info_msg_0_' # avoid https://github.com/njhartwell/pw3nage 168 | PROMPT="$prompt_lean_jobs%F{"$COLOR3"}${prompt_lean_tmux}%f`$PROMPT_LEAN_LEFT`%f%(?.%F{"$COLOR2"}.%B%F{203})%#%f%k%b " 169 | 170 | local lean_pwd='' 171 | [[ $PROMPT_LEAN_PWD == 1 ]] && lean_pwd=`prompt_lean_pwd` 172 | RPROMPT="%F{"$COLOR3"}`prompt_lean_cmd_exec_time`%f$prompt_lean_vimode%F{"$COLOR2"}$lean_pwd%F{"$COLOR1"}$vcs_info_str`prompt_lean_git_dirty`$prompt_lean_host%f`$PROMPT_LEAN_RIGHT`%f" 173 | 174 | (($PROMPT_LEAN_NOTITLE != 1)) && prompt_lean_set_title "$1" 175 | 176 | unset cmd_timestamp # reset value since `preexec` isn't always triggered 177 | } 178 | 179 | function zle-keymap-select { 180 | prompt_lean_precmd 181 | zle reset-prompt 182 | } 183 | 184 | prompt_lean_setup() { 185 | prompt_opts=(cr percent sp subst) 186 | 187 | zmodload zsh/datetime 188 | autoload -Uz add-zsh-hook 189 | [[ $PROMPT_LEAN_VCS == 1 ]] && autoload -Uz vcs_info 190 | 191 | [[ "$PROMPT_LEAN_VIMODE" != '' ]] && zle -N zle-keymap-select 192 | 193 | add-zsh-hook precmd prompt_lean_precmd 194 | add-zsh-hook preexec prompt_lean_preexec 195 | 196 | if [[ $PROMPT_LEAN_VCS == 1 ]]; then 197 | zstyle ':vcs_info:*' enable git 198 | zstyle ':vcs_info:git*' formats ' %20>...>%b%>>' 199 | zstyle ':vcs_info:git*' actionformats ' %20>...>%b%>>|%a' 200 | fi 201 | 202 | [[ "$SSH_CONNECTION" != '' ]] && prompt_lean_host=" %F{"$COLOR3"}%m%f" 203 | [[ "$TMUX" != '' ]] && prompt_lean_tmux=$PROMPT_LEAN_TMUX 204 | 205 | return 0 206 | } 207 | 208 | prompt_lean_setup "$@" 209 | -------------------------------------------------------------------------------- /prompt_lean_test.zsh: -------------------------------------------------------------------------------- 1 | #!/bin/zsh 2 | 3 | # Some tests for the prompt. We compare the prompt using hex encoding 4 | # to prevent all the control characters messing up the prompt. 5 | 6 | COLOR1="242" 7 | COLOR2="110" 8 | COLOR3="150" 9 | 10 | function comphex() { 11 | local name="$1" 12 | local a="$2" 13 | local b="$3" 14 | 15 | ah=$(print $a | hexdump) 16 | bh=$(print $b | hexdump) 17 | 18 | if [[ $ah == $bh ]]; then 19 | print " OK - $name" 20 | else 21 | print "FAIL - $name" 22 | print $a |hexdump -C 23 | echo 24 | print $b |hexdump -C 25 | exit 1 26 | fi 27 | } 28 | 29 | source prompt_lean_setup 30 | 31 | ( 32 | prompt_lean_precmd 33 | prompt_lean_preexec 34 | expect='%F{'$COLOR3'}%f%f%(?.%F{'$COLOR2'}.%B%F{203})%#%f%k%b ' 35 | comphex "prompt" $PROMPT $expect 36 | ) 37 | 38 | ( cd /tmp 39 | prompt_lean_precmd 40 | prompt_lean_preexec 41 | expect='%F{'$COLOR3'}%f%F{'$COLOR2'}/tmp%F{'$COLOR1'}$vcs_info_msg_0_%f%f' 42 | comphex "rprompt" $RPROMPT $expect 43 | ) 44 | 45 | ( 46 | function left() { echo left } 47 | PROMPT_LEAN_LEFT=left 48 | 49 | prompt_lean_precmd 50 | prompt_lean_preexec 51 | expect='%F{'$COLOR3'}%fleft%f%(?.%F{'$COLOR2'}.%B%F{203})%#%f%k%b ' 52 | comphex "lean_left" $PROMPT $expect 53 | ) 54 | 55 | ( cd /tmp 56 | function right() { echo right } 57 | PROMPT_LEAN_RIGHT=right 58 | 59 | prompt_lean_precmd 60 | prompt_lean_preexec 61 | expect='%F{'$COLOR3'}%f%F{'$COLOR2'}/tmp%F{'$COLOR1'}$vcs_info_msg_0_%fright%f' 62 | comphex "lean_right" $RPROMPT $expect 63 | ) 64 | 65 | ( 66 | PROMPT_LEAN_TMUX='t' 67 | TMUX='yes' 68 | source prompt_lean_setup # TMUX is only evaluated in setup 69 | 70 | prompt_lean_precmd 71 | prompt_lean_preexec 72 | expect='%F{'$COLOR3'}t%f%f%(?.%F{'$COLOR2'}.%B%F{203})%#%f%k%b ' 73 | comphex "tmux" $PROMPT $expect 74 | ) 75 | 76 | ( cd /tmp 77 | PROMPT_LEAN_CMD_MAX_EXEC_TIME=0.1 78 | sleep 1 79 | 80 | prompt_lean_precmd 81 | prompt_lean_preexec 82 | expect='%F{'$COLOR3'}1s %f%F{'$COLOR2'}/tmp%F{'$COLOR1'}$vcs_info_msg_0_%f%f' 83 | comphex "time" $RPROMPT $expect 84 | ) 85 | 86 | ( LONGDIR="/tmp/app/src/main/java/com/example" 87 | mkdir -p $LONGDIR && cd $LONGDIR 88 | abbr_dir=$(COLUMNS=100 PROMPT_LEAN_PATH_PERCENT=34 prompt_lean_abbr_shrink) 89 | comphex "abbr-shrink-unchanged" $abbr_dir $LONGDIR 90 | ) 91 | 92 | ( LONGDIR="/tmp/app/src/main/java/com/example" 93 | mkdir -p $LONGDIR && cd $LONGDIR 94 | abbr_dir=$(COLUMNS=100 PROMPT_LEAN_PATH_PERCENT=33 prompt_lean_abbr_shrink) 95 | comphex "abbr-shrink-1" $abbr_dir "/t/app/src/main/java/com/example" 96 | ) 97 | 98 | ( LONGDIR="/tmp/app/src/main/java/com/example" 99 | mkdir -p $LONGDIR && cd $LONGDIR 100 | abbr_dir=$(COLUMNS=100 PROMPT_LEAN_PATH_PERCENT=5 prompt_lean_abbr_shrink) 101 | comphex "abbr-shrink-full" $abbr_dir "/t/a/s/m/j/c/example" 102 | ) 103 | --------------------------------------------------------------------------------