美文网首页
iTerm2自定义配色+显示分支

iTerm2自定义配色+显示分支

作者: 爱迪生的小跟班 | 来源:发表于2018-10-09 15:39 被阅读0次

开发中Mac中的终端使用不可或缺,然鹅~使用iTerm2代替Mac自带的Termial是个不错的选择。
iTetm2可以自定义配色,并且可以显示分支


可见图中配色以及显示git分支.png

iTerm2下载:https://iterm2.com
安装后可以打开设置进行自定义配色:

自定义配色.png

更多配色方案可以下载人家的配色方案再导入;配色方案下载:https://github.com/mbadolato/iTerm2-Color-Schemes

导入配色方案.png 选择下载好的文件,选择open.png

这时候就可以在配色方案中选择更多配色效果了~

如何显示分支?

修改 /etc/profile/ 文件,将下面内容写入profile文件中保存:

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[$white@$green\h$white:$cyan\W$yellow\$git_branch$white]\$ $normal"

注意:可能由于profile文件没有写入权限,此时可以从“finder”中进入修改profile文件。

此时,打开item2可以看到图一的效果了。有了配色不再只有孤独的黑白色,也有了显示分支(图一效果),更明了了~

OK,感谢您的阅读~ 祝生活愉快!😁

相关文章

网友评论

      本文标题:iTerm2自定义配色+显示分支

      本文链接:https://www.haomeiwen.com/subject/wvzeaftx.html