Skip to content

Instantly share code, notes, and snippets.

@akiirui
Created July 27, 2025 13:39
Show Gist options
  • Select an option

  • Save akiirui/e2373fd754a949ec499b374064fc3595 to your computer and use it in GitHub Desktop.

Select an option

Save akiirui/e2373fd754a949ec499b374064fc3595 to your computer and use it in GitHub Desktop.
Fish shell prompt
function __prompt_left_git_is_dirty -d 'Check git repo dirty'
echo (git status -s --ignore-submodules=dirty 2>/dev/null)
end
function __prompt_left_git_get_branch_name -d 'Get git branch name'
set -l branch (git symbolic-ref --quiet HEAD 2>/dev/null)
if set -q branch[1]
echo (string replace -r '^refs/heads/' '' $branch)
else
echo (git rev-parse --short HEAD 2>/dev/null)
end
end
function fish_prompt -d "Akatsuki's customize prompt"
# Hyperlinks end
set -l hyperlinks_end '\e]8;;\e\\'
# Special color
set -l color_normal (set_color normal)
# Foreground colors
set -l fg_black (set_color black)
set -l fg_red (set_color red)
set -l fg_green (set_color green)
set -l fg_yellow (set_color yellow)
set -l fg_blue (set_color blue)
set -l fg_magenta (set_color magenta)
set -l fg_cyan (set_color cyan)
set -l fg_white (set_color white)
# Background colors
set -l bg_black (set_color -b black)
set -l bg_red (set_color -b red)
set -l bg_green (set_color -b green)
set -l bg_yellow (set_color -b yellow)
set -l bg_blue (set_color -b blue)
set -l bg_magenta (set_color -b magenta)
set -l bg_cyan (set_color -b cyan)
set -l bg_white (set_color -b white)
# Prompt left -> Current working directory
set -l cwd (prompt_pwd)
if test "$USER" = root
set prompt_left_cwd "$bg_red $cwd $color_normal$fg_red"
else
set prompt_left_cwd "$bg_blue $cwd $color_normal$fg_blue"
end
# Prompt left -> Git info
if __fish_is_git_repository
set -l git_branch_name (__prompt_left_git_get_branch_name)
if [ (__prompt_left_git_is_dirty) ]
set prompt_left_git "$bg_yellow$fg_black $git_branch_name $color_normal$fg_yellow"
else
set prompt_left_git "$bg_green$fg_black $git_branch_name $color_normal$fg_green"
end
end
# Prompt left -> Last separator
set -l prompt_left_end "$color_normal "
# Prompt left -> Full prompt
set -l prompt_left $prompt_left_cwd $prompt_left_git $prompt_left_end
# End the hyperlink marks
printf $hyperlinks_end
echo -s -n $prompt_left
end
function fish_right_prompt -d "Akatsuki's customize right prompt"
set -l exit_status $status
# Special color
set -l color_normal (set_color normal)
# Foreground colors
set -l fg_black (set_color black)
set -l fg_red (set_color red)
set -l fg_green (set_color green)
set -l fg_yellow (set_color yellow)
set -l fg_blue (set_color blue)
set -l fg_magenta (set_color magenta)
set -l fg_cyan (set_color cyan)
set -l fg_white (set_color white)
# Background colors
set -l bg_black (set_color -b black)
set -l bg_red (set_color -b red)
set -l bg_green (set_color -b green)
set -l bg_yellow (set_color -b yellow)
set -l bg_blue (set_color -b blue)
set -l bg_magenta (set_color -b magenta)
set -l bg_cyan (set_color -b cyan)
set -l bg_white (set_color -b white)
# Prompt right -> Exit status
if not test "$exit_status" = 0
set prompt_right_status "$bg_red$fg_white $exit_status $fg_red"
end
# Prompt right -> SSH info
if test -n "$SSH_TTY"
set -l host_info $USER'@'(prompt_hostname)
set prompt_right_ssh "$bg_green$fg_black $host_info $fg_green"
end
# Prompt right -> Full prompt
set -l prompt_right $prompt_right_status $prompt_right_ssh $color_normal
echo -s -n $prompt_right
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment