MacBook设置终端颜色,补全忽略大小写,设置命令别名alias,设置vim,设置显示git分支

一、启用终端颜色linux

修改配置文件
$ vim .bash_profile

#enables colorin the terminal bash shell export
export CLICOLOR=1

#sets up thecolor scheme for list export
export LSCOLORS=gxfxcxdxbxegedabagacad

#sets up theprompt color (currently a green similar to linux terminal)
export PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;36m\]\w\[\033[00m\]\$ '

#enables colorfor iTerm
export TERM=xterm-color

载入配置
$ source .bash_profile

其中LSCOLORS的值表示的含义以下:git

a       black
b       red
c       green
d       brown
e       blue
f       magenta
g       cyan
h       light grey
A       bold black, usually shows up as dark grey
B       bold red
C       bold green
D       bold brown, usually shows up as yellow
E       bold blue
F       bold magenta
G       bold cyan
H       bold light grey; looks like bright white
x       default foreground or background

文件类型:
1. directory
2. symbolic link
3. socket
4. pipe
5. executable
6. block special
7. character special
8. executable with setuid bit set
9. executable with setgid bit set
10. directory writable to others, with sticky bit
11. directory writable to others, without sticky

这里设置的值 gxfxaxdxcxegedabagacad 每两个字符表示一种文件类型的前景色和背景色。
因此对照这张表就能够知道,这里 directory 的前景色为 g(cyan),背景色为 x(default)。

二、系统自带的目录都是以大写开头,切换起来不是很方便,要是补全能忽略大小写就方便不少了。shell

在家目录下新建.inputrc文件
$ vim .inputrc

set completion-ignore-case on
set show-all-if-ambiguous on
TAB: menu-complete

这里直接载入会报错,须要重启终端生效。

三、mac系统没有自带ll命令别名,这应该是最经常使用的命令了,必须加上。vim

$ vim .bash_profile

#alias
alias ll="ls -lG"

$ source .bash_profile

四、设置vim,启用语法高亮bash

$ vim .vimrc

syntax on          #启用语法高亮
set ruler          #启用标尺,即显示光标当前位置的坐标

五、设置显示git分支,其实在这一点上zsh能够实现很是强大的git提示功能,这里只是显示分支名。socket

$ vim .bash_profile

#display git branch in PS1
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="$green\u$white@$green\h:$cyan\w$yellow\$git_branch$normal\$ "

$ source .bash_profile

设置完后效果以下ui

相关文章
相关标签/搜索