git environment on mac os x

个人苹果电脑上的.bash_profile设置,主要是关于git的命令行提示和颜色配置。

export GREP_OPTIONS='--color=auto'export GREP_COLOR='1;35;40'export CLICOLOR=1export LSCOLORS=GxFxCxDxBxegedabagacedalias ll='ls -la'# export JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF-8# export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)# git command completionsource /Applications/Xcode.app/Contents/Developer/usr/share/git-core/git-completion.bashsource /Applications/Xcode.app/Contents/Developer/usr/share/git-core/git-prompt.shexport PS1="\u@\W\[\033[35m\]\$(git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/')\[\033[00m\] \[\033[1;32m\]\[\033[00m\] "

PS1中的命令部分不要提到function里,否则使用screen命令会提示方法找不到。

如果不安装Xcode,可以通过brew命令安装,也可以达到相同的效果,按照安装完成的提示相应设置即可:

 brew install git bash-completion

个人的git全局配置文件~/.gitconfig的内容:

[user]    name = yu    email = test@gmail.com[push]    default = simple[core]    editor = vim    quotepath = false[color]    diff = auto    status = auto    branch = auto[color "branch"]    current = yellow reverse    local = yellow    remote = green[color "diff"]    meta = yellow bold    frag = magenta bold    old = red bold    new = green bold[color "status"]    added = yellow    changed = green    untracked = red[format]    pretty = %C(yellow)%h %C(green)| %C(red)%ad %C(green)| %C(magenta)%>(12,trunc)%an %C(green)| %C(green)%d %C(reset)%s[log]    date = iso

References

  1. Creating a Happy Git Environment on OS X
  2. Add Git Branch Name to Terminal Prompt (Mac)
  3. How To Setup Git Completion And Repo State On Osx
  4. git-prompt.sh
  5. table for 16-color terminal escape sequences
  6. Bash prompt basics
  7. git log containing author and date