fork/fish-shell
git clone https://git.julia.blue/fork/fish-shell
867946468
master
1# name: Disco 2# author: Fabian Homborg 3 4function fish_prompt 5set -l last_status$status 6 7set -l normal( set_color --reset) 8set -l usercolor( set_color $fish_color_user ) 9 10set -l delim\U25BA 11 12fish_is_root_user ;and set delim"#" 13 14set -l cwd( set_color $fish_color_cwd ) 15if command -sq cksum 16# randomized cwd color 17# We hash the physical PWD and turn that into a color. That means directories (usually) get different colors, 18# but every directory always gets the same color. It's deterministic. 19# We use cksum because 1. it's fast, 2. it's in POSIX, so it should be available everywhere. 20set -l shas( pwd -P| cksum | string split -f1' ' | math --base=hex| string sub -s3 | string pad -c0 -w6 | string match -ra ..) 21set -l col 0x$shas [ 1 .. 3 ] 22 23# If the (simplified idea of) luminance is below 120 (out of 255), add some more. 24# (this runs at most twice because we add 60) 25while test ( math 0.2126 x$col [ 1 ] +0.7152 x$col [ 2 ] +0.0722 x$col [ 3 ]) -lt 120 26set col[ 1 ] ( math --base=hex"min(255, $col [ 1 ] + 60)" ) 27set col[ 2 ] ( math --base=hex"min(255, $col [ 2 ] + 60)" ) 28set col[ 3 ] ( math --base=hex"min(255, $col [ 3 ] + 60)" ) 29end 30set -l col( string replace 0x'' $col | string pad -c0 -w2 | string join"" ) 31 32set cwd( set_color $col ) 33end 34 35# Prompt status only if it's not 0 36set -l prompt_status 37test $last_status -ne 0 ;and set prompt_status( set_color $fish_color_status ) "[ $last_status ] $normal " 38 39# Only show host if in SSH or container 40# Store this in a global variable because it's slow and unchanging 41if not set -q prompt_host 42set -g prompt_host"" 43if set -q SSH_TTY 44or begin 45command -sq systemd-detect-virt 46and systemd-detect-virt -q 47end 48set prompt_host$usercolor$USER$normal @( set_color $fish_color_host ) $hostname$normal ":" 49end 50end 51 52# Shorten pwd if prompt is too long 53set -l pwd( prompt_pwd ) 54 55echo -n -s$prompt_host $cwd $pwd $normal $prompt_status $delim 56end 57 58function fish_right_prompt 59set -g __fish_git_prompt_showdirtystate1 60set -g __fish_git_prompt_showuntrackedfiles1 61set -g __fish_git_prompt_showupstream informative 62set -g __fish_git_prompt_showcolorhints1 63set -g __fish_git_prompt_use_informative_chars1 64set -g __fish_git_prompt_char_dirtystate\U1F4a9 65set -g __fish_git_prompt_char_untrackedfiles"?" 66 67# The git prompt's default format is ' (%s)'. 68# We don't want the leading space. 69set -l vcs( fish_vcs_prompt '(%s)' 2> /dev/null) 70 71set -l d( set_color brgrey)( date "+%R" )( set_color --reset) 72 73set -l duration" $cmd_duration$CMD_DURATION " 74if test $duration -gt 100 75set duration( math $duration /1000 ) s 76else 77set duration 78end 79 80set -q VIRTUAL_ENV_DISABLE_PROMPT 81or set -g VIRTUAL_ENV_DISABLE_PROMPT true 82set -q VIRTUAL_ENV 83and set -l venv( string replace -r'.*/' '' --" $VIRTUAL_ENV " ) 84 85set_color --reset 86string join" " --$venv $duration $vcs $d 87end