Zsh prompt with current working directory

48,891

Solution 1

See the EXPANSION OF PROMPT SEQUENCES and SIMPLE PROMPT ESCAPES sections of the zsh manual page at man zshmisc.

This prompt string, PS1='%m %1d$ ', displays the machine name (%m) and the trailing component of the current path (%1d).

Solution 2

The best version of the combinations that works for me is this:

PS1='%n@%m %~$ '

%n is the user logged in

%m is the machine name

%~ gives the path relative to HOME, if path begins with HOME.

This is how it is for me:

This is how it is for me

The man page has more info. I tried to put in simpler terms here.! :D

Share:
48,891

Related videos on Youtube

AntK
Author by

AntK

Updated on September 18, 2022

Comments

  • AntK
    AntK over 1 year

    In bash I have my PROMPT set like so

    PS1="$(scutil --get ComputerName) \W\\$ "

    Where I only see the computer name and only the name of the current directory that I am in, not the full path and a $ sign.

    my-computer my-folder$

    My question is how can I set up my zsh prompt to be just like the bash one. I've been googling around, but the solutions I've found are not exactly what I am looking for.

    • creidhne
      creidhne almost 8 years
      Have you tried PS1='\h \W\$ ' in bash?
  • nolazybits
    nolazybits over 5 years
    man page are always good help indeed :) using %~ to have prompt with home replaced by ~.
  • JJLL
    JJLL over 3 years
    Thanks! This is the true equivalent to the bash version. The other answer (%1d) only shows the lowest hierarchy in the directory structure.