feat: Improve fish_prompt

keyring
anemofilia 2023-08-06 10:50:50 -03:00
parent 41a1181350
commit 7d7ee26c40
6 changed files with 36 additions and 5 deletions

View File

@ -0,0 +1 @@
/home/radio/projects/guile/radix/files/fish/completions/

View File

@ -0,0 +1 @@
/home/radio/projects/guile/radix/files/fish/conf.d

View File

@ -0,0 +1 @@
/home/radio/projects/guile/radix/files/fish/config.fish

View File

@ -0,0 +1 @@
/home/radio/projects/guile/radix/files/fish/fish_variables

View File

@ -0,0 +1 @@
/home/radio/projects/guile/radix/files/fish/functions

View File

@ -1,3 +1,5 @@
# Utilities
function blue function blue
set_color blue; printf $argv; set_color normal set_color blue; printf $argv; set_color normal
end end
@ -5,20 +7,44 @@ function normal
set_color normal; printf $argv; set_color normal set_color normal; printf $argv; set_color normal
end end
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
function fish_cwd_prompt function fish_cwd_prompt
set -l cwd (pwd) set -l cwd (pwd)
test $cwd = $HOME && printf "~" || \ test $cwd = $HOME && printf "~" || \
printf "%s/%s" (basename (dirname $cwd)) (basename $cwd) printf "%s/%s" (basename (dirname $cwd)) (basename $cwd)
end end
# Guix environment prompt
function fish_environment_prompt
normal "(env "; blue "%s" (basename $GUIX_ENVIRONMENT); normal ")"
end
# Actual prompt
function fish_prompt function fish_prompt
if test -n "$GUIX_ENVIRONMENT" if test -n "$GUIX_ENVIRONMENT"
normal "(env "; blue "%s" (basename $GUIX_ENVIRONMENT); normal ")" set -l fish_environment_prompt_length \
git branch &>/dev/null (displayed_string_length (fish_environment_prompt))
test $status -eq 0 && normal ":" 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
end end
test $status && fish_git_prompt | sed 's/ //'
test $status || test -n "$GUIX_ENVIRONMENT" && printf '\n'
switch "$fish_key_bindings" switch "$fish_key_bindings"
case fish_vi_key_bindings fish_hybrid_key_bindings case fish_vi_key_bindings fish_hybrid_key_bindings