更改 Cygwin 提示符

更改 Cygwin 提示符

默认的 cygwin 提示符"user@computer path \n $"对我来说太长了。我想保留这条路径。

我希望它变成:

小路$

是否有一个我可以修改的配置文件来执行此操作?

答案1

环境PS1变量控制提示:

PS1='\w $ '

有关此主题和其他提示配置主题的更多信息,请键入man bash(假设bash是您的 shell)并参阅“PROMPTING”部分。

要使此更改永久生效,请编辑您的~/.bashrc文件以添加上述行。

答案2

登录 shell 是参数零的第一个字符为 - 的 shell,或者是使用 --login 选项启动的 shell。当 bash 作为交互式登录 shell 或使用 --login 选项作为非交互式 shell 调用时,它首先从文件 /etc/profile 读取并执行命令(如果该文件存在)。读取该文件后,它会按顺序查找 ~/.bash_profile、~/.bash_login 和 ~/.profile,然后从第一个存在且可读的文件中读取并执行命令。启动 shell 时可以使用 --noprofile 选项来抑制此行为。当启动非登录 shell 的交互式 shell 时,bash 将从 ~/.bashrc 读取并执行命令(如果该文件存在)。

所以这取决于...我不使用--login,所以我必须将其添加到~/.bashrc

答案3

不确定为什么较少的上下文比更多的上下文更好...提示中有一个新行这一事实意味着提示的长度不应该成为问题,但请尝试这样做:

PS1='\[\e[1;33m\]\w\n\[\e[1;36m\]\$\[\e[0m\] '

或者

export PS1='\[\e[1;33m\]\w\n\[\e[1;36m\]\$\[\e[0m\] '

这将为您提供一个彩色提示:

/full/path/to/current/folder
$your command text here

这样,您总是可以看到完整的文件夹上下文,但仍然可以获得整行输入文本。(我省略了“$”后面的常规空格,因为为了清晰起见,它是彩色的)。

Colours are:
    1. '/full/path/...' = yellow;
    2. '$' (on next line) = cyan;
    3. 'your command text...' = light grey.

对于那些确实想要“user@hostname”上下文的人来说:

PS1='\[\e[1;32m\]\u\[\e[1;35m\]@\[\e[1;32m\]\h \[\e[1;33m\]\w\n\[\e[1;36m\]\$\[\e[0m\] '

或者

export PS1='\[\e[1;32m\]\u\[\e[1;35m\]@\[\e[1;32m\]\h \[\e[1;33m\]\w\n\[\e[1;36m\]\$\[\e[0m\] '

这将为您提供一个彩色提示:

user@hostname /full/path/to/current/folder
$your command text here

这是我的偏好。

Colours are:
    1. 'user' = (light) green;
    2. '@' = pink;
    3. 'hostname' = (light) green;
    4. '/full/path/...' = yellow;
    5. '$' (on next line) = cyan;
    6. 'your command text...' = light grey.

(不,这篇文章中没有拼写错误——标准英语;))

答案4

将其放入您的 ~/.bashrc 中。提供彩色提示并将状态保存在一行中。

export PS1="\[\e]0;\w\a\]\n\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]\$ "

相关内容