7

I don't know how long ago this happened, but today I realized that when I open up terminal it no longer says

Matthew-MacBook:~matthew$

as it used to. Instead, it appears to have synched up with my roommate's macbook pro. It now displays:

$Gabriels-MBP:~matthew$

I've restarted my mac but it doesn't change the name.

I've tried the suggestions suggested in these posts

sudo scutil --set HostName Matthew-Macbook

But no effect!

echo "$PS1" returns \h:\W \u\$

maddie
  • 171

2 Answers2

3

I know this is late, but the solution here may work for others with similar roommates.

I am thinking that your hostname is properly set, but that your prompt definition may have been pranked.

First check is to run 'echo $PROMPT && echo $PS1' and see if they match. If they don't, then we are looking for a prompt re-definition for sure but it is worthwhile to investigate fully anyways.


The terminal prompt is defined in several places and I suggest you look at them all for alterations

I am assuming that you use bash as your shell based on the output from your echo command. When I went to Mojave I switched to zsh, but I kept my bash settings. This following is from my previous master file.

# ==============

/private/etc/profile
Last edited: 2019/07/08

Bash first reads and executes commands from the file /etc/profile, if that file exists. From that file it calls (appends) /private/etc/bashrc, the System-wide bashrc file for interactive bash(1) shells. That bashrc checks if bash is interactive, then sets windowsize parms, and then appends Apple terminal definitions before returning control to here

After reading those files, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable.

# ================

You should look at /private/etc/profile and /private/etc/bashrc as system wide prompts can be set there.

Also look at the ~/.bash_profile, ~/.bash_login, and ~/.profile files as they are the final place your prompt is set.

In general you are looking statements along the lines of: PS1=' some set of esc sequences like '\n and '\u mixed with the chars like '$' or '@''

 OR

PROMPT= the same as just above.

If you see Gabiel's name in any of those files then that is the one to change.

I would look at these files in reverse order.

If you are interested, putting the following would give you a nice terminal front based on a Green on Black Homebrew profile for you, root, and you as sudo -s. Of course you could modify it as you see fit as the colours are defined too. Copy following to the end of /private/etc/profile:

# declare ANSI color codes VARs

 RS="\[\033[0m\]"        # reset
 HC="\[\033[1m\]"        # hicolor
 UL="\[\033[4m\]"        # underline
 INV="\[\033[7m\]"       # inverse background and foreground
 FBLK="\[\033[30m\]"     # foreground black
 FRED="\[\033[31m\]"     # foreground red
 FGRN="\[\033[32m\]"     # foreground green
 FYEL="\[\033[33m\]"     # foreground yellow
 FBLE="\[\033[34m\]"     # foreground blue
 FMAG="\[\033[35m\]"     # foreground magenta
 FCYN="\[\033[36m\]"     # foreground cyan
 FWHT="\[\033[37m\]"     # foreground white
 BBLK="\[\033[40m\]"     # background black
 BRED="\[\033[41m\]"     # background red
 BGRN="\[\033[42m\]"     # background green
 BYEL="\[\033[43m\]"     # background yellow
 BBLE="\[\033[44m\]"     # background blue
 BMAG="\[\033[45m\]"     # background magenta
 BCYN="\[\033[46m\]"     # background cyan
 BWHT="\[\033[47m\]"     # background white
 BFRED="\[\033[01;31m\]" # bright foreground red
 BFGRN="\[\033[01;32m\]" # bright foreground green
 BFYEL="\[\033[01;33m\]" # bright foreground yellow
 BFBLE="\[\033[01;34m\]" # bright foreground blue
 BFMAG="\[\033[01;35m\]" # bright foreground magenta
 BFCYN="\[\033[01;36m\]" # bright foreground cyan
 BFWHT="\[\033[01;37m\]" # bright foreground white

# end colour VARs

# set colour prompt

    export SUDO_PS1='\n'$BFRED'\u'$BFGRN'@'$BFRED'\h'$BFGRN':'$BFBLE'\w '$RS''$FRED'$ '

    if [[ ${EUID} != 0 ]]; then
        export PS1='\n'$BFGRN'\u'$BFRED'@'$BFGRN'\h'$BFRED':'$BFBLE'\w '$RS''$FGRN'# '
    else
        export PS1='\n'$BFRED'\u'$BFGRN'@'$BFRED'\h'$BFGRN':'$BFBLE'\w '$RS''$FRED'$ '
    fi

# end set prompt

0

In the intervening years I have transitioned to mostly zsh terminals. This works on Macs and all linux that allow zsh.

Put these line in your ~/.zshrc file: #!/bin/zsh

Set up the prompt

PS1=$'\n%{\e[\033[0;1;32;40m%}┬─[%n%{\e[\033[0;1;31;40m%}@%{\e[\033[32m%}%m%{\e[\033[31m%}:%{\e[\033[32m%}\e\e %D%{\e[\033[31m%}:%{\e[\033[32m%}%*%{\e[\033[31m%}:\n%{\e[\033[32m%}╰─>%{\e[\033[34m%}:%~/%{\e[\033[35m%}%(2L.+.)$%{\e[\033[0m%} '

AND this line in your /root/.zshrc file

PS1=$'\n%{\e[\033[0;1;31;40m%}┬─[%n%{\e[\033[0;1;32;40m%}@%{\e[\033[31m%}%m%{\e[\033[32m%}:%{\e[\033[31m%}\e\e %D%{\e[\033[32m%}:%{\e[\033[31m%}%*%{\e[\033[32m%}:\n%{\e[\033[31m%}╰─>%{\e[\033[34m%}:%~/%{\e[\033[35m%}%(2L.+.)$%{\e[\033[0m%} '

For those of you who try out different terminal types, you may recognize this as derived from the default fish prompt for root.

FYI, don't forget the final space and single quote.

I have tried for a prompt that gives status info and has a second line for the command. I wanted the second line because highlight copy of the last command can be very difficult if your path in the prompt wraps in the terminal and a third line to hold only the output. This also helps if readability if you terminal is not full screen.

I have then made it like the homebrew view, green on black for the user and and added red on black for root.

┬─[rcatyvr@aarc05:2-07-21:15:32:09:
╰─>:/etc/zsh/$ ls
zlogin zlogout zprofile zshenv zshrc

In this case the info is in green, the colons : and the @ sign are red, the path is in light blue, the prompt $ is magenta and the commands and output are white. For root, the red and green are reversed.

I chose white output for my weakening sight, but you can make the output to match the prompt lines as you want by changing the end of the line {\e[\033[0m%} to 31m% for red, or 32m% for green, or back to reset default white, 0%m.

If you are heavily committed to bash, most if not all of the escape sequences above have their bash equivalents. But that is a lot of work that I leave up to you if you are interested in the challenge. I'd like to see the bash equivalent of these zsh prompts posted in an answer.