I'm running into an issue with hiding my computer name. I want all terminal outputs on my mac (iTerm ->zsh & IntelliJ) to stop showing my computer name and show ~/. Can someone help me achieve this, I'm not sure what setting I'm looking to change.
ie.
From
users/ComputerName/app/src/main/java/com/virtualprodigy/android_compose_template
To
~/app/src/main/java/com/virtualprodigy/android_compose_template
CodePudding user response:
Prompt format in zsh is controlled by PROMPT
or PS1
variable. You can check if one of these variables is set up in ~/.zshrc
(if there's no such file, create it by running touch ~/.zshrc
).
If in your .zshrc you see a line setting either PROMPT
or PS1
, in its value substitute %/
(absolute path) with %~
(relative to home path).
If there's no such line in your .zshrc, you can just add this:
PROMPT='%~ %# '
Then save the file and restart your terminal.
CodePudding user response:
To change the output of the pwd command and other commands that display the current working directory, you can create an alias in your shell profile.
STEP 1 : To do this, open the shell profile in a text editor:
nano ~/.zshrc
STEP 2 : Add the following line to the file, which will create an alias for the pwd command that replaces "users/ComputerName" with "~":
alias pwd="pwd | sed 's/\/users\/ComputerName/~/g'"
STEP 3 : You need to replace "ComputerName" with your computer's name. Save the file and exit the editor.Then, you need to activate the changes by running
source ~/.zshrc
This will create an alias for the pwd command that will replace "users/ComputerName" with "~" in the output.
CodePudding user response:
You can change the prompt in your terminal to display ~ instead of the full path by modifying your shell's configuration file.
For zsh, you can add the following line to your ~/.zshrc file:
PROMPT='%~ %# '
For bash, you can add this line to your ~/.bash_profile or ~/.bashrc file:
PS1="\w \$ "
This will change the prompt to display only the current directory, represented by ~ for the home directory, and the command prompt symbol ($ for normal users, # for superusers).
You will need to either restart your terminal, or run the command source ~/.zshrc
or source ~/.bashrc
to apply the changes.