修改 OS X 终端中的 Bash 提示前缀
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26229576/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Modify Bash prompt prefix in OS X terminal
提问by sidegeeks
I have a massive prompt taking my Terminal's space "names-MacBook-Pro" on the same line where the command is entered on every line.
我有一个巨大的提示,在每一行输入命令的同一行上输入我终端的空间“名称s-MacBook-Pro”。
Is there a way I can remove this or make it shorter?
有没有办法可以删除它或缩短它?
回答by davidcondrey
Your prompt is set by the environment variable PS1
. This is set by the system in /private/etc/bashrc
, but it is usually modified by the user in your dotfiles within your home directory.
您的提示由环境变量设置PS1
。这是由系统在 中设置的/private/etc/bashrc
,但通常由用户在主目录中的点文件中修改。
Check what it is currently set as using this command:
使用此命令检查当前设置的内容:
echo $PS1
Modify it by setting the variable in your ~/.bash_profile
(or wherever you have defined it previously):
通过在您的~/.bash_profile
(或您之前定义的任何地方)中设置变量来修改它:
export PS1="$"
Reload the settings from your dotfiles by doing:
通过执行以下操作从您的点文件重新加载设置:
source ~/.bash_profile
This will make your new shell prompt simply a $
这将使您的新 shell 提示符变得简单 $
Prompt variables
提示变量
PS1
: Primary prompt string. The default value is\s-\v\$ .
PS2
: Secondary prompt string. The default is>
PS3
: Prompt for theselect
commandPS4
: Printed before each command Bash displays during an execution trace. The first character ofPS4
is replicated multiple times, as necessary, to indicate multiple levels of indirection. The default is+
PS1
: 主要提示字符串。默认值为\s-\v\$ .
PS2
: 次要提示字符串。默认是>
PS3
: 提示输入select
命令PS4
:在执行跟踪期间 Bash 显示的每个命令之前打印。的第一个字符PS4
根据需要多次复制,以指示多个间接级别。默认是+
Syntax (from the Bash manual)
语法(来自 Bash手册)
\a : An ASCII bell character (07)
\d : The date in “Weekday Month Date” format (e.g., “Tue May 26”)
\D{format} : the format is passed to strftime(3) and the result is inserted into the prompt string; an empty format results in a locale-specific time representation. The braces are required
\e : An ASCII escape character (033)
\h : The hostname up to the first ‘.'
\H : The hostname
\j : The number of jobs currently managed by the shell
\l : The basename of the shell's terminal device name
\n : Newline
\r : Carriage return
\s : The name of the shell, the basename of ##代码## (the portion following the final slash)
\t : The current time in 24-hour HH:MM:SS format
\T : The current time in 12-hour HH:MM:SS format
\@ : The current time in 12-hour am/pm format
\A : The current time in 24-hour HH:MM format
\u : The username of the current user
\v : The version of Bash (e.g., 2.00)
\V : The release of Bash, version + patch level (e.g., 2.00.0)
\w : The current working directory, with $HOME abbreviated with a tilde
\W : The basename of the current working directory, with $HOME abbreviated with a tilde
\! : The history number of this command
\# : The command number of this command
$ : If the effective UID is 0, a #, otherwise a $
\nnn : the character corresponding to the octal number nnn
\ : A backslash
\[ : Begin a sequence of non-printing characters, which could be used to embed a terminal control sequence into the prompt
\] : end a sequence of non-printing characters