fish_right_prompt.fish 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. # You can override some default right prompt options in your config.fish:
  2. # set -g theme_date_format "+%a %H:%M"
  3. function __bobthefish_cmd_duration -S -d 'Show command duration'
  4. [ "$theme_display_cmd_duration" = "no" ]; and return
  5. [ -z "$CMD_DURATION" -o "$CMD_DURATION" -lt 100 ]; and return
  6. if [ "$CMD_DURATION" -lt 5000 ]
  7. echo -ns $CMD_DURATION 'ms'
  8. else if [ "$CMD_DURATION" -lt 60000 ]
  9. __bobthefish_pretty_ms $CMD_DURATION s
  10. else if [ "$CMD_DURATION" -lt 3600000 ]
  11. set_color $fish_color_error
  12. __bobthefish_pretty_ms $CMD_DURATION m
  13. else
  14. set_color $fish_color_error
  15. __bobthefish_pretty_ms $CMD_DURATION h
  16. end
  17. set_color $fish_color_normal
  18. set_color $fish_color_autosuggestion
  19. [ "$theme_display_date" = "no" ]
  20. or echo -ns ' ' $__bobthefish_left_arrow_glyph
  21. end
  22. function __bobthefish_pretty_ms -S -a ms interval -d 'Millisecond formatting for humans'
  23. set -l interval_ms
  24. set -l scale 1
  25. switch $interval
  26. case s
  27. set interval_ms 1000
  28. case m
  29. set interval_ms 60000
  30. case h
  31. set interval_ms 3600000
  32. set scale 2
  33. end
  34. switch $FISH_VERSION
  35. # Fish 2.3 and lower doesn't know about the -s argument to math.
  36. case 2.0.\* 2.1.\* 2.2.\* 2.3.\*
  37. math "scale=$scale;$ms/$interval_ms" | string replace -r '\\.?0*$' $interval
  38. case \*
  39. math -s$scale "$ms/$interval_ms" | string replace -r '\\.?0*$' $interval
  40. end
  41. end
  42. function __bobthefish_timestamp -S -d 'Show the current timestamp'
  43. [ "$theme_display_date" = "no" ]; and return
  44. set -q theme_date_format
  45. or set -l theme_date_format "+%c"
  46. echo -n ' '
  47. date $theme_date_format
  48. end
  49. function fish_right_prompt -d 'bobthefish is all about the right prompt'
  50. set -l __bobthefish_left_arrow_glyph \uE0B3
  51. if [ "$theme_powerline_fonts" = "no" ]
  52. set __bobthefish_left_arrow_glyph '<'
  53. end
  54. set_color $fish_color_autosuggestion
  55. __bobthefish_cmd_duration
  56. __bobthefish_timestamp
  57. set_color normal
  58. end