在OS X终端中修改Bash提示前缀 [英] Modify Bash prompt prefix in OS X terminal

查看:71
本文介绍了在OS X终端中修改Bash提示前缀的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在每行输入命令的同一行上,我将出现一个很大的提示,将我的终端的空格"名称 s-MacBook-Pro"带到了该行.

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.

有没有办法删除它或使其更短?

Is there a way I can remove this or make it shorter?

推荐答案

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

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.

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

Check what it is currently set as using this command:

echo $PS1

通过在~/.bash_profile(或之前定义的位置)中设置变量来对其进行修改:

Modify it by setting the variable in your ~/.bash_profile (or wherever you have defined it previously):

export PS1="$"

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

Reload the settings from your dotfiles by doing:

source ~/.bash_profile

这将使您的新shell提示符简单地成为$

This will make your new shell prompt simply a $

  • PS1:主提示字符串.默认值为\s-\v\$ .
  • PS2:辅助提示字符串.默认值为>
  • PS3:提示输入select命令
  • PS4:在执行跟踪期间,在每个命令Bash显示之前打印.根据需要,多次复制PS4的第一个字符,以指示多个间接级别.默认值为+
  • PS1 : Primary prompt string. The default value is \s-\v\$ .
  • PS2 : Secondary prompt string. The default is >
  • PS3 : Prompt for the select command
  • PS4 : Printed before each command Bash displays during an execution trace. The first character of PS4 is replicated multiple times, as necessary, to indicate multiple levels of indirection. The default is +
\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

这篇关于在OS X终端中修改Bash提示前缀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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