From a9ac4f925b8d8c52915e5f1f4419d5570086cd8a Mon Sep 17 00:00:00 2001 From: William Carroll Date: Fri, 6 Mar 2020 12:15:13 +0000 Subject: Support root directory and dirs like /tmp Properly handle display the root directory and sub directories. --- configs/.config/fish/prompt.fish | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'configs') diff --git a/configs/.config/fish/prompt.fish b/configs/.config/fish/prompt.fish index 17d807da0f02..58d22dab5efa 100644 --- a/configs/.config/fish/prompt.fish +++ b/configs/.config/fish/prompt.fish @@ -45,14 +45,21 @@ else # Git information set -l git_repo (git rev-parse --show-toplevel 2>/dev/null) set -l git_status $status - set -l dir_parent (basename (realpath ..)) - set -l dir_current (basename (realpath .)) + + if [ (realpath .) = "/" ] + set -g dir_path (realpath .) + else if [ (realpath ..) = "/" ] + set -g dir_path (realpath .) + else + set -g dir_path (echo (basename (realpath ..))"/"(basename (realpath .))) + end + if test $git_status -eq 0 set -l git_repo_name (basename (git rev-parse --show-toplevel)) set -l git_branch (git branch 2>/dev/null | grep '^\*' | cut -d' ' -f2-) - echo -en "$color_active \bgit ✓ [$color_normal$git_branch$color_active|$color_normal$git_repo_name$color_active|$color_normal$dir_parent/$dir_current$color_active]$color_normal" + echo -en "$color_active \bgit ✓ [$color_normal$git_branch$color_active|$color_normal$git_repo_name$color_active|$color_normal$dir_path$color_active]$color_normal" else - echo -en "$color_inactive \bgit ✗ [$color_normal$dir_parent/$dir_current$color_inactive]$color_normal" + echo -en "$color_inactive \bgit ✗ [$color_normal$dir_path$color_inactive]$color_normal" end # Newline @@ -65,8 +72,6 @@ else set -g prompt_sigil "λ" end - # TODO(wpcarro): For root directories like /tmp, there will not be a parent - # directory. Support these directories. set -l time (date +"%T") if test $last_status -eq 0 set -l color_prompt (set_color white --bold) -- cgit 1.4.1