gitprompt.fish 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. # name: bash-git-prompt
  2. # author: Mariusz Smykuła <mariuszs@gmail.com>
  3. function fish_prompt
  4. if not set -q __GIT_PROMPT_DIR
  5. set __GIT_PROMPT_DIR ~/.bash-git-prompt
  6. end
  7. # Colors
  8. # Reset
  9. set ResetColor (set_color normal) # Text Reset
  10. # Regular Colors
  11. set Red (set_color red) # Red
  12. set Yellow (set_color yellow); # Yellow
  13. set Blue (set_color blue) # Blue
  14. set WHITE (set_color white)
  15. # Bold
  16. set BGreen (set_color -o green) # Green
  17. # High Intensty
  18. set IBlack (set_color -o black) # Black
  19. # Bold High Intensty
  20. set Magenta (set_color -o purple) # Purple
  21. # Default values for the appearance of the prompt. Configure at will.
  22. set GIT_PROMPT_PREFIX "["
  23. set GIT_PROMPT_SUFFIX "]"
  24. set GIT_PROMPT_SEPARATOR "|"
  25. set GIT_PROMPT_BRANCH "$Magenta"
  26. set GIT_PROMPT_STAGED "$Red● "
  27. set GIT_PROMPT_CONFLICTS "$Red✖ "
  28. set GIT_PROMPT_CHANGED "$Blue✚ "
  29. set GIT_PROMPT_REMOTE " "
  30. set GIT_PROMPT_UNTRACKED "…"
  31. set GIT_PROMPT_STASHED "⚑ "
  32. set GIT_PROMPT_CLEAN "$BGreen✔"
  33. # Various variables you might want for your PS1 prompt instead
  34. set Time (date +%R)
  35. set PathShort (pwd|sed "s=$HOME=~=")
  36. set PROMPT_START "$Yellow$PathShort$ResetColor"
  37. set PROMPT_END " \n$WHITE$Time$ResetColor \$ "
  38. set -e __CURRENT_GIT_STATUS
  39. set gitstatus "$__GIT_PROMPT_DIR/gitstatus.py"
  40. set _GIT_STATUS (python $gitstatus)
  41. set __CURRENT_GIT_STATUS $_GIT_STATUS
  42. set __CURRENT_GIT_STATUS_PARAM_COUNT (count $__CURRENT_GIT_STATUS)
  43. if not test "0" -eq $__CURRENT_GIT_STATUS_PARAM_COUNT
  44. set GIT_BRANCH $__CURRENT_GIT_STATUS[1]
  45. set GIT_REMOTE "$__CURRENT_GIT_STATUS[2]"
  46. if contains "." "$GIT_REMOTE"
  47. set -e GIT_REMOTE
  48. end
  49. set GIT_STAGED $__CURRENT_GIT_STATUS[3]
  50. set GIT_CONFLICTS $__CURRENT_GIT_STATUS[4]
  51. set GIT_CHANGED $__CURRENT_GIT_STATUS[5]
  52. set GIT_UNTRACKED $__CURRENT_GIT_STATUS[6]
  53. set GIT_STASHED $__CURRENT_GIT_STATUS[7]
  54. set GIT_CLEAN $__CURRENT_GIT_STATUS[8]
  55. end
  56. if test -n "$__CURRENT_GIT_STATUS"
  57. set STATUS " $GIT_PROMPT_PREFIX$GIT_PROMPT_BRANCH$GIT_BRANCH$ResetColor"
  58. if set -q GIT_REMOTE
  59. set STATUS "$STATUS$GIT_PROMPT_REMOTE$GIT_REMOTE$ResetColor"
  60. end
  61. set STATUS "$STATUS$GIT_PROMPT_SEPARATOR"
  62. if [ $GIT_STAGED != "0" ]
  63. set STATUS "$STATUS$GIT_PROMPT_STAGED$GIT_STAGED$ResetColor"
  64. end
  65. if [ $GIT_CONFLICTS != "0" ]
  66. set STATUS "$STATUS$GIT_PROMPT_CONFLICTS$GIT_CONFLICTS$ResetColor"
  67. end
  68. if [ $GIT_CHANGED != "0" ]
  69. set STATUS "$STATUS$GIT_PROMPT_CHANGED$GIT_CHANGED$ResetColor"
  70. end
  71. if [ "$GIT_UNTRACKED" != "0" ]
  72. set STATUS "$STATUS$GIT_PROMPT_UNTRACKED$GIT_UNTRACKED$ResetColor"
  73. end
  74. if [ "$GIT_STASHED" != "0" ]
  75. set STATUS "$STATUS$GIT_PROMPT_STASHED$GIT_STASHED$ResetColor"
  76. end
  77. if [ "$GIT_CLEAN" = "1" ]
  78. set STATUS "$STATUS$GIT_PROMPT_CLEAN"
  79. end
  80. set STATUS "$STATUS$ResetColor$GIT_PROMPT_SUFFIX"
  81. set PS1 "$PROMPT_START$STATUS$PROMPT_END"
  82. else
  83. set PS1 "$PROMPT_START$PROMPT_END"
  84. end
  85. echo -e $PS1
  86. end