修改OS X终端中的Bash提示符前缀

sid*_*eks 45 macos bash terminal

我有一个大规模的提示,我的终端空间" 名称 s-MacBook-Pro"在每行输入命令的同一行.

有没有办法可以删除它或缩短它?

dav*_*rey 84

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

使用此命令检查当前设置的内容:

echo $PS1
Run Code Online (Sandbox Code Playgroud)

通过在您的~/.bash_profile(或之前定义的任何位置)中设置变量来修改它:

export PS1="$"
Run Code Online (Sandbox Code Playgroud)

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

source ~/.bash_profile
Run Code Online (Sandbox Code Playgroud)

这将使你的新shell提示只是一个 $


提示变量

  • PS1:主要提示字符串.默认值为\s-\v\$ .
  • PS2:辅助提示字符串.默认是>
  • PS3:提示select命令
  • PS4:在执行跟踪期间Bash显示的每个命令之前打印.PS4必要时,第一个字符被多次复制,以指示多个间接级别.默认是+

语法(来自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 $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
Run Code Online (Sandbox Code Playgroud)


归档时间:

查看次数:

47479 次

最近记录:

8 年,9 月 前