关于文章 bash

bash find linux rm unix
bash git linux

linux bash显示git分支

linux bash显示git分支

在bashrc中加入

find_git_branch () {
  local dir=. head
  until [ "$dir" -ef / ]; do
    if [ -f "$dir/.git/HEAD" ]; then
      head=$(< "$dir/.git/HEAD")
      if [[ $head = ref:\ refs/heads/* ]]; then
        git_branch=" → ${head#*/*/}"
      elif [[ $head != '' ]]; then
        git_branch=" → (detached)"
      else
        git_branch=" → (unknow)"
      fi
      return
    fi
    dir="../$dir"
  done
  git_branch=''
}

PROMPT_COMMAND="find_git_branch; $PROMPT_COMMAND"
# Heree

black=$'\[\e[1;30m\]'

red=$'\[\e[1;31m\]'

green=$'\[\e[1;32m\]'

yellow=$'\[\e[1;33m\]'

blue=$'\[\e[1;34m\]'

magenta=$'\[\e[1;35m\]'

cyan=$'\[\e[1;36m\]'

white=$'\[\e[1;37m\]'

normal=$'\[\e[m\]'



PS1="$white[$magenta\u$white@$green\h$white:$cyan\w$yellow\$git_branch$white]\$ $normal"

然后

source .bashrc
bash comp linux 自动补全

bash开启自动补全

bash开启自动补全

linux bash开启自动补全

前提已经安装好了 bash-completion

在bashrc中加入

if [ -r /etc/bash_completion ]; then

  # Source completion code.

    . /etc/bash_completion

  fi

或者暴力一点

source /usr/share/bash-completion/bash_completion

然后

source .bashrc