From 7d7ee26c40a5a11644d44b449c3eb0ffde3ac320 Mon Sep 17 00:00:00 2001 From: anemofilia Date: Sun, 6 Aug 2023 10:50:50 -0300 Subject: [PATCH] feat: Improve fish_prompt --- files/fish/completions/completions | 1 + files/fish/completions/conf.d | 1 + files/fish/completions/config.fish | 1 + files/fish/completions/fish_variables | 1 + files/fish/completions/functions | 1 + files/fish/functions/fish_prompt.fish | 36 +++++++++++++++++++++++---- 6 files changed, 36 insertions(+), 5 deletions(-) create mode 120000 files/fish/completions/completions create mode 120000 files/fish/completions/conf.d create mode 120000 files/fish/completions/config.fish create mode 120000 files/fish/completions/fish_variables create mode 120000 files/fish/completions/functions diff --git a/files/fish/completions/completions b/files/fish/completions/completions new file mode 120000 index 0000000..9a3b84c --- /dev/null +++ b/files/fish/completions/completions @@ -0,0 +1 @@ +/home/radio/projects/guile/radix/files/fish/completions/ \ No newline at end of file diff --git a/files/fish/completions/conf.d b/files/fish/completions/conf.d new file mode 120000 index 0000000..abc97ab --- /dev/null +++ b/files/fish/completions/conf.d @@ -0,0 +1 @@ +/home/radio/projects/guile/radix/files/fish/conf.d \ No newline at end of file diff --git a/files/fish/completions/config.fish b/files/fish/completions/config.fish new file mode 120000 index 0000000..204b425 --- /dev/null +++ b/files/fish/completions/config.fish @@ -0,0 +1 @@ +/home/radio/projects/guile/radix/files/fish/config.fish \ No newline at end of file diff --git a/files/fish/completions/fish_variables b/files/fish/completions/fish_variables new file mode 120000 index 0000000..e97e6c2 --- /dev/null +++ b/files/fish/completions/fish_variables @@ -0,0 +1 @@ +/home/radio/projects/guile/radix/files/fish/fish_variables \ No newline at end of file diff --git a/files/fish/completions/functions b/files/fish/completions/functions new file mode 120000 index 0000000..f986208 --- /dev/null +++ b/files/fish/completions/functions @@ -0,0 +1 @@ +/home/radio/projects/guile/radix/files/fish/functions \ No newline at end of file diff --git a/files/fish/functions/fish_prompt.fish b/files/fish/functions/fish_prompt.fish index 7a0dcdc..d525f9a 100644 --- a/files/fish/functions/fish_prompt.fish +++ b/files/fish/functions/fish_prompt.fish @@ -1,3 +1,5 @@ +# Utilities + function blue set_color blue; printf $argv; set_color normal end @@ -5,20 +7,44 @@ function normal set_color normal; printf $argv; set_color normal 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 set -l cwd (pwd) test $cwd = $HOME && printf "~" || \ printf "%s/%s" (basename (dirname $cwd)) (basename $cwd) end +# Guix environment prompt +function fish_environment_prompt + normal "(env "; blue "%s" (basename $GUIX_ENVIRONMENT); normal ")" +end + +# Actual prompt function fish_prompt if test -n "$GUIX_ENVIRONMENT" - normal "(env "; blue "%s" (basename $GUIX_ENVIRONMENT); normal ")" - git branch &>/dev/null - test $status -eq 0 && normal ":" + 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 end - test $status && fish_git_prompt | sed 's/ //' - test $status || test -n "$GUIX_ENVIRONMENT" && printf '\n' switch "$fish_key_bindings" case fish_vi_key_bindings fish_hybrid_key_bindings