Advertisement
Guest User

Untitled

a guest
Dec 8th, 2021
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.75 KB | None | 0 0
  1. # Set these options in your config.fish (if you want to :])
  2. #
  3. # set -g theme_display_user yes
  4. # set -g theme_hostname never
  5. # set -g theme_hostname always
  6. # set -g default_user your_normal_user
  7.  
  8.  
  9.  
  10. # Backward compatibility
  11. #
  12. # Note: Do not depend on these behavior. These can be removed in anytime by the
  13. # author in the name of code readability.
  14. if set -q theme_hide_hostname
  15. # Existing $theme_hostname will always override $theme_hide_hostname
  16. if not set -q theme_hostname
  17. if [ "theme_hide_hostname" = "yes" ]
  18. set -g theme_hostname never
  19. end
  20. if [ "theme_hide_hostname" = "no" ]
  21. set -g theme_hostname always
  22. end
  23. end
  24. end
  25.  
  26.  
  27. #
  28. # Segments functions
  29. #
  30. set -g current_bg NONE
  31. set -g segment_separator \uE0B0
  32.  
  33. function prompt_segment -d "Function to draw a segment"
  34. set -l bg
  35. set -l fg
  36. if [ -n "$argv[1]" ]
  37. set bg $argv[1]
  38. else
  39. set bg normal
  40. end
  41. if [ -n "$argv[2]" ]
  42. set fg $argv[2]
  43. else
  44. set fg normal
  45. end
  46. if [ "$current_bg" != 'NONE' -a "$argv[1]" != "$current_bg" ]
  47. set_color -b $bg
  48. set_color $current_bg
  49. echo -n "$segment_separator "
  50. set_color -b $bg
  51. set_color $fg
  52. else
  53. set_color -b $bg
  54. set_color $fg
  55. echo -n " "
  56. end
  57. set current_bg $argv[1]
  58. if [ -n "$argv[3]" ]
  59. echo -n -s $argv[3] " "
  60. end
  61. end
  62.  
  63. function prompt_finish -d "Close open segments"
  64. if [ -n $current_bg ]
  65. set_color -b normal
  66. set_color $current_bg
  67. echo -n "$segment_separator "
  68. end
  69. set_color normal
  70. set -g current_bg NONE
  71. end
  72.  
  73.  
  74. #
  75. # Components
  76. #
  77. function prompt_virtual_env -d "Display Python virtual environment"
  78. if test "$VIRTUAL_ENV"
  79. prompt_segment white black (basename $VIRTUAL_ENV)
  80. end
  81. end
  82.  
  83.  
  84. function prompt_user -d "Display current user if different from $default_user"
  85. set -l BG 444444
  86. set -l FG BCBCBC
  87.  
  88. if [ "$theme_display_user" = "yes" ]
  89. if [ "$USER" != "$default_user" -o -n "$SSH_CLIENT" ]
  90. set USER (whoami)
  91. get_hostname
  92. if [ $HOSTNAME_PROMPT ]
  93. set USER_PROMPT $USER@$HOSTNAME_PROMPT
  94. else
  95. set USER_PROMPT $USER
  96. end
  97. prompt_segment $BG $FG $USER_PROMPT
  98. end
  99. else
  100. get_hostname
  101. if [ $HOSTNAME_PROMPT ]
  102. prompt_segment $BG $FG $HOSTNAME_PROMPT
  103. end
  104. end
  105. end
  106.  
  107. function get_hostname -d "Set current hostname to prompt variable $HOSTNAME_PROMPT if connected via SSH"
  108. set -g HOSTNAME_PROMPT ""
  109. if [ "$theme_hostname" = "always" -o \( "$theme_hostname" != "never" -a -n "$SSH_CLIENT" \) ]
  110. set -g HOSTNAME_PROMPT (hostname)
  111. end
  112. end
  113.  
  114.  
  115. function prompt_dir -d "Display the current directory"
  116. prompt_segment 1C1C1C FFFFFF (prompt_pwd)
  117. end
  118.  
  119.  
  120. function prompt_hg -d "Display mercurial state"
  121. set -l branch
  122. set -l state
  123. if command hg id >/dev/null 2>&1
  124. if command hg prompt >/dev/null 2>&1
  125. set branch (command hg prompt "{branch}")
  126. set state (command hg prompt "{status}")
  127. set branch_symbol \uE0A0
  128. if [ "$state" = "!" ]
  129. prompt_segment red white "$branch_symbol $branch ±"
  130. else if [ "$state" = "?" ]
  131. prompt_segment yellow black "$branch_symbol $branch ±"
  132. else
  133. prompt_segment green black "$branch_symbol $branch"
  134. end
  135. end
  136. end
  137. end
  138.  
  139.  
  140. function prompt_git -d "Display the current git state"
  141. set -l ref
  142. if command git rev-parse --is-inside-work-tree >/dev/null 2>&1
  143. set ref (command git symbolic-ref HEAD 2> /dev/null)
  144. if [ $status -gt 0 ]
  145. set -l branch (command git show-ref --head -s --abbrev |head -n1 2> /dev/null)
  146. set ref "➦ $branch "
  147. end
  148. set branch_symbol \uE0A0
  149. set -l branch (echo $ref | sed "s-refs/heads/-$branch_symbol -")
  150.  
  151. set -l BG PROMPT
  152. set -l dirty (command git status --porcelain --ignore-submodules=dirty 2> /dev/null)
  153. if [ "$dirty" = "" ]
  154. set BG green
  155. set PROMPT "$branch"
  156. else
  157. set BG yellow
  158. set dirty ''
  159.  
  160. # Check if there's any commit in the repo
  161. set -l empty 0
  162. git rev-parse --quiet --verify HEAD > /dev/null 2>&1; or set empty 1
  163.  
  164. set -l target
  165. if [ $empty = 1 ]
  166. # The repo is empty
  167. set target '4b825dc642cb6eb9a060e54bf8d69288fbee4904'
  168. else
  169. # The repo is not emtpy
  170. set target 'HEAD'
  171.  
  172. # Check for unstaged change only when the repo is not empty
  173. set -l unstaged 0
  174. git diff --no-ext-diff --ignore-submodules=dirty --quiet --exit-code; or set unstaged 1
  175. if [ $unstaged = 1 ]; set dirty $dirty'●'; end
  176. end
  177.  
  178. # Check for staged change
  179. set -l staged 0
  180. git diff-index --cached --quiet --exit-code --ignore-submodules=dirty $target; or set staged 1
  181. if [ $staged = 1 ]; set dirty $dirty'✚'; end
  182.  
  183. # Check for dirty
  184. if [ "$dirty" = "" ]
  185. set PROMPT "$branch"
  186. else
  187. set PROMPT "$branch $dirty"
  188. end
  189. end
  190. prompt_segment $BG black $PROMPT
  191. end
  192. end
  193.  
  194.  
  195. function prompt_svn -d "Display the current svn state"
  196. set -l ref
  197. if command svn ls . >/dev/null 2>&1
  198. set branch (svn_get_branch)
  199. set branch_symbol \uE0A0
  200. set revision (svn_get_revision)
  201. prompt_segment green black "$branch_symbol $branch:$revision"
  202. end
  203. end
  204.  
  205. function svn_get_branch -d "get the current branch name"
  206. svn info 2> /dev/null | awk -F/ \
  207. '/^URL:/ { \
  208. for (i=0; i<=NF; i++) { \
  209. if ($i == "branches" || $i == "tags" ) { \
  210. print $(i+1); \
  211. break;\
  212. }; \
  213. if ($i == "trunk") { print $i; break; } \
  214. } \
  215. }'
  216. end
  217.  
  218. function svn_get_revision -d "get the current revision number"
  219. svn info 2> /dev/null | sed -n 's/Revision:\ //p'
  220. end
  221.  
  222.  
  223. function prompt_status -d "the symbols for a non zero exit status, root and background jobs"
  224. if [ $RETVAL -ne 0 ]
  225. prompt_segment black red "✘"
  226. end
  227.  
  228. # if superuser (uid == 0)
  229. set -l uid (id -u $USER)
  230. if [ $uid -eq 0 ]
  231. prompt_segment black yellow "⚡"
  232. end
  233.  
  234. # Jobs display
  235. if [ (jobs -l | wc -l) -gt 0 ]
  236. prompt_segment black cyan "⚙"
  237. end
  238. end
  239.  
  240. if printf '%s\n' '2.2.0' $FISH_VERSION | sort --check=silent --version-sort
  241. # Current version ≥ 2.2.0
  242. function __exists -a name -d "Check if a function or program does exist."
  243. command -v "$name" ^/dev/null >&2
  244. end
  245. else
  246. # Current version < 2.2.0
  247. function __exists -a name -d "Check if a function or program does exist."
  248. type "$name" ^/dev/null >&2
  249. end
  250. end
  251.  
  252.  
  253. #
  254. # Prompt
  255. #
  256. function fish_prompt
  257. set -g RETVAL $status
  258. prompt_status
  259. prompt_virtual_env
  260. prompt_user
  261. prompt_dir
  262. __exists hg; and prompt_hg
  263. __exists git; and prompt_git
  264. __exists svn; and prompt_svn
  265. prompt_finish
  266. end
  267.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement