joelcannon
joelcannon

Reputation: 51

How to fix custom Terminal prompt with export PS1="\W \$"; clear; that becomes \W $

I am installing dev tools on a new MacBook Air (M1) with Big Sur and the default terminal prompt is too long and includes my user name and host, so I found instructions on how to customize it.

Using the Terminal's preference window, I added this code.

export PS1="\W \$"; clear;

but when I launch the terminal, I get this prompt

\W $

I replaced W with other options, but they are never processed - I just get the literal string.

I suspect it has to do with the config file format for Terminal.

Upvotes: 5

Views: 15290

Answers (4)

Sateesh
Sateesh

Reputation: 1336

Create .zshrc file at user root and paste text. Follow steps mentioned below.

  1. Run this command vi ~/.zshrc
  2. Press i button in keyboard to enter in edit mode
  3. Copy and paste this text into vi editor export PS1="%~ $ "
  4. Press Esc button in keyboard
  5. Press Shift + : button in keyboard
  6. Press wq button in keyboard and press Enter
  7. Restart your terminal by simply close and open again.

It Works!

For more configuration check documentation https://zsh.sourceforge.io/Doc/Release/Prompt-Expansion.html

Upvotes: 1

xdhmoore
xdhmoore

Reputation: 9915

My guess is that the \W is specific to bash.

Nowadays, the default macOS shell is zsh. See this page for some zsh prompt options

I am unable to test it on my Windows machine, but

PS1="%1~ $"

looks similar to \W to me.

Of course, if you want to configure your terminal to use bash, that's also an option.

Upvotes: 3

Nahuel
Nahuel

Reputation: 178

Put the following in your .bashrc file:

export PS1='\W $' 

Upvotes: 0

Rob Evans
Rob Evans

Reputation: 2874

I have something like:

#!/usr/bin/env bash

export BEEP=$(echo -en "\007")
LIGHT_GRAY="\[\033[0;37m\]"
GREEN="\[\033[0;32m\]"
export PS1=$LIGHT_GRAY"\u@\h $GREEN\w : $BEEP"

Works for me to give:

robevans@Robs-Machine ~ : [start_typing_here_in_green]

with an audible sound (not a beep but macOS's 'chime') when a command's execution is complete.

Upvotes: 1

Related Questions