Go Back   The macosxhints Forums > OS X Help Requests > UNIX - Newcomers



Reply
 
Thread Tools Rate Thread Display Modes
Old 03-23-2011, 08:06 PM   #1
michellepace
Prospect
 
Join Date: Jan 2009
Location: South Africa
Posts: 42
Question How to change "Michelle-Paces-MacBook-Pro:~ m$" (terminal)

Hello there,

Please could someone tell me how to alter "Michelle-Paces-MacBook-Pro" appearing immediately on the prompt line when opening my terminal window as shown below. The username of my account is "m". That part is fine, nice and short.

Michelle-Paces-MacBook-Pro:~ m$

Thank-you in advance, Michelle

Last edited by michellepace; 03-23-2011 at 08:08 PM.
michellepace is offline   Reply With Quote
Old 03-23-2011, 10:14 PM   #2
hayne
Site Admin
 
Join Date: Jan 2002
Location: Montreal
Posts: 31,956
Try changing the computer name in the Sharing preferences.
__________________
hayne.net/macosx.html
hayne is offline   Reply With Quote
Old 03-24-2011, 12:07 AM   #3
michellepace
Prospect
 
Join Date: Jan 2009
Location: South Africa
Posts: 42
Quote:
Originally Posted by hayne
Try changing the computer name in the Sharing preferences.

Thanks Hayne, but I have already tried that but to know avail.

I am sure there must be some type of unix'y command... or config setting somewhere ...?
michellepace is offline   Reply With Quote
Old 03-24-2011, 12:18 AM   #4
hayne
Site Admin
 
Join Date: Jan 2002
Location: Montreal
Posts: 31,956
1) What is the name of your computer in the Sharing preferences?

2) If your computer is attached to a network, then the "hostname" (which is what appears in the prompt) is often assigned by the DHCP server. Perhaps your router is assigning this name since that was the old name for this computer? You might need to reboot or reset your router.
__________________
hayne.net/macosx.html
hayne is offline   Reply With Quote
Old 03-24-2011, 02:36 AM   #5
michellepace
Prospect
 
Join Date: Jan 2009
Location: South Africa
Posts: 42
oh I'm an idiot.

thanks Hayne.
michellepace is offline   Reply With Quote
Old 03-24-2011, 10:38 AM   #6
hayne
Site Admin
 
Join Date: Jan 2002
Location: Montreal
Posts: 31,956
It might help some future reader (via Google) if you explained what you were doing wrong. I.e. what was causing the problem.

By the way, since you seem to be concerned with the length of your prompt, you might want to customize your prompt via the facilities offered by your shell. E.g. for Bash (the usual shell for new OS X accounts), see: http://www.cyberciti.biz/tips/howto-...up-prompt.html
__________________
hayne.net/macosx.html

Last edited by hayne; 03-24-2011 at 10:42 AM.
hayne is offline   Reply With Quote
Old 03-24-2011, 10:15 PM   #7
michellepace
Prospect
 
Join Date: Jan 2009
Location: South Africa
Posts: 42
The problem: the display of my prompt line in my terminal window was too long, I wanted to shorten it.

The solution: Shortened my computer name in computer name in system preferences.

(thanks again Hayne)
michellepace is offline   Reply With Quote
Old 03-24-2011, 11:25 PM   #8
brettgrant99
All Star
 
Join Date: May 2007
Posts: 654
It doesn't really matter, but it probably would have been to look into the prompt customizations available in the shell. I primarily use tcsh, so I can't really give help with the bash syntax.

In a way, it is kind of like living in San Francisco and flying to LA via New York. You get what you want in the end, but it kind of a roundabout way of doing it.

There are a lot of options with prompts. I've never been a fan of the computer name, but the worse one was a prompt that displayed the last two commands - that one was annoying, had to change it quickly.

HTH,
Brett
brettgrant99 is offline   Reply With Quote
Old 03-25-2011, 12:42 AM   #9
hayne
Site Admin
 
Join Date: Jan 2002
Location: Montreal
Posts: 31,956
Quote:
Originally Posted by michellepace
The solution: Shortened my computer name in computer name in system preferences.

Yes, but you had said that you had "already tried that but to [no] avail".
So I thought you were going to explain (for the benefit of future readers with the same problem) just what it was that caused the problem, or the confusion, or whatever.
__________________
hayne.net/macosx.html
hayne is offline   Reply With Quote
Old 03-30-2011, 01:21 AM   #10
tw
Hall of Famer
 
Join Date: Apr 2007
Posts: 4,262
Quote:
Originally Posted by hayne
Yes, but you had said that you had "already tried that but to [no] avail".
So I thought you were going to explain (for the benefit of future readers with the same problem) just what it was that caused the problem, or the confusion, or whatever.

I've actually had this confusion myself. Most people don't realize that the computer name (aka the name of the boot drive) can be different from the network name of the computer, and most people assume blithely that if you change the obvious one (the name of the boot drive) the non-obvious network name will change automatically. Frankly, if unix used the name of the boot drive rather than the network name (and I'm not sure why it doesn't) few people would ever realize that there are two names for the machine. Once you 'get' the fact that there are different names for the machine for different purposes it's all very obvious, but...
__________________
Philosophy is a battle against the bewitchment of our intelligence by means of language. -LW-
tw is offline   Reply With Quote
Old 03-30-2011, 02:39 AM   #11
hayne
Site Admin
 
