refined.zsh-theme 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. # ------------------------------------------------------------------------------
  21. # Set required options
  22. #
  23. setopt prompt_subst
  24. # Load required modules
  25. #
  26. autoload -Uz vcs_info
  27. # Set vcs_info parameters
  28. #
  29. zstyle ':vcs_info:*' enable hg bzr git
  30. zstyle ':vcs_info:*:*' unstagedstr '!'
  31. zstyle ':vcs_info:*:*' stagedstr '+'
  32. zstyle ':vcs_info:*:*' formats "$FX[bold]%r$FX[no-bold]/%S" "%s:%b" "%%u%c"
  33. zstyle ':vcs_info:*:*' actionformats "$FX[bold]%r$FX[no-bold]/%S" "%s:%b" "%u%c (%a)"
  34. zstyle ':vcs_info:*:*' nvcsformats "%~" "" ""
  35. # Fastest possible way to check if repo is dirty
  36. #
  37. git_dirty() {
  38. # Check if we're in a git repo
  39. command git rev-parse --is-inside-work-tree &>/dev/null || return
  40. # Check if it's dirty
  41. command git diff --quiet --ignore-submodules HEAD &>/dev/null; [ $? -eq 1 ] && echo "*"
  42. }
  43. # Display information about the current repository
  44. #
  45. repo_information() {
  46. echo "%F{blue}${vcs_info_msg_0_%%/.} %F{8}$vcs_info_msg_1_`git_dirty` $vcs_info_msg_2_%f"
  47. }
  48. # Displays the exec time of the last command if set threshold was exceeded
  49. #
  50. cmd_exec_time() {
  51. local stop=`date +%s`
  52. local start=${cmd_timestamp:-$stop}
  53. let local elapsed=$stop-$start
  54. [ $elapsed -gt 5 ] && echo ${elapsed}s
  55. }
  56. # Get the initial timestamp for cmd_exec_time
  57. #
  58. preexec() {
  59. cmd_timestamp=`date +%s`
  60. }
  61. # Output additional information about paths, repos and exec time
  62. #
  63. precmd() {
  64. setopt localoptions nopromptsubst
  65. vcs_info # Get version control info before we start outputting stuff
  66. print -P "\n$(repo_information) %F{yellow}$(cmd_exec_time)%f"
  67. unset cmd_timestamp #Reset cmd exec time.
  68. }
  69. # Define prompts
  70. #
  71. PROMPT="%(?.%F{magenta}.%F{red})❯%f " # Display a red prompt char on failure
  72. RPROMPT="%F{8}${SSH_TTY:+%n@%m}%f" # Display username if connected via SSH
  73. # ------------------------------------------------------------------------------
  74. #
  75. # List of vcs_info format strings:
  76. #
  77. # %b => current branch
  78. # %a => current action (rebase/merge)
  79. # %s => current version control system
  80. # %r => name of the root directory of the repository
  81. # %S => current path relative to the repository root directory
  82. # %m => in case of Git, show information about stashes
  83. # %u => show unstaged changes in the repository
  84. # %c => show staged changes in the repository
  85. #
  86. # List of prompt format strings:
  87. #
  88. # prompt:
  89. # %F => color dict
  90. # %f => reset color
  91. # %~ => current path
  92. # %* => time
  93. # %n => username
  94. # %m => shortname host
  95. # %(?..) => prompt conditional - %(condition.true.false)
  96. #
  97. # ------------------------------------------------------------------------------