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

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

问题描述

我有一个巨大的提示,将我的终端的空间names-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 中设置的,但通常由用户在主目录中的 dotfiles 中修改.

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

 : Newline

 : Carriage return
s : The name of the shell, the basename of $0 (the portion following the final slash)
	 : 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 $

nn : 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天全站免登陆