├── COPYRIGHT ├── LICENSE-APACHE ├── LICENSE-MIT ├── README.md ├── fish_mode_prompt.fish ├── fish_prompt.fish └── shellder.zsh-theme /COPYRIGHT: -------------------------------------------------------------------------------- 1 | Short version for non-laywers: 2 | The shellder project is dual-licensed under Apache 2.0 and MIT terms. 3 | 4 | Longer version: 5 | Copyright 2015-2020 Hyeon Kim 6 | 7 | Licensed under the Apache License, Version 2.0 or the MIT license 9 | , at your 10 | option. This file may not be copied, modified, or distributed 11 | except according to those terms. 12 | -------------------------------------------------------------------------------- /LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /LICENSE-MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015-2020, Hyeon Kim 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | **UNMAINTAINED**: I don't use MSYS2 anymore so I don't maintain this project 2 | anymore. If you want to use shellder, consider the alternatives below: 3 | 4 | 1. [powerlevel10k](https://github.com/romkatv/powerlevel10k) 5 | - Lowest latency. Utilizes async tasks and gitstatusd. 6 | - Only for ZSH 7 | - Not suits with MSYS2 or Cygwin since it's a big shell scripts. (But who uses MSYS2/Cygwin while we have WSL2?) 8 | 2. [starship](https://starship.rs/) 9 | - Higher latency than powerlevel10k, but still it's faster than most shell themes. 10 | - Compatible with many shell environments (i.e. Powershell, bash, tcsh, fish, ...) 11 | - No slowdown in MSYS2 or Cygwin since it's a Rust binary not a shell script. 12 | 13 |   14 | 15 | -------- 16 | 17 |   18 | 19 | 21 | 22 | shellder 23 | ======== 24 | 1. **No solarized** ― xterm256 colors are beautiful enough 25 | 2. **zsh** + **fish** support 26 | 3. **Speed** ― Carefully optimized for slow environments like MSYS2 27 | 28 |   29 | 30 | ![screenshot image of shellder](https://raw.githubusercontent.com/simnalamburt/i/master/shellder/screenshot.png) 31 | 32 | Installation 33 | -------- 34 | You can install shellder via various plugin managers. 35 | 36 | ### Zsh, [zinit] 37 | ```zsh 38 | # ~/.zshrc 39 | zinit light simnalamburt/shellder 40 | ``` 41 | 42 | ### Fish, [chips] 43 | ```yaml 44 | # ~/.config/chips/plugin.yaml 45 | github: 46 | - simnalamburt/shellder 47 | ``` 48 | 49 | ### Fish, [oh-my-fish] 50 | ```yaml 51 | # ~/.config/chips/plugin.yaml 52 | github: 53 | - simnalamburt/shellder 54 | ``` 55 | 56 |   57 | 58 | Configuration 59 | ------- 60 | You can turn off Fish-like path shrinking by adding the following to your `~/.zshrc`: 61 | 62 | ```zsh 63 | # ~/.zshrc 64 | export SHELLDER_KEEP_PATH=1 65 | ``` 66 | 67 | To control path shrinking in fish shell, set `fish_prompt_pwd_dir_length` or `fish_prompt_pwd_full_dirs` environment variable. See [prompt_pwd](https://fishshell.com/docs/current/cmds/prompt_pwd.html) for the further details. 68 | 69 |   70 | 71 | ## Fonts 72 | You'll need a powerline patched font. If you don't have one, download one or 73 | patch some fonts on you own. 74 | 75 | - https://github.com/powerline/fonts 76 | - https://github.com/ryanoasis/nerd-fonts 77 | 78 |   79 | 80 | -------- 81 | *shellder* is primarily distributed under the terms of both the [MIT license] 82 | and the [Apache License (Version 2.0)]. See [COPYRIGHT] for details. 83 | 84 | [zinit]: https://github.com/zdharma/zinit 85 | [chips]: https://github.com/xtendo-org/chips 86 | [oh-my-fish]: https://github.com/oh-my-fish/oh-my-fish 87 | [MIT license]: LICENSE-MIT 88 | [Apache License (Version 2.0)]: LICENSE-APACHE 89 | [COPYRIGHT]: COPYRIGHT 90 | -------------------------------------------------------------------------------- /fish_mode_prompt.fish: -------------------------------------------------------------------------------- 1 | function fish_mode_prompt 2 | if test "$fish_key_bindings" = "fish_vi_key_bindings" 3 | or test "$fish_key_bindings" = "fish_hybrid_key_bindings" 4 | switch $fish_bind_mode 5 | case default 6 | prompt_segment blue black "N" 7 | case insert 8 | prompt_segment green black "I" 9 | case replace_one 10 | prompt_segment red black "R" 11 | case visual 12 | prompt_segment magenta black "V" 13 | end 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /fish_prompt.fish: -------------------------------------------------------------------------------- 1 | # Set these options in your config.fish (if you want to :]) 2 | # 3 | # set -g theme_display_user yes 4 | # set -g theme_hostname never 5 | # set -g theme_hostname always 6 | # set -g default_user your_normal_user 7 | 8 | 9 | 10 | # Backward compatibility 11 | # 12 | # Note: Do not depend on these behavior. These can be removed in anytime by the 13 | # author in the name of code readability. 14 | if set -q theme_hide_hostname 15 | # Existing $theme_hostname will always override $theme_hide_hostname 16 | if not set -q theme_hostname 17 | if [ "theme_hide_hostname" = "yes" ] 18 | set -g theme_hostname never 19 | end 20 | if [ "theme_hide_hostname" = "no" ] 21 | set -g theme_hostname always 22 | end 23 | end 24 | end 25 | 26 | 27 | # 28 | # Segments functions 29 | # 30 | set -g current_bg NONE 31 | set -g segment_separator \uE0B0 32 | 33 | function prompt_segment -d "Function to draw a segment" 34 | set -l bg 35 | set -l fg 36 | if [ -n "$argv[1]" ] 37 | set bg $argv[1] 38 | else 39 | set bg normal 40 | end 41 | if [ -n "$argv[2]" ] 42 | set fg $argv[2] 43 | else 44 | set fg normal 45 | end 46 | if [ "$current_bg" != 'NONE' -a "$argv[1]" != "$current_bg" ] 47 | set_color -b $bg 48 | set_color $current_bg 49 | echo -n "$segment_separator " 50 | set_color -b $bg 51 | set_color $fg 52 | else 53 | set_color -b $bg 54 | set_color $fg 55 | echo -n " " 56 | end 57 | set current_bg $argv[1] 58 | if [ -n "$argv[3]" ] 59 | echo -n -s $argv[3] " " 60 | end 61 | end 62 | 63 | function prompt_finish -d "Close open segments" 64 | if [ -n $current_bg ] 65 | set_color -b normal 66 | set_color $current_bg 67 | echo -n "$segment_separator " 68 | end 69 | set_color normal 70 | set -g current_bg NONE 71 | end 72 | 73 | 74 | # 75 | # Components 76 | # 77 | function prompt_virtual_env -d "Display Python virtual environment" 78 | if test "$VIRTUAL_ENV" 79 | prompt_segment white black (basename $VIRTUAL_ENV) 80 | end 81 | end 82 | 83 | 84 | function prompt_user -d "Display current user if different from $default_user" 85 | set -l BG 444444 86 | set -l FG BCBCBC 87 | 88 | if [ "$theme_display_user" = "yes" ] 89 | if [ "$USER" != "$default_user" -o -n "$SSH_CLIENT" ] 90 | set USER (whoami) 91 | get_hostname 92 | if [ $HOSTNAME_PROMPT ] 93 | set USER_PROMPT $USER@$HOSTNAME_PROMPT 94 | else 95 | set USER_PROMPT $USER 96 | end 97 | prompt_segment $BG $FG $USER_PROMPT 98 | end 99 | else 100 | get_hostname 101 | if [ $HOSTNAME_PROMPT ] 102 | prompt_segment $BG $FG $HOSTNAME_PROMPT 103 | end 104 | end 105 | end 106 | 107 | function get_hostname -d "Set current hostname to prompt variable $HOSTNAME_PROMPT if connected via SSH" 108 | set -g HOSTNAME_PROMPT "" 109 | if [ "$theme_hostname" = "always" -o \( "$theme_hostname" != "never" -a -n "$SSH_CLIENT" \) ] 110 | set -g HOSTNAME_PROMPT (hostname) 111 | end 112 | end 113 | 114 | 115 | function prompt_dir -d "Display the current directory" 116 | prompt_segment 1C1C1C FFFFFF (prompt_pwd) 117 | end 118 | 119 | 120 | function prompt_hg -d "Display mercurial state" 121 | set -l branch 122 | set -l state 123 | if command hg id >/dev/null 2>&1 124 | if command hg prompt >/dev/null 2>&1 125 | set branch (command hg prompt "{branch}") 126 | set state (command hg prompt "{status}") 127 | set branch_symbol \uE0A0 128 | if [ "$state" = "!" ] 129 | prompt_segment red white "$branch_symbol $branch ±" 130 | else if [ "$state" = "?" ] 131 | prompt_segment yellow black "$branch_symbol $branch ±" 132 | else 133 | prompt_segment green black "$branch_symbol $branch" 134 | end 135 | end 136 | end 137 | end 138 | 139 | 140 | function prompt_git -d "Display the current git state" 141 | set -l ref 142 | if command git rev-parse --is-inside-work-tree >/dev/null 2>&1 143 | set ref (command git symbolic-ref HEAD 2> /dev/null) 144 | if [ $status -gt 0 ] 145 | set -l branch (command git show-ref --head -s --abbrev |head -n1 2> /dev/null) 146 | set ref "➦ $branch " 147 | end 148 | set branch_symbol \uE0A0 149 | set -l branch (echo $ref | sed "s-refs/heads/-$branch_symbol -") 150 | 151 | set -l BG PROMPT 152 | set -l dirty (command git status --porcelain --ignore-submodules=dirty 2> /dev/null) 153 | if [ "$dirty" = "" ] 154 | set BG green 155 | set PROMPT "$branch" 156 | else 157 | set BG yellow 158 | set dirty '' 159 | 160 | # Check if there's any commit in the repo 161 | set -l empty 0 162 | git rev-parse --quiet --verify HEAD > /dev/null 2>&1; or set empty 1 163 | 164 | set -l target 165 | if [ $empty = 1 ] 166 | # The repo is empty 167 | set target '4b825dc642cb6eb9a060e54bf8d69288fbee4904' 168 | else 169 | # The repo is not emtpy 170 | set target 'HEAD' 171 | 172 | # Check for unstaged change only when the repo is not empty 173 | set -l unstaged 0 174 | git diff --no-ext-diff --ignore-submodules=dirty --quiet --exit-code; or set unstaged 1 175 | if [ $unstaged = 1 ]; set dirty $dirty'●'; end 176 | end 177 | 178 | # Check for staged change 179 | set -l staged 0 180 | git diff-index --cached --quiet --exit-code --ignore-submodules=dirty $target; or set staged 1 181 | if [ $staged = 1 ]; set dirty $dirty'✚'; end 182 | 183 | # Check for dirty 184 | if [ "$dirty" = "" ] 185 | set PROMPT "$branch" 186 | else 187 | set PROMPT "$branch $dirty" 188 | end 189 | end 190 | prompt_segment $BG black $PROMPT 191 | end 192 | end 193 | 194 | 195 | function prompt_svn -d "Display the current svn state" 196 | set -l ref 197 | if command svn ls . >/dev/null 2>&1 198 | set branch (svn_get_branch) 199 | set branch_symbol \uE0A0 200 | set revision (svn_get_revision) 201 | prompt_segment green black "$branch_symbol $branch:$revision" 202 | end 203 | end 204 | 205 | function svn_get_branch -d "get the current branch name" 206 | svn info 2> /dev/null | awk -F/ \ 207 | '/^URL:/ { \ 208 | for (i=0; i<=NF; i++) { \ 209 | if ($i == "branches" || $i == "tags" ) { \ 210 | print $(i+1); \ 211 | break;\ 212 | }; \ 213 | if ($i == "trunk") { print $i; break; } \ 214 | } \ 215 | }' 216 | end 217 | 218 | function svn_get_revision -d "get the current revision number" 219 | svn info 2> /dev/null | sed -n 's/Revision:\ //p' 220 | end 221 | 222 | 223 | function prompt_status -d "the symbols for a non zero exit status, root and background jobs" 224 | if [ $RETVAL -ne 0 ] 225 | prompt_segment black red "✘" 226 | end 227 | 228 | # if superuser (uid == 0) 229 | set -l uid (id -u $USER) 230 | if [ $uid -eq 0 ] 231 | prompt_segment black yellow "⚡" 232 | end 233 | 234 | # Jobs display 235 | if [ (jobs -l | wc -l) -gt 0 ] 236 | prompt_segment black cyan "⚙" 237 | end 238 | end 239 | 240 | if printf '%s\n' '2.2.0' $FISH_VERSION | sort --check=silent --version-sort 241 | # Current version ≥ 2.2.0 242 | function __exists -a name -d "Check if a function or program does exist." 243 | command -v "$name" ^/dev/null >&2 244 | end 245 | else 246 | # Current version < 2.2.0 247 | function __exists -a name -d "Check if a function or program does exist." 248 | type "$name" ^/dev/null >&2 249 | end 250 | end 251 | 252 | 253 | # 254 | # Prompt 255 | # 256 | function fish_prompt 257 | set -g RETVAL $status 258 | prompt_status 259 | prompt_virtual_env 260 | prompt_user 261 | prompt_dir 262 | __exists hg; and prompt_hg 263 | __exists git; and prompt_git 264 | __exists svn; and prompt_svn 265 | prompt_finish 266 | end 267 | -------------------------------------------------------------------------------- /shellder.zsh-theme: -------------------------------------------------------------------------------- 1 | # vim:ft=zsh ts=2 sw=2 sts=2 2 | 3 | # 4 | # Segment drawing 5 | # 6 | CURRENT_BG='NONE' 7 | 8 | # 9 | # color scheme 10 | # 11 | SHELLDER_CONTEXT_BG=${SHELLDER_CONTEXT_BG:-238} 12 | SHELLDER_CONTEXT_FG=${SHELLDER_CONTEXT_FG:-250} 13 | 14 | SHELLDER_DIRECTORY_BG=${SHELLDER_DIRECTORY_BG:-234} 15 | SHELLDER_DIRECTORY_FG=${SHELLDER_DIRECTORY_FG:-231} 16 | 17 | SHELLDER_GIT_CLEAN_BG=${SHELLDER_GIT_CLEAN_BG:-034} 18 | SHELLDER_GIT_CLEAN_FG=${SHELLDER_GIT_CLEAN_FG:-'black'} 19 | 20 | SHELLDER_GIT_UNTRACKED_BG=${SHELLDER_GIT_UNTRACKED_BG:-226} 21 | SHELLDER_GIT_UNTRACKED_FG=${SHELLDER_GIT_UNTRACKED_FG:-'black'} 22 | 23 | SHELLDER_GIT_UNPUSHED_BG=${SHELLDER_GIT_UNPUSHED_BG:-48} 24 | SHELLDER_GIT_UNPUSHED_FG=${SHELLDER_GIT_UNPUSHED_FG:-'black'} 25 | 26 | SHELLDER_GIT_MODIFIED_BG=${SHELLDER_GIT_MODIFIED_BG:-172} 27 | SHELLDER_GIT_MODIFIED_FG=${SHELLDER_GIT_MODIFIED_FG:-'black'} 28 | 29 | SHELLDER_GIT_STAGED_BG=${SHELLDER_GIT_STAGED_BG:-166} 30 | SHELLDER_GIT_STAGED_FG=${SHELLDER_GIT_STAGED_FG:-'black'} 31 | 32 | SHELLDER_GIT_ADDED_BG=${SHELLDER_GIT_ADDED_BG:-218} 33 | SHELLDER_GIT_ADDED_FG=${SHELLDER_GIT_ADDED_FG:-'black'} 34 | 35 | SHELLDER_VIRTUALENV_BG=${SHELLDER_VIRTUALENV_BG:-017} 36 | SHELLDER_VIRTUALENV_FG=${SHELLDER_VIRTUALENV_FG:-189} 37 | 38 | SHELLDER_STATUS_BG=${SHELLDER_STATUS_BG:-236} 39 | SHELLDER_STATUS_FG=${SHELLDER_STATUS_FG:-'default'} 40 | 41 | # Special Powerline characters 42 | set_separator() { 43 | local LC_ALL='' LC_CTYPE='en_US.UTF-8' 44 | SEGMENT_SEPARATOR=$'\ue0b0' 45 | } 46 | set_separator 47 | 48 | # Begin a segment 49 | # Takes two arguments, background and foreground. Both can be omitted, 50 | # rendering default background/foreground. 51 | prompt_segment() { 52 | local bg fg 53 | [[ -n $1 ]] && bg="%K{$1}" || bg='%k' 54 | [[ -n $2 ]] && fg="%F{$2}" || fg='%f' 55 | if [[ "$CURRENT_BG" != 'NONE' && $1 != "$CURRENT_BG" ]]; then 56 | echo -n " %{$bg%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR%{$fg%} " 57 | else 58 | echo -n "%{$bg%}%{$fg%} " 59 | fi 60 | CURRENT_BG=$1 61 | [[ -n $3 ]] && echo -n "$3" 62 | } 63 | 64 | # End the prompt, closing any open segments 65 | prompt_end() { 66 | if [[ -n "$CURRENT_BG" ]]; then 67 | echo -n " %{%k%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR" 68 | else 69 | echo -n '%{%k%}' 70 | fi 71 | echo -n '%{%f%}' 72 | CURRENT_BG='' 73 | } 74 | 75 | 76 | # 77 | # Prompt functions 78 | # 79 | 80 | # Context: user@hostname (who am I and where am I) 81 | prompt_context() { 82 | local prompt 83 | if [[ -n "$SSH_CLIENT" ]]; then 84 | if [[ "$USER" != "$DEFAULT_USER" ]]; then 85 | prompt="%(!.%{%F{yellow}%}.)$USER@%m" 86 | else 87 | prompt='%(!.%{%F{yellow}%}.)%m' 88 | fi 89 | prompt_segment "$SHELLDER_CONTEXT_BG" "$SHELLDER_CONTEXT_FG" "$prompt" 90 | fi 91 | } 92 | 93 | # Git: branch/detached head, dirty status 94 | prompt_git() { 95 | local repo_path 96 | local GIT_STATUS 97 | 98 | repo_path=$(git rev-parse --git-dir 2>/dev/null) 99 | 100 | if [[ -n $repo_path ]]; then 101 | local PL_BRANCH_CHAR dirty bgcolor fgcolor mode ref 102 | 103 | set_branch_char() { 104 | local LC_ALL='' LC_CTYPE='en_US.UTF-8' 105 | PL_BRANCH_CHAR=$'\ue0a0' #  106 | } 107 | set_branch_char 108 | 109 | GIT_STATUS=$( 110 | command git status --porcelain --ignore-submodules=dirty 2>/dev/null | 111 | sed -e 's/^ //g' 112 | ) 113 | modified=$(<<< "$GIT_STATUS" grep '^M') 114 | untracked=$(<<< "$GIT_STATUS" grep '^?') 115 | added=$(<<< "$GIT_STATUS" grep '^A') 116 | staged=$(git diff --name-only --cached) 117 | unpushed=$(command git cherry 2>/dev/null) 118 | 119 | if [[ -n $added ]]; then 120 | bgcolor=$SHELLDER_GIT_ADDED_BG 121 | fgcolor=$SHELLDER_GIT_ADDED_FG 122 | elif [[ -n $staged ]]; then 123 | bgcolor=$SHELLDER_GIT_STAGED_BG 124 | fgcolor=$SHELLDER_GIT_STAGED_FG 125 | elif [[ -n $modified ]]; then 126 | bgcolor=$SHELLDER_GIT_MODIFIED_BG 127 | fgcolor=$SHELLDER_GIT_MODIFIED_FG 128 | elif [[ -n $untracked ]]; then 129 | bgcolor=$SHELLDER_GIT_UNTRACKED_BG 130 | fgcolor=$SHELLDER_GIT_UNTRACKED_FG 131 | elif [[ -n $unpushed ]]; then 132 | bgcolor=$SHELLDER_GIT_UNPUSHED_BG 133 | fgcolor=$SHELLDER_GIT_UNPUSHED_FG 134 | else 135 | bgcolor=$SHELLDER_GIT_CLEAN_BG 136 | fgcolor=$SHELLDER_GIT_CLEAN_FG 137 | fi 138 | prompt_segment "$bgcolor" "$fgcolor" 139 | 140 | if [[ -e "${repo_path}/BISECT_LOG" ]]; then 141 | mode=' ' 142 | elif [[ -e "${repo_path}/MERGE_HEAD" ]]; then 143 | mode=' >M<' 144 | elif [[ -e "${repo_path}/rebase" || -e "${repo_path}/rebase-apply" || -e "${repo_path}/rebase-merge" || -e "${repo_path}/../.dotest" ]]; then 145 | mode=' >R>' 146 | fi 147 | 148 | # vcs_info is too slow with MSYS2 (~300ms with i7-6770K + SSD) 149 | if [[ -z $MSYS ]]; then 150 | autoload -Uz vcs_info 151 | zstyle ':vcs_info:*' enable git 152 | zstyle ':vcs_info:*' check-for-changes true 153 | zstyle ':vcs_info:*' stagedstr '✚' 154 | zstyle ':vcs_info:*' unstagedstr '●' 155 | zstyle ':vcs_info:*' formats ' %u%c' 156 | zstyle ':vcs_info:*' actionformats ' %u%c' 157 | vcs_info 158 | else 159 | if [[ -n $dirty ]]; then 160 | vcs_info_msg_0_=' !' 161 | fi 162 | fi 163 | 164 | ref=$(git symbolic-ref HEAD 2> /dev/null) || ref="➦ $(git rev-parse --short HEAD 2> /dev/null)" 165 | echo -n "${ref/refs\/heads\//$PL_BRANCH_CHAR }${vcs_info_msg_0_%% }${mode}" 166 | fi 167 | } 168 | 169 | prompt_hg() { 170 | local rev 171 | if hg id >/dev/null 2>&1; then 172 | if hg prompt >/dev/null 2>&1; then 173 | if [[ $(hg prompt '{status|unknown}') = '?' ]]; then 174 | # if files are not added 175 | prompt_segment red white 176 | st='±' 177 | elif [[ -n $(hg prompt '{status|modified}') ]]; then 178 | # if any modification 179 | prompt_segment yellow black 180 | st='±' 181 | else 182 | # if working copy is clean 183 | prompt_segment green black 184 | fi 185 | echo -n "$(hg prompt '☿ {rev}@{branch}')" "$st" 186 | else 187 | st='' 188 | rev=$(hg id -n 2>/dev/null | sed 's/[^-0-9]//g') 189 | branch=$(hg id -b 2>/dev/null) 190 | if hg st | grep -q "^\?"; then 191 | prompt_segment red black 192 | st='±' 193 | elif hg st | grep -q '^[MA]'; then 194 | prompt_segment yellow black 195 | st='±' 196 | else 197 | prompt_segment green black 198 | fi 199 | echo -n "☿ $rev@$branch" $st 200 | fi 201 | fi 202 | } 203 | 204 | # Turn '/some/quite/very/long/path' into '/s/q/v/l/path' 205 | function shrinked_path() { 206 | local paths=(${PWD/$HOME/\~}) 'cur_dir' 207 | paths=(${(s:/:)paths}) 208 | for idx in {1..$#paths}; do 209 | if [[ idx -lt $#paths ]]; then 210 | cur_dir+="${paths[idx]:0:1}" 211 | else 212 | cur_dir+="${paths[idx]}" 213 | fi 214 | cur_dir+='/' 215 | done 216 | echo "${cur_dir: :-1}" 217 | } 218 | 219 | # Dir: current working directory 220 | prompt_dir() { 221 | local dir 222 | if [[ -n $SHELLDER_KEEP_PATH ]]; then 223 | dir='%~' 224 | else 225 | dir=$(shrinked_path) 226 | fi 227 | prompt_segment "$SHELLDER_DIRECTORY_BG" "$SHELLDER_DIRECTORY_FG" "$dir" 228 | } 229 | 230 | # Virtualenv: current working virtualenv 231 | prompt_virtualenv() { 232 | local virtualenv_path="$VIRTUAL_ENV" 233 | if [[ -n $virtualenv_path && -n $VIRTUAL_ENV_DISABLE_PROMPT ]]; then 234 | prompt_segment "$SHELLDER_VIRTUALENV_BG" "$SHELLDER_VIRTUALENV_FG" "$(basename "$virtualenv_path")" 235 | fi 236 | } 237 | 238 | # Status: error + root + background jobs 239 | prompt_status() { 240 | local symbols 241 | symbols=() 242 | [[ $RETVAL -ne 0 ]] && symbols+="%{%F{yellow}%}$RETVAL" 243 | [[ $UID -eq 0 ]] && symbols+='%{%F{yellow}%}⚡' 244 | [[ $(jobs -l | wc -l) -gt 0 ]] && symbols+='%{%F{cyan}%}⚙' 245 | 246 | [[ -n "$symbols" ]] && prompt_segment "$SHELLDER_STATUS_BG" "$SHELLDER_STATUS_FG" "$symbols" 247 | } 248 | 249 | 250 | # 251 | # Prompt 252 | # 253 | build_prompt() { 254 | RETVAL=$? 255 | prompt_status 256 | prompt_virtualenv 257 | prompt_context 258 | prompt_dir 259 | prompt_git 260 | prompt_hg 261 | prompt_end 262 | } 263 | 264 | export VIRTUAL_ENV_DISABLE_PROMPT='true' 265 | PROMPT='%{%f%b%k%}$(build_prompt) ' 266 | --------------------------------------------------------------------------------