Terminally Confused

Discussion in 'Mac Apps and Mac App Store' started by dbally, Sep 29, 2003.

  1. dbally macrumors member

    Joined:
    Jul 27, 2003
    #1
    I decided to try out a software firewall since I currently only have an ibook connected to a router (with a built-in firewall) and didn't see a reason to keep it connected since there aren't any other computers on the network at the moment. The problem I found is that when I'm connected to the router, Terminal shows the

    [localhost:~] myname%

    prompt that I'd gotten used to. When I'm connected to the dsl modem directly, it shows a looooooong string of characters (my IP included) and myname%. I'd like to be able to be connected directly but have my old localhost label. This is just me being picky, I know, and I apologize. I don't understand why the localhost name would have changed, although I can (maybe) see why it'd be designated by my IP. The additional text in the localhost name is just annoying. My service is verizon dsl if thats on any use. Any help would be greatly appreciated.

    Cheers :)
     
  2. tomf87 macrumors 65816

    tomf87

    Joined:
    Sep 10, 2003
    #2
    Here's what I can come up with.

    When connected behind your router, your mac gets an IP. When opening terminal, it does a reverse DNS lookup for your IP. Since you are not running a DNS server that resolves the IP to a name (I'm assuming this), it just defaults to localhost.

    When connected directly to the DSL router, it gets an IP, and Verizon does have a reverse DNS (or PTR) record. So terminal shows the real name.

    I don't know how to change this behavior though.
     
  3. Doctor Q Administrator

    Doctor Q

    Staff Member

    Joined:
    Sep 19, 2002
    Location:
    Los Angeles
    #3
    Assuming you are using the tcsh shell (which is the default), your prompt is controlled by a shell variable named prompt. By default, prompt has this value:
    Code:
    [%m:%c3] %n%# 
    (with a trailing space that you can't see above). The shell replaces %m with the first part of your hostname as it determines it. The %c3 is replaced with your current directory (at most 3 levels), the %n with your user name, and the %# with either % for a regular user or # if you are superuser.

    The good news is that you can tinker with this string all you like (and get some pretty nutty prompts if you like). Try it:
    Code:
    [localhost:~] myname% set path='I like MacRumors > '
    I like MacRumors > set prompt='%n %# '
    myname% set prompt='[%m:%c3] %n%# '
    [localhost:~] myname% 
    Since you don't like seeing the hostname as the shell looks it up under your DSL connection, you can make it a constant, i.e.,
    Code:
    set prompt='[localhost:%c3] %n%# '
    Now the shell uses the constant "localhost" instead of looking it up (%m). You can use any constant string you like, not just "localhost".

    Of course, you don't want to type this every time you open a Terminal window, so put the set command at the end of file ~/.tcshrc and it'll be done for you automatically from now on.
     
  4. dbally thread starter macrumors member

    Joined:
    Jul 27, 2003
    #4
    Thanks Doctor Q

    Thanks for the help. I followed your steps and everything worked out wonderfully except for the part about adding the set command to the end of file ~/.tcshrc. I was unable to find this file. Could you please fill me in?

    I'm trying to discover some of the goodies Terminal has to offer and am probably messing with powers I do not yet understand . . . thats what makes it fun.
     
  5. Nermal Moderator

    Nermal

    Staff Member

    Joined:
    Dec 7, 2002
    Location:
    New Zealand
    #5
    ~/.tcshrc is hidden, and may not even exist by default. Type "pico ~/.tcshrc" and you'll get a text editor, where you can add the line, press Ctrl-X to quit, then press Y to save changes.
     
  6. Doctor Q Administrator

    Doctor Q

    Staff Member

    Joined:
    Sep 19, 2002
    Location:
    Los Angeles
    #6
    Your home directory is directory /Users/myname. By shell convention, your home directory can be referred to as ~, and the home directory of user thatuser can be referred to as ~thatuser. Which means that your own home directory can be referred to as either /Users/myname or ~ or ~myname.

    When you first open a Terminal window, you should be in your home directory. Type ls ("list") to display a list of the files currently in that directory, e.g.,
    Code:
    [localhost:~] myname% ls
    Apps       Pictures   Desktop
    Public     Documents  Library
    Sites      Movies     Music
    [localhost:~] myname% 
    If you add the -a ("all") switch, it'll show you hidden files too, where a hidden file is a file whose name begins with a period. So the command ls -a should include some extra files, such as these:
    Code:
    .
    ..
    .DS_Store
    .tcshrc
    The file named . is the current directory, i.e., the way /Users/myname refers to itself. The file named .. is the parent directory, i.e., the way /Users/myname refers to /Users. The file named .DS_Store is used by the Finder. And the file named .tcshrc, if you see it, holds your tcsh "resource control" lines, i.e., it is your shell startup file. If you don't see this file, you can simply create it.

    Editing files can be done a number of ways. I use vi, the "visual editor" that is part of Unix. There are lots of other editors, e.g., emacs, and you'll find fans of each one. A lesson in vi is beyond the scope of this one post, so here's a super-shortcut for what you want to do:

    1. Very carefully type this command in the shell:
    Code:
    cat >>~/.tcshrc
    and press RETURN.

    2. The shell will seem to stop talking to you, because it is appending all lines you type to file ~/.tcshrc until you give it a special end-of-file signal. So type the command you want in the file:
    Code:
    set prompt='[localhost:%c3] %n%# '
    and press RETURN.

    3. Again, it will seem dead, waiting for more input. Give it the end-of-file signal by pressing Control-D. You will get your beloved shell prompt back.

    This should add the prompt line onto the end of file ~/.tcshrc if it already exists, or create it if it doesn't already exist. Open a new window and see if it worked!

    You can learn more than you want to know about tcsh by typing man tcsh. If you read far enough, you'll come to the complete list of % thingies you can use in the prompt setting.
     
  7. dbally thread starter macrumors member

    Joined:
    Jul 27, 2003
    #7
    many thanks!

    Worked like a charm. Thank you very much for the great responses. Seeing how supportive the Mac community is is almost worth the price of switching all by itself.

    Cheers
     

Share This Page