refined.zsh-theme 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. vcs_info # Get version control info before we start outputting stuff
  65. print -P "\n$(repo_information) %F{yellow}$(cmd_exec_time)%f"
  66. unset cmd_timestamp #Reset cmd exec time.
  67. }
  68. # Define prompts
  69. #
  70. PROMPT="%(?.%F{magenta}.%F{red})❯%f " # Display a red prompt char on failure
  71. RPROMPT="%F{8}${SSH_TTY:+%n@%m}%f" # Display username if connected via SSH
  72. # ------------------------------------------------------------------------------
  73. #
  74. # List of vcs_info format strings:
  75. #
  76. # %b => current branch
  77. # %a => current action (rebase/merge)
  78. # %s => current version control system
  79. # %r => name of the root directory of the repository
  80. # %S => current path relative to the repository root directory
  81. # %m => in case of Git, show information about stashes
  82. # %u => show unstaged changes in the repository
  83. # %c => show staged changes in the repository
  84. #
  85. # List of prompt format strings:
  86. #
  87. # prompt:
  88. # %F => color dict
  89. # %f => reset color
  90. # %~ => current path
  91. # %* => time
  92. # %n => username
  93. # %m => shortname host
  94. # %(?..) => prompt conditional - %(condition.true.false)
  95. #
  96. # ------------------------------------------------------------------------------