pure.zsh-theme 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #!/usr/bin/env zsh
  2. # ------------------------------------------------------------------------------
  3. #
  4. # Pure - A minimal and beautiful theme for oh-my-zsh
  5. #
  6. # Based on the custom Zsh-prompt of the same name by Sindre Sorhus. A huge
  7. # thanks goes out to him for designing the fantastic Pure prompt in the first
  8. # place! I'd also like to thank Julien Nicoulaud for his "nicoulaj" theme from
  9. # which I've borrowed both some ideas and some actual code. You can find out
  10. # more about both of these fantastic two people here:
  11. #
  12. # Sindre Sorhus
  13. # Github: https://github.com/sindresorhus
  14. # Twitter: https://twitter.com/sindresorhus
  15. #
  16. # Julien Nicoulaud
  17. # Github: https://github.com/nicoulaj
  18. # Twitter: https://twitter.com/nicoulaj
  19. #
  20. # License
  21. #
  22. # Copyright (c) 2013 Kasper Kronborg Isager
  23. #
  24. # Permission is hereby granted, free of charge, to any person obtaining a copy
  25. # of this software and associated documentation files (the "Software"), to deal
  26. # in the Software without restriction, including without limitation the rights
  27. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  28. # copies of the Software, and to permit persons to whom the Software is
  29. # furnished to do so, subject to the following conditions:
  30. #
  31. # The above copyright notice and this permission notice shall be included in
  32. # all copies or substantial portions of the Software.
  33. #
  34. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  35. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  36. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  37. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  38. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  39. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  40. # THE SOFTWARE.
  41. #
  42. # ------------------------------------------------------------------------------
  43. # Set required options
  44. #
  45. setopt prompt_subst
  46. # Load required modules
  47. #
  48. autoload -Uz vcs_info
  49. # Set vcs_info parameters
  50. #
  51. zstyle ':vcs_info:*' enable hg bzr git
  52. zstyle ':vcs_info:*:*' unstagedstr '!'
  53. zstyle ':vcs_info:*:*' stagedstr '+'
  54. zstyle ':vcs_info:*:*' formats "$FX[bold]%r$FX[no-bold]/%S" "%s/%b" "%%u%c"
  55. zstyle ':vcs_info:*:*' actionformats "$FX[bold]%r$FX[no-bold]/%S" "%s/%b" "%u%c (%a)"
  56. zstyle ':vcs_info:*:*' nvcsformats "%~" "" ""
  57. # Fastest possible way to check if repo is dirty
  58. #
  59. git_dirty() {
  60. # Check if we're in a git repo
  61. command git rev-parse --is-inside-work-tree &>/dev/null || return
  62. # Check if it's dirty
  63. command git diff --quiet --ignore-submodules HEAD &>/dev/null; [ $? -eq 1 ] && echo "*"
  64. }
  65. # Display information about the current repository
  66. #
  67. repo_information() {
  68. echo "%F{blue}${vcs_info_msg_0_%%/.} %F{8}$vcs_info_msg_1_`git_dirty` $vcs_info_msg_2_%f"
  69. }
  70. # Displays the exec time of the last command if set threshold was exceeded
  71. #
  72. cmd_exec_time() {
  73. local stop=`date +%s`
  74. local start=${cmd_timestamp:-$stop}
  75. let local elapsed=$stop-$start
  76. [ $elapsed -gt 5 ] && echo ${elapsed}s
  77. }
  78. # Get the intial timestamp for cmd_exec_time
  79. #
  80. preexec() {
  81. cmd_timestamp=`date +%s`
  82. }
  83. # Output additional information about paths, repos and exec time
  84. #
  85. precmd() {
  86. vcs_info # Get version control info before we start outputting stuff
  87. print -P "\n$(repo_information) %F{yellow}$(cmd_exec_time)%f"
  88. }
  89. # Define prompts
  90. #
  91. PROMPT="%(?.%F{magenta}.%F{red})❯%f " # Display a red prompt char on failure
  92. RPROMPT="%F{8}${SSH_TTY:+%n@%m}%f" # Display username if connected via SSH
  93. # ------------------------------------------------------------------------------
  94. #
  95. # List of vcs_info format strings:
  96. #
  97. # %b => current branch
  98. # %a => current action (rebase/merge)
  99. # %s => current version control system
  100. # %r => name of the root directory of the repository
  101. # %S => current path relative to the repository root directory
  102. # %m => in case of Git, show information about stashes
  103. # %u => show unstaged changes in the repository
  104. # %c => show staged changes in the repository
  105. #
  106. # List of prompt format strings:
  107. #
  108. # prompt:
  109. # %F => color dict
  110. # %f => reset color
  111. # %~ => current path
  112. # %* => time
  113. # %n => username
  114. # %m => shortname host
  115. # %(?..) => prompt conditional - %(condition.true.false)
  116. #
  117. # ------------------------------------------------------------------------------