# # Segments functions # set -g current_bg NONE set -g segment_separator_right \uE0B2 function prompt_segment_right -d "Function to draw a segment" set -l bg set -l fg if [ -n "$argv[1]" ] set bg $argv[1] else set bg normal end if [ -n "$argv[2]" ] set fg $argv[2] else set fg normal end if [ -z "$argv[3]" ] return end set_color $bg echo -n " $segment_separator_right" set_color -b $bg set_color $fg echo -n " $argv[3]" set -g current_bg $bg end function git_status_summary_right -d "Deal with git status --porcelain" awk ' BEGIN { untracked=0; unstaged=0; staged=0; ahead=0; behind=0; } { if (!after_first && $0 ~ /^##.+/) { if ( match($0, /ahead ([1-9]+)/) ) { split(substr($0, RSTART, RLENGTH), A); ahead=A[2]; } if ( match($0, /behind ([1-9]+)/) ) { split(substr($0, RSTART, RLENGTH), A); behind=A[2]; } } else if ($0 ~ /^\?\? .+/) { untracked += 1 } else { if ($0 ~ /^.[^ ] .+/) { unstaged += 1 } if ($0 ~ /^[^ ]. .+/) { staged += 1 } } after_first = 1 } END { if (!seen_header) { } print ahead ";" behind ";" untracked ";" unstaged ";" staged }' end function prompt_git_right -d "Display the current git state" set -l ref if [ -e .git ] set dirty '' set gstatus ( git status --porcelain -b | git_status_summary_right ) # Check for commit ahead set ahead (echo $gstatus | cut -d ';' -f 1) # Check for commit behind set behind (echo $gstatus | cut -d ';' -f 2) # Check for modified files set unstdg (echo $gstatus | cut -d ';' -f 3) # Check for untracked files set untrkd (echo $gstatus | cut -d ';' -f 4) # Check for staged files set staged (echo $gstatus | cut -d ';' -f 5) if [ $ahead -gt 0 ] set dirty $dirty' ↑:'$ahead end if [ $behind -gt 0 ] set dirty $dirty' ↓:'$behind end if [ $untrkd -gt 0 ] set dirty $dirty' U:'$untrkd end if [ $unstdg -gt 0 ] set dirty $dirty' ?:'$unstdg end if [ $staged -gt 0 ] set dirty $dirty' S:'$staged end if [ $staged -eq 0 -a $untrkd -eq 0 ] set BG green set PROMPT "$dirty" else set BG yellow # Check if there's any commit in the repo set -l empty 0 git rev-parse --quiet --verify HEAD > /dev/null 2>&1; or set empty 1 set -l target if [ $empty = 1 ] # The repo is empty set dirty '' set target '4b825dc642cb6eb9a060e54bf8d69288fbee4904' else # The repo is not emtpy set target 'HEAD' end # Check for dirty if [ "$dirty" != "" ] set PROMPT "$dirty" end end prompt_segment_right $BG black $PROMPT end end function prompt_shlv_right -d "Display level shell" set pline '' if [ "$VIMRUNTIME" != "" ] set pline 'vim' if [ "$SHLVL" -gt 3 ] set pline 'vim:['$SHLVL']' end else if [ "$SHLVL" -gt 2 ] set pline '['$SHLVL']' end end if [ $pline != '' ] prompt_segment_right 8C8C8C black "$pline" end end function prompt_todo_right -d "Display todo" if which todo 2> /dev/null > /dev/null set all (todo | wc -l) set chkd (todo checked | wc -l) set td (math "$all-$chkd") if [ $all -gt 0 ] prompt_segment_right 5C5C5C blue "$td/$all" end end end function prompt_status_right -d "the symbols for a non zero exit status, root and background jobs" if [ $RETVAL -ne 0 ] prompt_segment_right black red "✘" end # if superuser (uid == 0) set -l uid (id -u $USER) if [ $uid -eq 0 ] prompt_segment_right black yellow "⚡" end # Jobs display if [ (jobs -l | wc -l) -gt 0 ] prompt_segment_right black cyan "⚙" end end function prompt_finish_right -d "Close open segments" if [ -n $current_bg ] set_color -b normal end set -g current_bg NONE end function available -a name -d "Check if a function or program is available." type "$name" 2>/dev/null >&2 end # # Right prompt # function fish_right_prompt set -g RETVAL $status # prompt_status_right # available git; and prompt_git_right # prompt_todo_right # prompt_shlv_right # prompt_finish_right end