如何隐藏(或自定义)Mac Terminal Shell提示符 [英] How to suppress (or customize) Mac Terminal shell prompt

查看:242
本文介绍了如何隐藏(或自定义)Mac Terminal Shell提示符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前在我的终端中,每个shell提示符都类似于ComputerName: FooDir UserName$. UserName部分仅浪费了我宝贵的80列中的太多空间.有办法抑制它吗?

Currently in my Terminal, every shell prompt looks like ComputerName: FooDir UserName$. The UserName part simply wastes too much space out of my precious 80 columns. Is there a way to suppress it?

推荐答案

提示由环境变量PS1定义,您可以在.bash_profile中定义.

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

要对其进行编辑,请打开或创建(隐藏)文件.bash_profile:

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

nano .bash_profile

并添加一行说明

export PS1=""

在引号之间,您可以插入所需的内容作为终端提示.您还可以在其中使用变量:

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

  • \d –日期
  • \t –时间
  • \h –主机名
  • \# –命令号
  • \u –用户名
  • \W –当前目录(例如:桌面)
  • \w –当前目录路径(例如:/Users/Admin/Desktop)
  • \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)

常见Linux发行版的默认提示符为\w $,在您的主目录或例如,其值为~ $. /Users $其他地方.还有一些网站(例如)可以帮助您建立提示.

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.

如果要删除UserName部分,则选择\h: \w$.

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

进行更改后,请使用 Control + o Return Control + x .

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

这篇关于如何隐藏(或自定义)Mac Terminal Shell提示符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