在我的 ubuntu 终端中,我始终完全显示当前目录。像这样:
blabla@blublu:~/music/my_album/classical/beethoven$
但是在我的 Mac (Mac OS X 10.6.5) 终端中没有显示完整路径,它是这样的:
blabas-MacBook-Pro:古典贝多芬$
无论如何,我是否可以将 mac 终端行为更改为像 linux 终端一样?
Asm*_*mus 118
要让 bash 返回“user@hostname:path/to/directory$”作为提示,请将以下行添加到您的 ~/.bash_profile 中:
export PS1='\u@\H:\w$'
Run Code Online (Sandbox Code Playgroud)
或者
export PS1='\u@\H:\w$ '
Run Code Online (Sandbox Code Playgroud)
如果你喜欢在 $ 和命令之间有一个空格
要使更改立即生效,请在每个打开的窗口中运行以下命令(或重新启动终端):
source ~/.bash_profile
Run Code Online (Sandbox Code Playgroud)
编辑:可以在 bash ( man bash)手册页的“提示”段落中找到可用字符串列表:
提示
Run Code Online (Sandbox Code Playgroud)When executing interactively, bash displays the primary prompt PS1 when it is ready to read a command, and the secondary prompt PS2 when it needs more input to complete a command. Bash allows these prompt strings to be customized by inserting a number of backslash-escaped special characters that are decoded as follows: \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
小智 10
我不知道有关Mac,但在Ubuntu我已经改变了Gnome终端提示与
PS1="\a\n\n\e[31;1m\u@\h on \d at \@\n\e[33;1m\w\e[0m\n$ "
Run Code Online (Sandbox Code Playgroud)
小智 10
我使它看起来与 Mac 上的 centOS 终端非常相似。在终端上打开 bash_profile
nano ~/.bash_profile
Run Code Online (Sandbox Code Playgroud)
添加以下内容
# Show always fullpath on terminal
export PS1='\u@\H [\w]$ '
Run Code Online (Sandbox Code Playgroud)
重新启动终端,然后它看起来像这样
username@host.local [/Applications/MAMP/htdocs]$
Run Code Online (Sandbox Code Playgroud)
小智 6
在 PS1 值中,“\w”表示完整路径,其中“\W”仅表示当前目录名称。
http://tldp.org/HOWTO/Bash-Prompt-HOWTO/bash-prompt-escape-sequences.html
| 归档时间: |
|
| 查看次数: |
110373 次 |
| 最近记录: |