zsh declare PROMPT using multiple lines

Not exactly what you are looking for, but you don’t need to define PROMPT in a single assignment:

PROMPT="%n"    # username
PROMPT+="@%m"  # @hostname
PROMPT+=" %~"  # directory
PROMPT+="$ "

Probably closer to what you wanted is the ability to join the elements of an array:

prompt_components=(
   %n   # username
   " "  # space
   %m   # hostname
   " "  # space
   "%~"  # directory
   "$"
)
PROMPT=${(j::)prompt_components}

Or, you could let the j flag add the space delimiters, rather than putting them in the array:

# This is slightly different from the above, as it will put a space
# between the director and the $ (which IMO would look better).
# I leave it as an exercise to figure out how to prevent that.
prompt_components=(
 "%[email protected]%m"  # [email protected]
 "$~"  # directory
 "$" 
)

PROMPT=${(j: :)prompt_components}

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top