From 983896f644698582b01b1508b37772989316adc6 Mon Sep 17 00:00:00 2001 From: Jonathan Hodgson Date: Thu, 18 Feb 2021 21:38:50 +0000 Subject: [PATCH] ZSH: Makes prompt shorter in narrow terminals This is mainly achieved by no longer showing the full path. If the terminal is less than 100 characters, it will show a preceding icon, >> then the bottom most folder name. The >> indicates that folders have been missed. I have added an icon for my dotfiles folder --- shells/zsh/includes/promptconfig.zsh | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/shells/zsh/includes/promptconfig.zsh b/shells/zsh/includes/promptconfig.zsh index f99ee7a5..20378ca5 100644 --- a/shells/zsh/includes/promptconfig.zsh +++ b/shells/zsh/includes/promptconfig.zsh @@ -8,9 +8,10 @@ prompt_dir(){ gitReposIcon="" magentoSiteIcon=" " dropboxIcon="" + dotfilesIcon="" seperator="  " seperatorDual="  " - root=" $seperator" + root=" " # Gets the path. local current_path="$(print -P "%~")" @@ -54,15 +55,21 @@ prompt_dir(){ fi - # Replace Dropbox with icon current_path=$(echo $current_path | sed -r -e "s/$homeIcon\/Dropbox/$dropboxIcon/") # Replace GitRepos with icon current_path=$(echo $current_path | sed -r -e "s/$homeIcon\/GitRepos/$gitReposIcon/") + # Replace GitRepos with icon + current_path=$(echo $current_path | sed -r -e "s/$homeIcon\/.dotfiles/$dotfilesIcon/") + # Set the root - current_path=$(echo $current_path | sed -r -e "s/^\//$root/g") + current_path=$(echo $current_path | sed -r -e "s/^\//$root\//g") + + if [[ $(tput cols) -lt 100 ]]; then + current_path=$(echo $current_path | sed -r -e "s/\/.*\//\/\//g") + fi # Set the dual seperator current_path=$(echo $current_path | sed -r -e "s/\/\//$seperatorDual/g") @@ -250,9 +257,7 @@ set_prompts(){ background="$(echo "$segment" | sed -n '2p')" fi - invisibleSeperator=$(echo -e '\u2063') - - PROMPT="$PROMPT $(seperator "$background")$(resetColor)$invisibleSeperator" + PROMPT="$PROMPT $(seperator "$background")$(resetColor)" #$(resetColor) RPROMPT="$(resetColor)$(prompt_last_exit_code "$RETVAL")$(resetColor)"