fish_prompt_i_liked.fish 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. function fish_prompt
  2. # - green lines if the last return command is OK, red otherwise
  3. # - your user name, in red if root or yellow otherwise
  4. # - your hostname, in cyan if ssh or blue otherwise
  5. # - the current path (with prompt_pwd)
  6. # - date +%X
  7. # - the current virtual environment, if any
  8. # - the current git status, if any, with __fish_git_prompt
  9. # - the current battery state, if any, and if your power cable is unplugged, and if you have "acpi"
  10. # - current background jobs, if any
  11. # It goes from:
  12. # ┬─[nim@Hattori:~]─[11:39:00]
  13. # ╰─>$ echo here
  14. # To:
  15. # ┬─[nim@Hattori:~/w/dashboard]─[11:37:14]─[V:django20]─[G:master↑1|●1✚1…1]─[B:85%, 05:41:42 remaining]
  16. # │ 2 15054 0% arrêtée sleep 100000
  17. # │ 1 15048 0% arrêtée sleep 100000
  18. # ╰─>$ echo there
  19. set -q __fish_git_prompt_showupstream
  20. or set -g __fish_git_prompt_showupstream auto
  21. function _nim_prompt_wrapper
  22. set retc $argv[1]
  23. set field_name $argv[2]
  24. set field_value $argv[3]
  25. set_color normal
  26. set_color $retc
  27. echo -n '─'
  28. set_color -o green
  29. echo -n '['
  30. set_color normal
  31. test -n $field_name
  32. and echo -n $field_name:
  33. set_color $retc
  34. echo -n $field_value
  35. set_color -o green
  36. echo -n ']'
  37. end
  38. and set retc green
  39. or set retc red
  40. set_color $retc
  41. echo -n '┬─'
  42. set_color -o green
  43. echo -n [
  44. if test "$USER" = root -o "$USER" = toor
  45. set_color -o red
  46. else
  47. set_color -o yellow
  48. end
  49. echo -n $USER
  50. set_color -o white
  51. echo -n @
  52. if [ -z "$SSH_CLIENT" ]
  53. set_color -o blue
  54. else
  55. set_color -o cyan
  56. end
  57. echo -n (prompt_hostname)
  58. set_color -o white
  59. echo -n :(prompt_pwd)
  60. set_color -o green
  61. echo -n ']'
  62. # Date
  63. _nim_prompt_wrapper $retc '' (date +%X)
  64. # Virtual Environment
  65. set -q VIRTUAL_ENV
  66. and _nim_prompt_wrapper $retc V (basename "$VIRTUAL_ENV")
  67. # git
  68. set prompt_git (__fish_git_prompt | string trim -c ' ()')
  69. test -n "$prompt_git"
  70. and _nim_prompt_wrapper $retc G $prompt_git
  71. # Battery status
  72. type -q acpi
  73. and test (acpi -a 2> /dev/null | string match -r off)
  74. and _nim_prompt_wrapper $retc B (acpi -b | cut -d' ' -f 4-)
  75. # New line
  76. echo
  77. # Background jobs
  78. set_color normal
  79. for job in (jobs)
  80. set_color $retc
  81. echo -n '│ '
  82. set_color brown
  83. echo $job
  84. end
  85. set_color normal
  86. set_color $retc
  87. echo -n '╰─>'
  88. set_color -o red
  89. echo -n '$ '
  90. set_color normal
  91. end