You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
1.7 KiB

2 weeks ago
2 weeks ago
  1. PS1=
  2. RPROMPT=
  3. ZSH_THEME_GIT_PROMPT_PREFIX=""
  4. ZSH_THEME_GIT_PROMPT_SUFFIX=""
  5. ZSH_THEME_GIT_PROMPT_SEPARATOR=" "
  6. ZSH_THEME_DEBLAN_USE_GIT=${ZSH_THEME_DEBLAN_USE_GIT:-1}
  7. function deblan_precmd() {
  8. local exit_code=$?
  9. local datetime="%T"
  10. local current_directory="%~"
  11. local final_char="%%"
  12. local is_privilegied=${(%):-%(\!.1.0)}
  13. local prompt_width=
  14. local prompt_content=
  15. local term_width=
  16. local rprompt_content=
  17. PS1=
  18. RPROMPT=
  19. prompt_content="$(deblan_last_status)"
  20. prompt_content="$prompt_content %{$fg_bold[cyan]%}${datetime}"
  21. if [ $is_privilegied -eq 1 ]; then
  22. prompt_content="$prompt_content %{$fg_bold[red]%}%n@%m"
  23. final_char="%{$fg_bold[red]%}#"
  24. else
  25. prompt_content="$prompt_content %{$fg_bold[white]%}%n@%m"
  26. fi
  27. prompt_content="$prompt_content %{$fg_bold[white]%}$current_directory"
  28. prompt_width="${#${(%):-$prompt_content}}"
  29. term_width=$(tput cols)
  30. if [[ "$prompt_width*1.3" -gt $term_width ]]; then
  31. prompt_content="$prompt_content
  32. "
  33. else
  34. prompt_content="$prompt_content "
  35. fi
  36. prompt_content="$prompt_content%{$fg_bold[yellow]%}$final_char"
  37. prompt_content="$prompt_content %{$reset_color%}"
  38. if [ $ZSH_THEME_DEBLAN_USE_GIT -eq 1 ]; then
  39. if (command -v git_super_status >/dev/null); then
  40. rprompt_content='%{$fg[$NCOLOR]%} $(git_super_status)%{$reset_color%}'
  41. fi
  42. fi
  43. PS1="$prompt_content"
  44. RPROMPT="$rprompt_content"
  45. }
  46. function deblan_last_status() {
  47. local value=
  48. if [ $exit_code -eq 0 ]; then
  49. value="%{$fg_bold[green]%}●"
  50. elif [ $exit_code -eq 1 ]; then
  51. value="%{$fg_bold[red]%}●"
  52. elif [ $exit_code -eq 130 ]; then
  53. value="%{$fg_bold[grey]%}●"
  54. else
  55. value="%{$fg_bold[yellow]%}● [$exit_code]"
  56. fi
  57. echo -n "$value"
  58. }
  59. setopt prompt_subst
  60. autoload -U add-zsh-hook
  61. add-zsh-hook precmd deblan_precmd