dotfiles/fish/conf.d/fish_right_prompt.fish
2024-12-16 16:49:01 +05:30

37 lines
1.4 KiB
Fish

function fish_right_prompt
# Check if we're in a Git repo
set git_dir (git rev-parse --show-toplevel 2>/dev/null)
if test -n "$git_dir"
# Escape
set escaped_git_dir (string replace "/" "\\/" $git_dir)
# Get the repo name
set repo_name (basename $git_dir)
# Relative path in git
set relative_path (string replace -r "^$escaped_git_dir/" "" (pwd))
# RGB color codes
set repo_color "\033[38;2;55;120;130m" # RGB for repo name (dark cyan)
set separator_color "\033[38;2;178;98;44m" # RGB for separator (bronze)
set path_color "\033[38;2;82;82;82m" # RGB for path (gray)
set reset_color "\033[0m" # Reset color
# Ensure the relative path starts with a single slash
if not string match -r "^/" $relative_path
set relative_path "/$relative_path"
end
# Check if we're at the Git root or inside the repo
if test "$relative_path" = ""
# At the repo root
printf "$repo_color$repo_name$reset_color"
else
# Inside the repo, print the repo name, separator, and path
printf "$repo_color$repo_name$separator_color 󰊢 $path_color$relative_path$reset_color"
end
else
# Not in a Git repo, use the default prompt_pwd function
prompt_pwd
end
end