fish_right_prompt.fish 2.1 KB

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