你可以将用户名和主机名设置为白色,当前路径设置为蓝色,并在 $ 符号前以绿色显示 Git 分支信息。以下是如何配置的步骤:

1. 修改 .bashrc 文件

请按照以下步骤进行配置:

  1. 打开 ~/.bashrc 文件:

    nano ~/.bashrc
    
  2. 在文件中添加或修改以下代码:

    # Git branch information
    parse_git_branch() {
        git branch 2>/dev/null | grep '*' | sed 's/* /(/' | sed 's/$/)/'
    }
    
    # Customize PS1 (Prompt String 1) to keep directory path colored and show Git branch before the $
    export PS1="\[\033[0;37m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[1;32m\]\$(parse_git_branch)\[\033[00m\]\$ "
    
    

    这里:

  3. 保存并关闭文件,然后使更改生效:

source ~/.bashrc
  1. 设置conda红、用户名绿、主机名绿、文件夹蓝、git分支黄
PS1='\[\033[01;31m\]($(conda info --envs | grep "*" | cut -d " " -f1)) \[\033[01;32m\]\u@\h:\[\033[01;34m\]\w\[\033[00m\]$ '

2. 重新打开终端

重新打开终端,用户名和主机名将显示为白色,当前路径将显示为蓝色,而 Git 分支信息将以绿色显示在 $ 符号之前。

你可以将上述配置写入一个 .sh 文件,并通过执行该脚本来应用配置。以下是如何将这个配置写入 .sh 文件的步骤:

1. 创建 custom_prompt.sh 文件

  1. 在你的主目录或其他合适的位置创建一个 custom_prompt.sh 文件:

    nano ~/custom_prompt.sh
    
  2. 在文件中添加以下内容:

    #!/bin/bash
    
    # Git branch information
    parse_git_branch() {
        git branch 2>/dev/null | grep '*' | sed 's/* /(/' | sed 's/$/)/'
    }
    
    # Customize PS1 (Prompt String 1) to keep directory path colored and show Git branch before the $
    export PS1="\[\033[0;37m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[1;32m\]\$(parse_git_branch)\[\033[00m\]\$ "
    
  3. 保存并关闭文件。

2. 使 custom_prompt.sh 可执行

要使脚本可执行,运行以下命令: