在OSX终端中修改Bash提示符前缀

在OSX终端中修改Bash提示符前缀,bash,macos,terminal,Bash,Macos,Terminal,我有一个巨大的提示,将终端的空格“names MacBook Pro”放在同一行中,命令在每一行中输入 有什么方法可以删除或缩短它吗?您的提示是由环境变量PS1设置的。这是由系统在/private/etc/bashrc中设置的,但通常由用户在主目录的dotfiles中修改 使用以下命令检查当前设置为什么: echo $PS1 通过在~/.bash_配置文件(或之前定义的任何地方)中设置变量来修改它: 通过执行以下操作从点文件重新加载设置: source ~/.bash_profile 这将使

我有一个巨大的提示,将终端的空格“names MacBook Pro”放在同一行中,命令在每一行中输入


有什么方法可以删除或缩短它吗?

您的提示是由环境变量
PS1
设置的。这是由系统在
/private/etc/bashrc
中设置的,但通常由用户在主目录的dotfiles中修改

使用以下命令检查当前设置为什么:

echo $PS1
通过在
~/.bash_配置文件
(或之前定义的任何地方)中设置变量来修改它:

通过执行以下操作从点文件重新加载设置:

source ~/.bash_profile
这将使您的新shell提示符成为一个简单的
$


提示变量
  • PS1
    :主提示字符串。默认值为
    \s-\v\$。
  • PS2
    :辅助提示字符串。默认值为
    >
  • PS3
    :提示输入
    select
    命令
  • PS4
    :在执行跟踪期间显示每个命令Bash之前打印。必要时,将多次复制
    PS4
    的第一个字符,以指示多级间接寻址。默认值为
    +
语法(来自Bash)
请参阅开放系统首选项->共享,更改本地主机名。重复的我想在提示符和键入的命令之间保留一个空格,因此我选择自己添加一个空格:
export PS1=“$”
。David,提醒一下:您的答案。export PS1=“$”最好是export PS1=“$”因为这有助于区分命令提示符和您键入的实际命令inI do export PS1=“[\u@\h:\w]\n$”请注意,
PS1
的默认值是
\h:\w\u\$
,并且此答案中列出的默认值没有任何用处,他们可能从那时起就更改了它
source ~/.bash_profile
\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 $0 (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