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
Jonathan Hodgson 4 years ago
parent 83a5c7c6c4
commit 979b0233a2
  1. 17
      shells/zsh/includes/promptconfig.zsh

@ -8,9 +8,10 @@ prompt_dir(){
gitReposIcon="" gitReposIcon=""
magentoSiteIcon=" " magentoSiteIcon=" "
dropboxIcon="" dropboxIcon=""
dotfilesIcon=""
seperator=" " seperator=" "
seperatorDual=" " seperatorDual=" "
root=" $seperator" root=" "
# Gets the path. # Gets the path.
local current_path="$(print -P "%~")" local current_path="$(print -P "%~")"
@ -54,15 +55,21 @@ prompt_dir(){
fi fi
# Replace Dropbox with icon # Replace Dropbox with icon
current_path=$(echo $current_path | sed -r -e "s/$homeIcon\/Dropbox/$dropboxIcon/") current_path=$(echo $current_path | sed -r -e "s/$homeIcon\/Dropbox/$dropboxIcon/")
# Replace GitRepos with icon # Replace GitRepos with icon
current_path=$(echo $current_path | sed -r -e "s/$homeIcon\/GitRepos/$gitReposIcon/") 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 # 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 # Set the dual seperator
current_path=$(echo $current_path | sed -r -e "s/\/\//$seperatorDual/g") current_path=$(echo $current_path | sed -r -e "s/\/\//$seperatorDual/g")
@ -250,9 +257,7 @@ set_prompts(){
background="$(echo "$segment" | sed -n '2p')" background="$(echo "$segment" | sed -n '2p')"
fi fi
invisibleSeperator=$(echo -e '\u2063') PROMPT="$PROMPT $(seperator "$background")$(resetColor)"
PROMPT="$PROMPT $(seperator "$background")$(resetColor)$invisibleSeperator"
#$(resetColor) #$(resetColor)
RPROMPT="$(resetColor)$(prompt_last_exit_code "$RETVAL")$(resetColor)" RPROMPT="$(resetColor)$(prompt_last_exit_code "$RETVAL")$(resetColor)"

Loading…
Cancel
Save