iterm2配色方案
-
打开iterm的官方主题配置站 github.com/mbadolato/iTerm2-Color-Schemes,将资源下载至本地 , 解压。
-
打开 iTerm2
-
color presets 处选择import
打开刚下载解压好的文件夹,打开schemes 文件夹,全选那些配色方案,点open,这样就把所有的配色方案导入了
-
再去点击color presets ,就能选择刚刚导入的这些 配色方案了。
终端展示git分之名配置
bash版
- 因为10.15.x 默认使用的是 zsh 了 而不是 bash 了,所以需要执行以下命令切换
chsh -s /bin/bash
-
创建文件 ~/.bashrc;如果有进行编辑即可;也可以到全局配置/etc/profile下配置
执行编辑命令 vim ~/.bashrc ;/etc/profile 文件则 执行命令 sudo vim /etc/profile
我这里采用的是.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"
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 当然如果你编辑的是/etc/profile 则需要执行 source /etc/profile 让上面的内容立即生效
- idea终端不生效,这里原因同1,因为idea中用的还是zsh,需要更改为bash,关闭终端重新打开就好,如下图
zsh版
与bash版配置过程一样,只需要把脚本更换为下面这个 function内容也可用bash版的
autoload -U colors && colors;
function git_branch() {
branch="`git branch 2>/dev/null | grep "^\*" | sed -e "s/^\*\ //"`"
if [ "${branch}" != "" ];then
if [ "${branch}" = "(no branch)" ];then
branch="(`git rev-parse --short HEAD`...)"
fi
echo "(${branch})";
fi
}
function m32(){
echo "\e[01;32m";
}
function m36(){
echo "\e[01;36m";
}
function m0(){
echo "\e[0m";
}
function dir() {
echo "\e[01;36m$1~\e[0m";
}
PS1="%n@%m $(m36)%1~$(m0) $(m32)\$(git_branch)$(m0) \$ ";