How can I display the current branch and folder path in terminal?

前端 未结 13 1115
无人共我
无人共我 2020-12-04 07:09

I\'ve been watching some of the Team Treehouse videos and they have a very nice looking terminal when working with Git.

For example they have (something similar):

13条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-04 07:39

    Keep it fast, keep it simple

    put this in your ~/.bashrc file.

    git_stuff() {
      git_branch=$(git branch --show-current 2> /dev/null)
      if [[ $git_branch == "" ]];then
        echo -e ""
      elif [[ $git_branch == *"Nocommit"* ]];then
        echo -e "No commits"
      else
        echo -e "$git_branch"
      fi
    }
    prompt() {
      PS1="\e[2m$(date +%H:%M:%S.%3N) \e[4m$(git_stuff)\033[0m\n\w$ "
    }
    PROMPT_COMMAND=prompt
    

    Then source ~/.bashrc

提交回复
热议问题