Advertisement
Trambelus

fish_prompt.fish

Feb 19th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.57 KB | None | 0 0
  1. function _common_section
  2. printf $c1
  3. printf $argv[1]
  4. printf $c0
  5. printf ":"
  6. printf $c2
  7. printf $argv[2]
  8. printf $argv[3]
  9. printf $c0
  10. printf ", "
  11. end
  12.  
  13. function section
  14. _common_section $argv[1] $c3 $argv[2] $ce
  15. end
  16.  
  17. function error
  18. _common_section $argv[1] $ce $argv[2] $ce
  19. end
  20.  
  21. function git_branch
  22. set -g git_branch (git rev-parse --abbrev-ref HEAD ^ /dev/null)
  23. if [ $status -ne 0 ]
  24. set -ge git_branch
  25. set -g git_dirty_count 0
  26. else
  27. set -g git_dirty_count (git status -s | grep -v \?\? | wc -l | sed "s/ //g")
  28. end
  29. end
  30.  
  31. function fish_prompt
  32. # $status gets nuked as soon as something else is run, e.g. set_color
  33. # so it has to be saved asap.
  34. set -l last_status $status
  35.  
  36. # c0 to c4 progress from dark to bright
  37. # ce is the error colour
  38. # set -g c0 (set_color 005284)
  39. # set -g c1 (set_color 0075cd)
  40. # set -g c2 (set_color 009eff)
  41. # set -g c3 (set_color 6dc7ff)
  42. # set -g c4 (set_color ffffff)
  43. set -g c0 (set_color 008800)
  44. set -g c1 (set_color 444400)
  45. set -g c2 (set_color 880000)
  46. set -g c3 (set_color 008888)
  47. set -g c4 (set_color 222222)
  48. set -g ce (set_color $fish_color_error)
  49.  
  50. # Clear the line because fish seems to emit the prompt twice. The initial
  51. # display, then when you press enter.
  52. printf "\033[K"
  53.  
  54. # Current time
  55. printf (date "+$c2%H$c0:$c2%M$c0:$c2%S, ")
  56. if [ $last_status -ne 0 ]
  57. error last $last_status
  58. set -ge status
  59. end
  60.  
  61. # Track the last non-empty command. It's a bit of a hack to make sure
  62. # execution time and last command is tracked correctly.
  63. # set -l cmd_line (commandline)
  64. # if test -n "$cmd_line"
  65. # set -g last_cmd_line $cmd_line
  66. # set -ge new_prompt
  67. # else
  68. # set -g new_prompt true
  69. # end
  70.  
  71. # # Show last execution time and growl notify if it took long enough
  72. # set -l now (date +%s)
  73. # if test $last_exec_timestamp
  74. # set -l taken (math $now - $last_exec_timestamp)
  75. # if test $taken -gt 10 -a -n "$new_prompt"
  76. # error taken $taken
  77. # # "/cygdrive/c/Program Files (x86)/Growl for Windows/growlnotify.com" "Returned $last_status, took $taken seconds /t $last_cmd_line"
  78. # # Clear the last_cmd_line so pressing enter doesn't repeat
  79. # set -ge last_cmd_line
  80. # end
  81. # end
  82. # set -g last_exec_timestamp $now
  83.  
  84. # # Show loadavg when too high
  85. # set -l load1m (uptime | grep -o '[0-9]\+\.[0-9]\+' | head -n1)
  86. # set -l load1m_test (math $load1m \* 100 / 1)
  87. # if test $load1m_test -gt 100
  88. # error load $load1m
  89. # end
  90.  
  91. # Show disk usage when low
  92. # set -l du (df / | tail -n1 | sed "s/ */ /g" | cut -d' ' -f 5 | cut -d'%' -f1)
  93. # if test $du -gt 80
  94. # error du $du%%
  95. # end
  96.  
  97. # Virtual Env
  98. # if set -q VIRTUAL_ENV
  99. # section env (basename "$VIRTUAL_ENV")
  100. # end
  101.  
  102. # Git branch and dirty files
  103. git_branch
  104. if set -q git_branch
  105. set out $git_branch
  106. if test $git_dirty_count -gt 0
  107. set out "$out$c0:$ce$git_dirty_count"
  108. end
  109. section git $out
  110. end
  111.  
  112. # Current Directory
  113. # 1st sed for colourising forward slashes
  114. # 2nd sed for colourising the deepest path (the 'm' is the last char in the
  115. # ANSI colour code that needs to be stripped)
  116. printf $c1
  117. printf (pwd | sed "s,/,$c0/$c1,g" | sed "s,\(.*\)/[^m]*m,\1/$c3,")
  118.  
  119. # Prompt on a new line
  120. printf $c4
  121. printf "\n> "
  122. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement