fish_prompt.fish 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. # Status Chars
  2. set __fish_git_prompt_char_dirtystate '!'
  3. set __fish_git_prompt_char_untrackedfiles '☡'
  4. set __fish_git_prompt_char_stashstate '↩'
  5. set __fish_git_prompt_char_cleanstate '✓'
  6. # Display the state of the branch when inside of a git repo
  7. function __simple_ass_prompt_parse_git_branch_state -d "Display the state of the branch"
  8. git update-index --really-refresh -q 1> /dev/null
  9. # Check for changes to be commited
  10. if git_is_touched
  11. echo -n "$__fish_git_prompt_char_dirtystate"
  12. else
  13. echo -n "$__fish_git_prompt_char_cleanstate"
  14. end
  15. # Check for untracked files
  16. set -l git_untracked (command git ls-files --others --exclude-standard 2> /dev/null)
  17. if [ -n "$git_untracked" ]
  18. echo -n "$__fish_git_prompt_char_untrackedfiles"
  19. end
  20. # Check for stashed files
  21. if git_is_stashed
  22. echo -n "$__fish_git_prompt_char_stashstate"
  23. end
  24. # Check if branch is ahead, behind or diverged of remote
  25. git_ahead
  26. end
  27. # Display current git branch
  28. function __simple_ass_prompt_git -d "Display the actual git branch"
  29. set -l ref
  30. set -l std_prompt (prompt_pwd)
  31. set -l is_dot_git (string match '*/.git' $std_prompt)
  32. if git_is_repo; and test -z $is_dot_git
  33. printf 'on '
  34. set_color purple
  35. set -l git_branch (command git symbolic-ref --quiet --short HEAD 2> /dev/null; or git rev-parse --short HEAD 2> /dev/null; or echo -n '(unknown)')
  36. printf '%s ' $git_branch
  37. set state (__simple_ass_prompt_parse_git_branch_state)
  38. set_color 0087ff
  39. printf '[%s]' $state
  40. set_color normal
  41. end
  42. end
  43. # Print current user
  44. function __simple_ass_prompt_get_user -d "Print the user"
  45. if test $USER = 'root'
  46. set_color red
  47. else
  48. set_color d75f00
  49. end
  50. printf '%s' (whoami)
  51. end
  52. # Get Machines Hostname
  53. function __simple_ass_prompt_get_host -d "Get Hostname"
  54. if test $SSH_TTY
  55. tput bold
  56. set_color red
  57. else
  58. set_color af8700
  59. end
  60. printf '%s' (hostname|cut -d . -f 1)
  61. end
  62. # Get Project Working Directory
  63. function __simple_ass_prompt_pwd -d "Get PWD"
  64. set_color $fish_color_cwd
  65. printf '%s ' (prompt_pwd)
  66. end
  67. # Simple-ass-prompt
  68. function fish_prompt
  69. set -l code $status
  70. # Logged in user
  71. __simple_ass_prompt_get_user
  72. set_color normal
  73. printf ' at '
  74. # Machine logged in to
  75. __simple_ass_prompt_get_host
  76. set_color normal
  77. printf ' in '
  78. # Path
  79. __simple_ass_prompt_pwd
  80. set_color normal
  81. # Git info
  82. __simple_ass_prompt_git
  83. # Line 2
  84. echo
  85. if test -e "Cargo.toml"
  86. printf "(rust:%s) " (set_color red)(rustup show | tail -n 3 | head -n 1 | cut -d '-' -f 1)(set_color normal)
  87. end
  88. if test $VIRTUAL_ENV
  89. printf "(python:%s) " (set_color blue)(basename $VIRTUAL_ENV)(set_color normal)
  90. end
  91. if test $code -eq 127
  92. set_color red
  93. end
  94. printf '↪ '
  95. set_color normal
  96. end