fork/fish-shell
git clone https://git.julia.blue/fork/fish-shell
867946468
master
1# name: Scales 2# author: Leonard Hecker <leonard@hecker.io> 3 4# Sources: 5# - General theme setup: https://github.com/sorin-ionescu/prezto/blob/d275f316ffdd0bbd075afbff677c3e00791fba16/modules/prompt/functions/prompt_sorin_setup 6# - Extraction of git info: https://github.com/sorin-ionescu/prezto/blob/d275f316ffdd0bbd075afbff677c3e00791fba16/modules/git/functions/git-info#L180-L441 7 8function fish_prompt 9if test -n " $SSH_TTY " 10echo -n( set_color brred) " $USER " ( set_color white) '@' ( set_color yellow)( prompt_hostname ) ' ' 11end 12 13echo -n( set_color blue)( prompt_pwd ) ' ' 14 15set_color -o 16if fish_is_root_user 17echo -n( set_color red) '# ' 18end 19echo -n( set_color red) '❯' ( set_color yellow) '❯' ( set_color green) '❯ ' 20set_color --reset 21end 22 23# And now define the right prompt so that it's brought along 24function fish_right_prompt 25set -l cmd_status$status 26if test $cmd_status -ne 0 27echo -n( set_color red) "✘ $cmd_status " 28end 29 30if not command -sq git 31set_color --reset 32return 33end 34 35# Get the git directory for later use. 36# Return if not inside a Git repository work tree. 37if not set -l git_dir( command git rev-parse --git-dir2> /dev/null) 38set_color --reset 39return 40end 41 42# Get the current action ("merge", "rebase", etc.) 43# and if there's one get the current commit hash too. 44set -l commit'' 45if set -l action( fish_print_git_action " $git_dir " ) 46set commit( command git rev-parse HEAD2> /dev/null| string sub -l7 ) 47end 48 49# Get either the branch name or a branch descriptor. 50set -l branch_detached0 51if not set -l branch( command git symbolic-ref --short HEAD2> /dev/null) 52set branch_detached1 53set branch( command git describe --contains --all HEAD2> /dev/null) 54end 55 56# Get the commit difference counts between local and remote. 57command git rev-list --count --left-right'HEAD...@{upstream}' 2> /dev/null\ 58| read -d\t -l status_ahead status_behind 59if test $status -ne 0 60set status_ahead0 61set status_behind0 62end 63 64# Get the stash status. 65# (git stash list) is very slow. => Avoid using it. 66set -l status_stashed0 67if test -f " $git_dir /refs/stash" 68set status_stashed1 69else if test -r " $git_dir /commondir" 70read -l commondir< " $git_dir /commondir" 71if test -f " $commondir /refs/stash" 72set status_stashed1 73end 74end 75 76# git-status' porcelain v1 format starts with 2 letters on each line: 77# The first letter (X) denotes the index state. 78# The second letter (Y) denotes the working directory state. 79# 80# The following table presents the possible combinations: 81# * The underscore character denotes whitespace. 82# * The cell values stand for the following file states: 83# a: added 84# d: deleted 85# m: modified 86# r: renamed 87# u: unmerged 88# t: untracked 89# * Cells with more than one letter signify that both states 90# are simultaneously the case. This is possible since the git index 91# and working directory operate independently of each other. 92# * Cells which are empty are unhandled by this code. 93# * T (= type change) is undocumented. 94# See Git v1.7.8.2 release notes for more information. 95# 96# \ Y→ 97# X \ 98# ↓ | A | C | D | M | R | T | U | X | B | ? | _ 99# ----+----+----+----+----+----+----+----+----+----+----+---- 100# A | u | | ad | am | r | am | u | | | | a 101# C | | | ad | am | r | am | u | | | | a 102# D | | | u | am | r | am | u | | | | a 103# M | | | ad | am | r | am | u | | | | a 104# R | r | r | rd | rm | r | rm | ur | r | r | r | r 105# T | | | ad | am | r | am | u | | | | a 106# U | u | u | u | um | ur | um | u | u | u | u | u 107# X | | | | m | r | m | u | | | | 108# B | | | | m | r | m | u | | | | 109# ? | | | | m | r | m | u | | | t | 110# _ | | | d | m | r | m | u | | | | 111set -l porcelain_status( command git status --porcelain2> /dev/null| string sub -l2) 112 113set -l status_added0 114if string match -qr'[ACDMT][ MT]|[ACMT]D' $porcelain_status 115set status_added1 116end 117set -l status_deleted0 118if string match -qr'[ ACMRT]D' $porcelain_status 119set status_deleted1 120end 121set -l status_modified0 122if string match -qr'[MT]$' $porcelain_status 123set status_modified1 124end 125set -l status_renamed0 126if string match -qe R$porcelain_status 127set status_renamed1 128end 129set -l status_unmerged0 130if string match -qr'AA|DD|U' $porcelain_status 131set status_unmerged1 132end 133set -l status_untracked0 134if string match -qe'\?\?' $porcelain_status 135set status_untracked1 136end 137 138set_color -o 139 140if test -n " $branch " 141if test $branch_detached -ne 0 142set_color brmagenta 143else 144set_color green 145end 146echo -n" $branch " 147end 148if test -n " $commit " 149echo -n' ' ( set_color yellow) " $commit " 150end 151if test -n " $action " 152set_color --reset 153echo -n( set_color white) ':' ( set_color -o brred) " $action " 154end 155if test $status_ahead -ne 0 156echo -n' ' ( set_color brmagenta) '⬆' 157end 158if test $status_behind -ne 0 159echo -n' ' ( set_color brmagenta) '⬇' 160end 161if test $status_stashed -ne 0 162echo -n' ' ( set_color cyan) '✭' 163end 164if test $status_added -ne 0 165echo -n' ' ( set_color green) '✚' 166end 167if test $status_deleted -ne 0 168echo -n' ' ( set_color red) '✖' 169end 170if test $status_modified -ne 0 171echo -n' ' ( set_color blue) '✱' 172end 173if test $status_renamed -ne 0 174echo -n' ' ( set_color magenta) '➜' 175end 176if test $status_unmerged -ne 0 177echo -n' ' ( set_color yellow) '═' 178end 179if test $status_untracked -ne 0 180echo -n' ' ( set_color white) '◼' 181end 182 183set_color --reset 184end