Created
April 1, 2015 16:05
-
-
Save dmay-work/5bf554bdd089c45bac75 to your computer and use it in GitHub Desktop.
fish_prompt.fish
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function _common_section | |
printf $c1 | |
printf $argv[1] | |
printf $c0 | |
printf ":" | |
printf $c2 | |
printf $argv[2] | |
printf $argv[3] | |
printf $c0 | |
printf " $c9| " | |
end | |
function section | |
_common_section $argv[1] $c3 $argv[2] $ce | |
end | |
function error | |
_common_section $argv[1] $ce $argv[2] $ce | |
end | |
function git_branch | |
set -g git_branch (git rev-parse --abbrev-ref HEAD ^ /dev/null) | |
if [ $status -ne 0 ] | |
set -ge git_branch | |
set -g git_dirty_count 0 | |
else | |
set -g git_dirty_count (git status --porcelain | wc -l | sed "s/ //g") | |
end | |
end | |
function fish_prompt | |
# $status gets nuked as soon as something else is run, e.g. set_color | |
# so it has to be saved asap. | |
set -l last_status $status | |
# c0 to c4 progress from dark to bright | |
# ce is the error colour | |
set -g c0 (set_color 005284) | |
set -g c1 (set_color 0075cd) | |
set -g c2 (set_color 009eff) | |
set -g c3 (set_color 6dc7ff) | |
set -g c4 (set_color ffffff) | |
set -g c9 (set_color 666666) | |
set -g ce (set_color $fish_color_error) | |
# Clear the line because fish seems to emit the prompt twice. The initial | |
# display, then when you press enter. | |
printf "\033[K" | |
# Current time | |
printf (date "+$c2%H$c0:$c2%M$c0:$c2%S$c0 $c9| ") | |
if [ $last_status -ne 0 ] | |
error last $last_status | |
set -ge status | |
end | |
# Git branch and dirty files | |
git_branch | |
if set -q git_branch | |
set out $git_branch | |
if test $git_dirty_count -gt 0 | |
set out "$out$c0:$ce$git_dirty_count" | |
end | |
section git $out | |
end | |
# Current Directory | |
# 1st sed for colourising forward slashes | |
# 2nd sed for colourising the deepest path (the 'm' is the last char in the | |
# ANSI colour code that needs to be stripped) | |
printf $c1 | |
printf (prompt_pwd | sed "s,/,$c0/$c1,g" | sed "s,\(.*\)/[^m]*m,\1/$c3,") | |
# Prompt on a new line | |
printf $c4 | |
printf "\n☵ " | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment