radix/files/fish/functions/fish_prompt.fish

62 lines
1.6 KiB
Fish
Raw Normal View History

2023-08-06 13:50:50 +00:00
# Utilities
2023-08-06 02:30:22 +00:00
function blue
set_color blue; printf $argv; set_color normal
end
function normal
set_color normal; printf $argv; set_color normal
end
2023-08-06 13:50:50 +00:00
function displayed_string_length
string replace -ra -- '\x1b.*?[mGKH]' '' "$argv" | string length
end
function padding
printf "%-"$argv[1]"s%s" " " "$output"
end
# Current working directory prompt
2023-08-06 02:30:22 +00:00
function fish_cwd_prompt
set -l cwd (pwd)
test $cwd = $HOME && printf "~" || \
2023-08-06 03:14:42 +00:00
printf "%s/%s" (basename (dirname $cwd)) (basename $cwd)
2023-08-06 02:30:22 +00:00
end
2023-08-06 13:50:50 +00:00
# Guix environment prompt
function fish_environment_prompt
normal "(env "; blue "%s" (basename $GUIX_ENVIRONMENT); normal ")"
end
# Actual prompt
2023-08-06 02:30:22 +00:00
function fish_prompt
if test -n "$GUIX_ENVIRONMENT"
2023-08-06 13:50:50 +00:00
set -l fish_environment_prompt_length \
(displayed_string_length (fish_environment_prompt))
set -l fish_git_prompt_length \
(displayed_string_length (fish_git_prompt))
fish_environment_prompt
printf (padding (math $COLUMNS - $fish_environment_prompt_length \
- $fish_git_prompt_length))
fish_git_prompt | string replace -ra ' ' ''
printf '\n'
else
function fish_right_prompt
fish_git_prompt
end
2023-08-06 02:30:22 +00:00
end
switch "$fish_key_bindings"
case fish_vi_key_bindings fish_hybrid_key_bindings
test $fish_bind_mode = 'default' && normal ':' || normal '+'
end
blue (whoami); normal ' at '; blue (prompt_hostname)
normal ' in '; blue (fish_cwd_prompt)
normal ' > '
end
function fish_default_mode_prompt -d "Display vi prompt mode"
# Do nothing
end