Join Date: Jan 2002
Location: Montreal
Posts: 31,956
Quote:
Originally Posted by tw
if unix used the name of the boot drive rather than the network name (and I'm not sure why it doesn't) few people would ever realize that there are two names for the machine

The name of the boot drive is just (and only) that - the name of a drive.
If you boot from a different drive, you probably don't want the name of the machine to change.
Note also that the name of the boot drive is not actually used at the Unix level - the boot drive is always referred to as "/" in Unix. It's only in Finder that the name you assign to the drive is visible. (It is also visible at the Unix level as an symbolic link in /Volumes just for consistency with other drives, but this alias is not usually used.)
__________________
hayne.net/macosx.html
hayne is offline   Reply With Quote
Old 03-28-2012, 03:37 AM   #12
michellepace
Prospect
 
Join Date: Jan 2009
Location: South Africa
Posts: 42
Question

Goodness, one year later and an upgrade to Lion and I have this problem again. My computer's name in Sharing is "fuboo".

I'd like to shorten the prompt:
Change this: vc-gp-n-41-16-229-201:~ m$
To this: fuboo:~ m$
Sorry to ask the same question, anyone got any ideas on how to do this?

Also, just what is "vc-gp-n-41-16-229-201" and where does it come from? The name of my boot drive (i.e. my only drive) is simply called the default, "Macintosh HD".

thank-you.
Attached Thumbnails
Click image for larger version

Name:	shorten-this-prompt.jpg
Views:	64
Size:	56.2 KB
ID:	4493  

Last edited by michellepace; 03-28-2012 at 03:46 AM. Reason: clarity, and another question
michellepace is offline   Reply With Quote
Old 03-28-2012, 09:10 AM   #13
benwiggy
League Commissioner
 
Join Date: Aug 2006
Posts: 5,071
There are several different "names" that your computer goes under.

The "ComputerName", which is the one in the Sharing System Preference.
The "LocalHostName", which is the one under the "Edit..." button in the Sharing Pref. This can be different from the ComputerName.

There's also a "HostName", which on OS X is "not set". However, typing the Terminal command "hostname" returns the LocalHostName.
Typing "scutil --get HostName" returns "not set".

The name in the Terminal prompt is normally the LocalHostName. The one you have there looks like it's been assigned by your router, possibly.
In the "Edit..." button dialog, make sure that the checkbox "Use dynamic global hostname" is de-ticked.
benwiggy is offline   Reply With Quote
Old 03-28-2012, 10:58 AM   #14
trevor
Moderator
 
Join Date: Jun 2003
Location: Boulder, CO USA
Posts: 19,560
Quote:
Originally Posted by michellepace
Goodness, one year later and an upgrade to Lion and I have this problem again. My computer's name in Sharing is "fuboo".

I'd like to shorten the prompt:
Change this: vc-gp-n-41-16-229-201:~ m$
To this: fuboo:~ m$
Sorry to ask the same question, anyone got any ideas on how to do this?

hayne gave you a link to how customize your prompt above in post #6, and that's really the best answer. But if you'd prefer some very specific directions, here you go:

I'm assuming that you're using the bash shell.

nano ~/.bash_profile

If .bash_profile already exists in your home folder, make sure that it contains the line

source $HOME/.bashrc

If it doesn't exist (the nano command above makes nano open up with no text), then type or copy/paste the source $HOME/.bashrc into it. Save the file in Nano with Control-X, 'y', and hit Return.

Now, let's add the line to customize your prompt to ~/.bashrc

nano ~/.bashrc

First check to see if there's anything there about 'PS1'. If so, move to edit that line. If not, use the arrow keys (or if it's long, you can move down a page at a time with Control-V) to move to the bottom of the file.

To get exactly the prompt you requested above all the time, copy/paste the following:

export PS1="\r\n\e[1;32mfuboo:\w $\e[0;30m "

This above assumes that your Terminal is black text on a white or light colored background. If your normal text is white on a black or dark colored background, then change the above to

export PS1="\r\n\e[1;32mfuboo:\w $\e[0;37m "

Save with Control-X, 'y', and then hit Return.

Now, restart your Terminal window to see your new prompt.
trevor is offline   Reply With Quote
Old 03-29-2012, 05:34 AM   #15
michellepace
Prospect
 
Join Date: Jan 2009
Location: South Africa
Posts: 42
Thank-you Trevor, that worked just fine. I followed your steps exactly by creating .bashrc, it worked great.

However, I then wondered if just setting PS1 in .bash_profile would work.. I deleted .bashrc, removed source $HOME/.bashrc from .bash_profile, and added export PS1="\r\n\e[1;32mfuboo:\w $\e[0;30m " to .bash_profile. It worked perfectly too.

So just for the interest of knowing, why your suggested preference of using .bashrc?

Last edited by michellepace; 03-29-2012 at 05:40 AM.
michellepace is offline   Reply With Quote
Old 03-29-2012, 11:23 AM   #16
trevor
Moderator
 
Join Date: Jun 2003
Location: Boulder, CO USA
Posts: 19,560
For the long answer, check hayne's FAQ:
http://hayne.net/MacDev/Notes/unixFAQ.html#shellStartup

For the short answer, if you do it the way I suggested, you get consistent behavior when you start a new Terminal window, versus when you start the bash shell at the command prompt (for example, by typing
bash
and hitting Return.)

If you skip the extra step, you'll get inconsistent behavior.

Trevor
trevor is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 02:52 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.