本文使用最简单的方法配置iterm2终端颜色,仅需修改~/.bash_profile文件
切换为bash
安装iterm2后默认是bash,注意bash才能设置颜色,mac自带的zsh不行。
切换bash命令:
chsh -s /bin/bash
如果你想看看自己的机子上装了哪些shell,可以使用如下命令:
cat /etc/shells
/bin/bash /bin/csh /bin/ksh /bin/sh /bin/tcsh /bin/zsh
配置bash_profile
修改文件:
vi ~/.bash_profile
alias cls='tput reset' alias egrep='egrep -G' alias fgrep='fgrep -G' alias grep='grep -G' alias l.='ls -d .* -G' alias ll='ls -la -G' alias la='ls -a -G' alias ls='ls -G' alias vi='vim' #alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde' export CLICOLOR=1 export LSCOLORS=gxfxaxdxcxegedabagacad 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" 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[$magentau$white@$greenh$white:$cyanw$yellow$git_branch$white]$ $normal" export GOPATH=/Users/your_dir/go export PATH=$GOPATH/bin:$PATH
重新打开终端即可看到颜色。
颜色自定义
参考文章修改颜色:MAC+iTerm定制目录显示颜色和提示符
