How to suppress (or customize) Mac Terminal shell prompt

前端 未结 4 1113
南方客
南方客 2021-01-29 21:53

Currently in my Terminal, every shell prompt looks like ComputerName: FooDir UserName$. The UserName part simply wastes too much space out of my precio

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-29 22:45

    The prompt is defined by the environment variable PS1 which you can define in .bash_profile.

    To edit it, open or create the (hidden) file .bash_profile:

    nano .bash_profile

    and add a line that says

    export PS1=""

    Between the quotation marks, you can insert what you would like as your terminal prompt. You can also use variables there:

    • \d – date
    • \t – time
    • \h – hostname
    • \# – command number
    • \u – username
    • \W – current directory (e.g.: Desktop)
    • \w – current directory path (e.g.: /Users/Admin/Desktop)

    The default prompt for common Linux distributions would be \w $, which evaluates to ~ $ in your home directory or e.g. /Users $ somewhere else. There are also website (like this one) that can help you with building your prompt.

    If you want to remove the UserName part, your choice would be \h: \w$.

    Once you made your changes, save the file with Control+o, Return, Control+x.

提交回复
热议问题