Created
March 26, 2025 01:29
-
-
Save akarca/b6bab58d4bed9bd478e439a49010a8e0 to your computer and use it in GitHub Desktop.
Fish Prompt and Right Prompt
This file contains hidden or 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 fish_prompt --description 'Write out the prompt' | |
set -l laststatus $status | |
set -l git_info | |
if set -l git_branch (command git symbolic-ref HEAD 2>/dev/null | string replace refs/heads/ '') | |
set git_branch (set_color -o blue)"$git_branch" | |
set -l git_status | |
if not command git diff-index --quiet HEAD -- | |
if set -l count (command git rev-list --count --left-right $upstream...HEAD 2>/dev/null) | |
echo $count | read -l ahead behind | |
if test "$ahead" -gt 0 | |
set git_status "$git_status"(set_color red)⬆ | |
end | |
if test "$behind" -gt 0 | |
set git_status "$git_status"(set_color red)⬇ | |
end | |
end | |
for i in (git status --porcelain | string sub -l 2 | sort | uniq) | |
switch $i | |
case "." | |
set git_status "$git_status"(set_color green)✚ | |
case " D" | |
set git_status "$git_status"(set_color red)✖ | |
case "*M*" | |
set git_status "$git_status"(set_color green)✱ | |
case "*R*" | |
set git_status "$git_status"(set_color purple)➜ | |
case "*U*" | |
set git_status "$git_status"(set_color brown)═ | |
case "??" | |
set git_status "$git_status"(set_color red)≠ | |
end | |
end | |
else | |
set git_status (set_color green): | |
end | |
set git_info "(git$git_status$git_branch"(set_color white)")" | |
end | |
# Disable PWD shortening by default. | |
set -q fish_prompt_pwd_dir_length | |
or set -lx fish_prompt_pwd_dir_length 0 | |
# set_color -b black | |
printf '%s%s%s%s' (set_color yellow) (prompt_pwd) (set_color white) $git_info | |
if test $laststatus -eq 0 | |
printf " %s➜%s " (set_color -o green) (set_color normal) | |
else | |
printf " %s✗%s " (set_color -o red) (set_color normal) | |
end | |
end |
This file contains hidden or 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 fish_right_prompt | |
set virtname (pyenv version-name) | |
if [ $virtname != "system" ] | |
set pyver (python --version | awk '{print $2}') | |
set_color brgrey | |
echo "($virtname-$pyver)" | |
set_color normal | |
end | |
set -l d (set_color brgrey)(date "+%R")(set_color normal) | |
set -l duration "$cmd_duration$CMD_DURATION" | |
set duration (math $duration / 1000)s | |
echo " "$duration | |
echo " "$d | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment