晒 bashrc

sh/bash/dash/ksh/zsh等Shell脚本
回复
头像
自由建客
帖子: 13468
注册时间: 2008-07-30 23:21
系统: Debian stable AMD64

晒 bashrc

#1

帖子 自由建客 » 2010-10-21 23:07

代码: 全选

if [ -z "$DISPLAY" ]; then
	export LANG=en_US.UTF-8
	PS1='\n\[\e[1m\e[4m\]>$?<\[\e[0m\] \W\$ '
else
	PS1='\n\[\e]2;\u@\h\a\]\[\e[1m\e[4m\]>$?<\[\e[0m\] \W\$ '
fi
set -o ignoreeof
set -o vi
alias ls="ls -F"
xihe
帖子: 28
注册时间: 2007-03-07 19:07

Re: 晒 bashrc

#2

帖子 xihe » 2010-10-21 23:11

代码: 全选

#!/bin/bash
alias fbterm='LANG=zh_CN.UTF-8 LC_ALL=zh_CN.UTF-8 fbterm -i fbterm_ucimf'
if [[ -z "$DISPLAY"  &&  $(tty) == /dev/tty1 ]]; then
	LANG=zh_CN.UTF-8 LC_ALL=zh_CN.UTF-8 exec fbterm -i fbterm_ucimf
fi

#alias ls='ls -F --color=auto'
alias ls='ls --color=auto'
alias ll='ls -lh'
alias la='ls -d .*'
alias lla='ls -lha'
alias grep='grep --color=auto'
alias sdcv='sdcv -n -u 朗道英汉字典5.0 -u 朗道汉英字典5.0 -u 计算机词汇'
#alias 囗囗囗='ssh -CfNg -D 127.0.0.1:7777 -l gezidi constantine.dreamhost.com'

shopt -s cdspell

#alias ..="cd .."
#alias ..2="cd ../.."
#alias ..3="cd ../../.."
#alias ..4="cd ../../../.."
#alias ..5="cd ../../../../.."
alias ..="cd .."
alias ...="cd ../.."
alias ....="cd ../../.."
alias .....="cd ../../../.."
alias ......="cd ../../../../.."

alias vg="vim --servername gdbvim"
alias mk="make -j4"

if [[  "$TERM" == "linux" || "$TERM" == "xterm-256color" ]]
then
		PS1="\[\e[36;1m\]\u\[\e[34;1m\]@\[\e[32;1m\]\H\[\e[30;1m\](\j)\[\e[33;1m\]\W\[\033k\033\134\] \$ \[\e[0m\]"
else
		PS1="\[\e]2;\u@\H \w\a\e[32;1m\]\$\[\e[0m\] "
fi
#export PROMPT_COMMAND="echo -ne `date`" 
#if [[ $TERM != "linux" ]];then
	export TERM="xterm-256color"
#fi


#.$HOME/bin/chs_completion

. $HOME/.colors

delectate
帖子: 18311
注册时间: 2008-01-09 22:41

Re: 晒 bashrc

#3

帖子 delectate » 2010-10-21 23:17

一团

[bash]delectate@delectate:~$ cat ./.bashrc

# Check for an interactive session
# If not running interactively, don't do anything
[ -z "$PS1" ] && return

#alias ls='ls --color=auto'
#PS1='[\u@\h \W]\$ '


LC_CTYPE=en_US.utf8
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples

# If not running interactively, don't do anything
[ -z "$PS1" ] && return

# don't put duplicate lines in the history. See bash(1) for more options
# don't overwrite GNU Midnight Commander's setting of `ignorespace'.
export HISTCONTROL=$HISTCONTROL${HISTCONTROL+,}ignoredups
# ... or force ignoredups and ignorespace
export HISTCONTROL=ignoreboth

# append to the history file, don't overwrite it
shopt -s histappend

# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)

# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize

# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"

# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi

# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
xterm-color) color_prompt=yes;;
esac

# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
#force_color_prompt=yes

if [ -n "$force_color_prompt" ]; then
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
# We have color support; assume it's compliant with Ecma-48
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
# a case would tend to support setf rather than setaf.)
color_prompt=yes
else
color_prompt=
fi
fi

if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
# PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
fi
unset color_prompt force_color_prompt

# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
;;
*)
;;
esac

# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

#if [ -f ~/.bash_aliases ]; then
# . ~/.bash_aliases
#fi

# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
#eval "`dircolors -b`"
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
alias ls='ls --color=auto'
#alias dir='dir --color=auto'
#alias vdir='vdir --color=auto'

alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
fi

# some more ls aliases
alias ll='ls -l'
#alias la='ls -A'
#alias l='ls -CF'

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi


# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi



alias modeA1="sudo cp /etc/usb_modeswitchA1 /etc/usb_modeswitch.conf"
alias mode09="sudo cp /etc/usb_modeswitch09 /etc/usb_modeswitch.conf"
alias modeSet="sudo usb_modeswitch -W"
alias wdiAL="sudo wvdial"
alias vpnstart="sudo /etc/rc.d/openvpn start"
alias vpnstop="sudo /etc/rc.d/openvpn stop"
alias setDns="sudo cp /etc/resolv.conf.dns /etc/resolv.conf"
alias rm="rm -i"
alias ipv6stop="sudo /etc/rc.d/miredo stop"
alias ipv6start="sudo /etc/rc.d/miredo start"
alias sduo="sudo"


### chsdir start ###
. /usr/bin/chddir/bin/chs_completion
PATH=$PATH:/usr/bin/chddir/bin
#export CHSDIR="{'n':'l'}"
### chsdir finish. ###


export GTK_IM_MODULE=ibus
export XMODIFIERS=@im=ibus
export QT_IM_MODULE=ibus
[/bash]
renzaoren615
帖子: 58
注册时间: 2009-08-18 19:17

Re: 晒 bashrc

#4

帖子 renzaoren615 » 2010-10-22 3:06

很不错,参考了 :em11
头像
fanhe
帖子: 2357
注册时间: 2007-03-24 23:45

Re: 晒 bashrc

#5

帖子 fanhe » 2010-10-22 22:16

就几个alias,几个自定义函数,把ps1改成彩色
没了
一般都是喜欢自己加,不喜欢把看不明白的一通加进去

默认就好
tusooa
帖子: 6548
注册时间: 2008-10-31 22:12
系统: 践兔
联系:

Re: 晒 bashrc

#6

帖子 tusooa » 2010-10-24 9:22

代码: 全选

tlcr: 0 庚寅年九月十七日 9:15 ~ 
● dog ~/.zshrc
#color{{{
autoload colors 
colors

for color in RED GREEN YELLOW BLUE MAGENTA CYAN WHITE; do
eval _$color='%{$terminfo[bold]$fg[${(L)color}]%}'
eval $color='%{$fg[${(L)color}]%}'
eval bg_$color='%{$bg[${(L)color}]%}'
(( count = $count + 1 ))
done
FINISH="%{$terminfo[sgr0]%}"

#}}}

#命令提示符 {{{
#RPROMPT=$(echo "$RED%D %T$FINISH")
#PROMPT=$(echo "$BLUE%M$GREEN%/
#$CYAN%n $_YELLOW>>>$FINISH ")
#}}}
#标题栏、任务栏样式{{{
#case $TERM in 
#       (*xterm*|*rxvt*|(dt|k|E)term)
#   precmd () { print -Pn "\e]0;%n@%M//%/\a" }
#   preexec () { print -Pn "\e]0;%n@%M//%/\ $1\a" }
#   ;;
#esac
#}}}

#关于历史纪录的配置 {{{
#历史纪录条目数量
export HISTSIZE=100000
#注销后保存的历史纪录条目数量
export SAVEHIST=100000
#历史纪录文件
export HISTFILE=~/.zhistory
#以附加的方式写入历史纪录
setopt INC_APPEND_HISTORY
#如果连续输入的命令相同,历史纪录中只保留一个
setopt HIST_IGNORE_DUPS      
#为历史纪录中的命令添加时间戳      
setopt EXTENDED_HISTORY      

#启用 cd 命令的历史纪录,cd -[TAB]进入历史路径
setopt AUTO_PUSHD
#相同的历史路径只保留一个
setopt PUSHD_IGNORE_DUPS

#在命令前添加空格,不将此命令添加到纪录文件中
#setopt HIST_IGNORE_SPACE      
#}}}

#每个目录使用独立的历史纪录{{{
#cd() {
#    builtin cd "$@"                             # do actual cd
#    fc -W                                       # write current history  file
#    local HISTDIR="$HOME/.zsh_history$PWD"      # use nested folders for history
#        if  [ ! -d "$HISTDIR" ] ; then          # create folder if needed
#            mkdir -p "$HISTDIR"
#        fi
#        export HISTFILE="$HISTDIR/zhistory"     # set new history file
#    touch $HISTFILE
#    local ohistsize=$HISTSIZE
#        HISTSIZE=0                              # Discard previous dir's history
#        HISTSIZE=$ohistsize                     # Prepare for new dir's history
#    fc -R                                       #read from current histfile
#}
#mkdir -p $HOME/.zsh_history$PWD
#export HISTFILE="$HOME/.zsh_history$PWD/zhistory"
export HISTFILE="$HOME/.zhistory"
#function convhistory {
#            sort $1 | uniq |
#            sed 's/^:\([ 0-9]*\):[0-9]*;\(.*\)/\1::::::\2/' |
#            awk -F"::::::" '{ $1=strftime("%Y-%m-%d %T",$1) "|"; print }'  
#}
#使用 histall 命令查看全部历史纪录
#function histall { convhistory =(allhistory) |
#              sed '/^.\{20\} *cd/i\\' }
#使用 hist 查看当前目录历史纪录
#function hist { convhistory $HISTFILE }

#全部历史纪录 top44
function top44 { dog "$HISTFILE" | awk -F':[ 0-9]*:[0-9]*;' '{ $1="" ; print }' | sed 's/ /\n/g' | sed '/^$/d' | sort | uniq -c | sort -nr | head -n 44 }

#}}}

#杂项 {{{
#允许在交互模式中使用注释  例如:
#cmd #这是注释
setopt INTERACTIVE_COMMENTS      
      
#启用自动 cd,输入目录名回车进入目录
#稍微有点混乱,不如 cd 补全实用
#setopt AUTO_CD
      
#扩展路径
#/v/c/p/p => /var/cache/pacman/pkg
setopt complete_in_word
      
#禁用 core dumps
limit coredumpsize 0

#Emacs风格 键绑定
bindkey -e
#设置 [DEL]键 为向后删除
bindkey "\e[3~" delete-char

#以下字符视为单词的一部分
WORDCHARS='*?_-[]~=&;!#$%^(){}<>'

# 不显示bad pattern的信息。
unsetopt badpattern
# 自动更正命令
setopt correct
#}}}


#自动补全功能
. ~/.zsh/complete

##空行(光标在行首)补全 "cd " {{{
user-complete(){
    case $BUFFER in
        "" )                       # 空行填入 "cd "
            BUFFER="cd "
            zle end-of-line
            ;;
        "cd --" )                  # "cd --" 替换为 "cd +"
            BUFFER="cd +"
            zle end-of-line
            ;;
        "cd +-" )                  # "cd +-" 替换为 "cd -"
            BUFFER="cd -"
            zle end-of-line
            ;;
    esac
    zle expand-or-complete
}
zle -N user-complete
bindkey "\t" user-complete
#}}}

##在命令前插入 sudo {{{
#定义功能 
sudo-command-line() {
    [[ -z $BUFFER ]] && zle up-history
    [[ $BUFFER != sudo\ * ]] && BUFFER="sudo $BUFFER"
    zle end-of-line                 #光标移动到行末
}
zle -N sudo-command-line
#定义快捷键为: [Esc] [Esc]
bindkey "\e\e" sudo-command-line
#}}}
  
#命令别名 {{{
#alias -g rm='RemoveFile'
alias ls='ls -h --color=always -X '
#alias l='ls-l -h --color=always -X --time-style="+[%Y-%m-%d %k:%M]"'
alias l='ls -l'
alias sed='sed -r'
alias make=ColorMake
alias grep='egrep'
alias egrep="GREP_COLOR=\"\$(echo 3\$[\$(date +%N)%6+1]';1;4;40')\" egrep --color=always"
alias less='less -R'
alias df='df -Th'
alias du='du -h'
alias a=awk
alias s=sed
alias p=less
#alias g=grep
alias showip='curl ifconfig.me' # 显示计算机外网ip
alias irssi='Irssi-Alias'
#alias vim='screen -c $HOME/.screenrc-vim vim'
alias emacs='env DISPLAY= emacs'
alias \$=''

# 后缀别名
alias -g A='|awk'
alias -g L='|less'
alias -g P='|perl'
alias -g G="|g"
alias -g S='|sed'
alias -g B='S "s@\x1B\[[0-9;]*[mK]@@g"'

#[Esc][h] man 当前命令时,显示简短说明 
alias run-help >&/dev/null && unalias run-help
autoload run-help

#历史命令 top10
#alias top10='print -l  ${(o)history%% *} | uniq -c | sort -nr | head -n 10'
top10(){ history 0 | awk '{CMD[$2]++;count++;}END { for (a in CMD)print CMD[a] " " CMD[a]/count*100 "% " a;}' | grep -v "./" | column -c3 -s " " -t | sort -nr | nl | head -n10 }
# Screen Aliases
if [ "$TERM" = screen ] ; then
    alias mutt='screen -t email mutt'
    alias irssi='screen -t chat Irssi-Alias'
fi
#}}}

#路径别名 {{{
#进入相应的路径时只要 cd ~xxx
hash -d dw="$HOME/个人/下载"
hash -d scripts="$HOME/应用/脚本"
hash -d games="$HOME/应用/脚本/游戏"
hash -d tslinux="$HOME/应用/TusooaLinux"
hash -d apps="$HOME/应用/源码/GitHub/tusooa/Apps"
#}}}
    
##for Emacs {{{
#在 Emacs终端 中使用 Zsh 的一些设置 不推荐在 Emacs 中使用它
if [[ "$TERM" == "dumb" ]]; then
setopt No_zle
PROMPT='%n@%M %/
>>'
alias ls='ls -F'
fi      
#}}}

#{{{ F1 计算器
arith-eval-echo() {
  LBUFFER="${LBUFFER}echo \$(( "
  RBUFFER=" ))$RBUFFER"
}
zle -N arith-eval-echo
bindkey "^[[11~" arith-eval-echo
#}}}

####{{{
function timeconv { date -d @$1 +"%Y-%m-%d %T" }

# }}}

# vim:filetype=zsh foldmethod=marker autoindent expandtab shiftwidth=4

# PATHs manager

pathappend()
{
        local dir="$1" pathvar="$2"
        [ -z "$pathdir" ] && pathvar="PATH"
        [ -d "$dir" ] &&
        {
                #eval "in_arg_list_PATH \"$dir\" \"\$$pathvar\"" ||
                eval "$pathvar=\"\$$pathvar\${$pathvar+:}$dir\""
        }
}

pathprepend()
{
        local dir="$1" pathvar="$2"
        [ -z "$pathdir" ] && pathvar="PATH"
        [ -d "$dir" ] && 
        {
                #eval "in_arg_list_PATH \"$dir\" \"\$$pathvar\"" ||
                eval "$pathvar=\"$dir\${$pathvar+:\$$pathvar}\""
        }
}

PKG_CONFIG_PATH="/usr/lib/pkgconfig:/usr/local/lib/pkgconfig"

# Sbin
pathappend /sbin
pathappend /usr/sbin

# Tusooa Tree
pathprepend "$HOME/应用/脚本"
pathprepend "$HOME/应用/脚本/游戏"
pathprepend "$HOME/应用/二进制"

# scripts-eexp
pathprepend "$HOME/应用/脚本/scripts-eexp"

# scripts-bones
pathprepend "$HOME/应用/脚本/scripts-bones"

# scripts-xiooli
pathprepend "$HOME/应用/脚本/scripts-xiooli"

# Opera
#pathprepend "/opt/opera/bin"
#pathprepend "/opt/opera/share/man" MANPATH

. ~/.zsh/distro

# Install File
pathprepend "$HOME/应用/链接/Executables"
#pathappend "$HOME/应用/安装/库/pkgconfig" PKG_CONFIG_PATH
#pathappend "$HOME/应用/安装/库" LD_LIBRARY_PATH
pathprepend "$HOME/应用/链接/Libraries" LD_LIBRARY_PATH
pathprepend "$HOME/应用/链接/Libraries/pkgconfig" PKG_CONFIG_PATH

# Compile-Program
pathprepend "$HOME/应用/源码/gcode-svn/compile-program"

if distro arch ; then
# Pacman

pacman()
{
    if [ -x '/usr/bin/powerpill' ] ; then
            sudo powerpill "$@"
    elif [ -x '/usr/bin/pacman-color' ] ; then
            sudo /usr/bin/pacman-color "$@"
    else
            sudo /usr/bin/pacman  "$@"
    fi
    local var
    [ "$(echo "$@" | grep Sy)" ] || return 0
    print -Pn "${_BLUE}::${FINISH} ${_WHITE}Do you want to upgrade the programs list?[Y/n]${FINISH} \n"
        read var
        case $var in 
            ([Yy]|"") ;;
            (*) return ;;
        esac
        sudo pacfile -S
        mkdir -p $HOME/.share/
        pacfile 'bin/[^\/]+$' > $HOME/.share/programsList && echo "programs list is up to date"
}

yaourt()
{
    /usr/bin/yaourt "$@"
    local var
    [ "$(echo "$@" | grep Sy)" ] || return 0
    print -Pn "${_BLUE}::${FINISH} ${_WHITE}Do you want to upgrade the programs list?[Y/n]${FINISH} \n"
        read var
        case $var in 
            ([Yy]|"") ;;
            (*) return ;;
        esac
        sudo pacfile -S
        mkdir -p $HOME/.share/
        pacfile 'bin/[^\/]+$' > $HOME/.share/programsList && echo "programs list is up to date"
}

srcpac()
{
    sudo srcpac "$@"
    local var
    [ "$(echo "$@" | grep Sy)" ] || return 0
    print -Pn "${_BLUE}::${FINISH} ${_WHITE}Do you want to upgrade the programs list?[Y/n]${FINISH} \n"
        read var
        case $var in 
            ([Yy]|"") ;;
            (*) return ;;
        esac
        sudo pacfile -S
        mkdir -p $HOME/.share/
        pacfile 'bin/[^\/]+$' > $HOME/.share/programsList && echo "programs list is up to date"
}

elif distro ubuntu ; then
apt-file()
{
    sudo apt-file "$@"
    if [ "$1" = update ] ; then
        sudo apt-file search bin/ > "$HOME/.share/programsList"
    fi
}
fi

command_not_found_handler() {
    local l="$(grep /$1$ < $HOME/.share/programsList)"
    if [ "$l" ]; then
        echo "下列软件包含有命令 $1 :"
        echo "$l" | awk '{print "\033[0;1;32m" $1 "\t\t\033[31m /" $2}'
    else
        echo "未搜索到含有命令 $1 的软件包"
    fi
    return 127
}

export EDITOR='vim' PACKAGER='[email protected]'

export RM_DESTDIR="$HOME/.del"
rm()
{
    local dest file i
    mkdir -p $RM_DESTDIR
    while [ $# -gt 0 ]
    do
        case "$1" in 
        -*)
            shift
        ;;
        *)
            [ -z "$1" ] && continue
            case "$1" in
                /*)file=$1;;
                *)file=$PWD/$1;;
            esac
            i=0
            dest=$((i++))-$(basename $file)
            while [ -f "$RM_DESTDIR/$dest" ] || [ -d "$RM_DESTDIR/$dest" ]; do
                dest=$((i++))-$(basename $file)
            done
            mv "$file" "$RM_DESTDIR/$dest"
            cat >> $HOME/.rm << EOF
Source:$file
Dest:$dest
EOF
            shift
        ;;
        esac
    done
}

export FCDWDIR="$HOME/个人/下载/full circle"

# 输入法
export XMODIFIERS="@im=fcitx"
export QT_IM_MODULE=xim GTK_IM_MODULE=xim
export XIM=fcitx XIM_PROGRAM=fcitx
#export XMODIFIERS=@im=SCIM
#export GTK_IM_MODULE="scim"
#export QT_IM_MODULE="scim"

mkcd()
{
    mkdir -p "$1" && cd "$1"
}

# Python
# 太烦了!居然有这么长的路径。
export PYTHONPATH2="$HOME/应用/库/脚本"

# 笨兔就是烦!
distro ubuntu &&
export PYTHONPATH2="$PYTHONPATH2:$HOME/应用/链接/Libraries/python2.6:$HOME/应用/链接/Libraries/python2.6/site-packages/gtk-2.0"

export PYTHONPATH3="$HOME/应用/库/脚本/Py3k"
. ~/.zsh/python

# LANG
if [[ $TERM = linux ]] ; then
        LANG=en_US.UTF-8
else
        LANG=zh_CN.UTF-8
fi

#autoload -U promptinit
#promptinit
#prompt adam2

NOCOL=$'%{\e[0m%}'

tlcr-check()
{
    local ret="$?"
    if [[ $ret = 0 ]] ; then
        echo -n "${_GREEN}tlcr: $ret${NOCOL}"
    else
        echo -n "${_RED}tlcr: $ret${NOCOL}"
    fi
}

date-now()
{
    echo -n "${_BLUE}$(lc-农历.perl -s 2>/dev/null) %T"
}

# Git
get_git_status () {
        unset __CURRENT_GIT_BRANCH
        unset __CURRENT_GIT_BRANCH_STATUS
        unset __CURRENT_GIT_BRANCH_IS_DIRTY
        [[ "$PWD" = "$HOME" ]] && return
        local dir=$(git rev-parse --git-dir 2>/dev/null)
        [[ "${dir:h}" = "$HOME" ]] && return
        local st="$(git status 2>/dev/null)"
        if [[ -n "$st" ]]
        then
                local -a arr
                arr=(${(f)st}) 
                if [[ $arr[1] =~ 'Not currently on any branch.' ]]
                then
                        __CURRENT_GIT_BRANCH='no-branch' 
                else
                        __CURRENT_GIT_BRANCH="${arr[1][(w)4]}" 
                fi
                if [[ $arr[2] =~ 'Your branch is' ]]
                then
                        if [[ $arr[2] =~ 'ahead' ]]
                        then
                                __CURRENT_GIT_BRANCH_STATUS='ahead' 
                        elif [[ $arr[2] =~ 'diverged' ]]
                        then
                                __CURRENT_GIT_BRANCH_STATUS='diverged' 
                        else
                                __CURRENT_GIT_BRANCH_STATUS='behind' 
                        fi
                fi
                [[ ! $st =~ "nothing (added )?to commit" ]] && __CURRENT_GIT_BRANCH_IS_DIRTY='1' 
        fi
        return 0
}

get_prompt_git () {
        if [[ -n $__CURRENT_GIT_BRANCH ]]
        then
                local s=$__CURRENT_GIT_BRANCH
                case "$__CURRENT_GIT_BRANCH_STATUS" in
                        (ahead) s+="+"  ;;
                        (diverged) s+="="  ;;
                        (behind) s+="-"  ;;
                esac
                [[ $__CURRENT_GIT_BRANCH_IS_DIRTY = '1' ]] && s+="*" 
                echo " ${bg_WHITE}${RED}$s${NOCOL}"
        fi
}

git_branch_chpwd () {
        get_git_status
        return 0
}

git_branch_precmd () {
        [[ "$(fc -l -1)" = *git* ]] && get_git_status
        return 0
}

setopt promptsubst

PROMPT="${NOCOL}\$(tlcr-check) \$(date-now) \$_prompt_pwd \$(get_prompt_git)
${WHITE}${bg_GREEN}●$NOCOL "
PROMPT2="${RED}%_${_GREEN} >>>$NOCOL "
pwd_color_chpwd()
{
    [[ $PWD = $OLDPWD ]] || _prompt_pwd="${_CYAN}$bg_MAGENTA%~$NOCOL"
}
pwd_color_preexec()
{
    _prompt_pwd="${_WHITE}${bg_MAGENTA}%~$NOCOL"
}
_prompt_pwd="${_WHITE}$bg_MAGENTA%~$NOCOL"
#RPROMPT="\$_prompt_pwd"
SPROMPT="${_YELLOW}Tip${NOCOL}: Correct ${_RED}%R${NOCOL} to ${_GREEN}%r${NOCOL} ? [${_CYAN}N${NOCOL}]o/[${_CYAN}Y${NOCOL}]es/[${_CYAN}E${NOCOL}]dit/[${_CYAN}A${NOCOL}]bort ${_YELLOW}=>${NOCOL} "
export SUDO_PROMPT=$'[\e[5;31msudo\e[0m] password for \e[1;33m%p\e[0m:'

preexec_functions=(pwd_color_preexec)
precmd_functions=(git_branch_precmd)
chpwd_functions=(pwd_color_chpwd git_branch_chpwd)

precmd_增强()
{
    local ret="$?" datenow
    datenow="$(lc-农历.perl -s 2>/dev/null) $(date +%T)"
    
    PROMPT="%{%}tlcr: ${ret} \${datenow} %~%{%}
%{%}●%{%} "
    [ "$TERM" != linux ] && print -Pn "%{\e]2;term $cwd\a%}" || true
    #print -Pn "%{\ekzsh\e\\%}"
}

precmd_right()
{
COL=$(stty size | awk '{print $2}')
PROMPT="${_YELLOW}/-- ${_CYAN}tlcr: $? $(lc-农历.perl -s 2>/dev/null) $(date +%T) ${_YELLOW}"
((COL = $COL - 10))
local PLEN=${#PROMPT}
PLEN=$[PLEN-39]
while [[ $PLEN < $COL ]] ; do
PROMPT+='-'
PLEN=$[PLEN+1]
done
PROMPT+=$(echo "\\ ${_YELLOW}\\->${NOCOL} ") #%{\e[0;1;42m%}●%{\e[0m} '
RPROMPT="${_MAGENTA}%~ ${_YELLOW}--/${NOCOL}"

}

# preexec()
#{
#    # 其实对于不带标题的Fvwm没有什么作用
#    [ "$TERM" != linux ] && print -Pn "${NOCOL}%{\e]2;$1 $(pwd | sed -e "s#^$HOME#\~#")\a%}" || true
#}

# preexec()
#{
#    # 自动更换screen标题
#    print -Pn "%{\ek$1\e\\%}"
#}

precmd_简单()
{
    PROMPT="%K{green}%B%F{white}>>%b%f%k "
    [ "$TERM" != linux ] && print -Pn "%{\e]2;term $cwd\a%}" || true
}

sp()
{
    precmd(){ precmd_简单; }
}

rep()
{
    precmd(){ precmd_right; }
}
ep() { precmd() { precmd_增强; } }


#[ "$TERM" = linux ] && sp || ep
bin-exist() {[[ -x `whence -cp $1 2>/dev/null` ]]}
# less
#MOST like colored man pages
export PAGER=less
export LESS_TERMCAP_md=$'\E[1;31m' #bold1
export LESS_TERMCAP_mb=$'\E[1;31m'
export LESS_TERMCAP_me=$'\E[m'
export LESS_TERMCAP_so=$'\E[01;44;33m' #search highlight
export LESS_TERMCAP_se=$'\E[m'
export LESS_TERMCAP_us=$'\E[1;2;32m' #bold2
export LESS_TERMCAP_ue=$'\E[m'
export LESS="-M -i -R --shift 5"
export LESSCHARSET=utf-8
export READNULLCMD=less
# In archlinux the pipe script is in PATH, how ever in debian it is not
(bin-exist src-hilite-lesspipe.sh) && export LESSOPEN="| src-hilite-lesspipe.sh %s"
[ -x /usr/share/source-highlight/src-hilite-lesspipe.sh ] && export LESSOPEN="| /usr/share/source-highlight/src-hilite-lesspipe.sh %s" || :

# Glob匹配失败的时候使用原来内容,不报错
setopt nonomatch

# Tips
. ~/.zsh/tips-"$(distro)"
. ~/.zsh/tips

# clean up
typeset -U PATH
export PATH
export PKG_CONFIG_PATH
export LD_LIBRARY_PATH

if [ "" ] ; then
# 高亮
TOKENS_FOLLOWED_BY_COMMANDS=('|' '||' ';' '&' '&&' 'sudo' 'do' 'time' 'strace' 'builtin' 'command' '$' 'env' 'type' 'which' 'whence')
if [ 'x' ] ; then
recolor-cmd()
{
    region_highlight=()
    state=1
    offset=0
#    start_pos=0
    for arg in ${(z)BUFFER}; do
        #((start_pos+=${#BUFFER[$start_pos+1,-1]}-${#${BUFFER[$start_pos+1,-1]## #}}))
        #if [[ $state = 1 ]] ; then
        #    color=$(color_cmd "$arg")
        #    state=2
        #elif [[ $state = 2 ]] ; then
        #    color=$(color_arg "$arg")
        #fi
        #((end_pos=$start_pos+${#arg}))
        if [[ $state = 1 ]]; then
            state=2
            res=$(LC_ALL=C builtin type "$arg" 2>/dev/null)
            case $res in
                *'reserved word'*)   style="fg=magenta,bold";;
                *'alias for'*)       style="fg=cyan,bold";;                   
                *'shell builtin'*)   style="fg=yellow,bold";;
                *'shell function'*)  style='fg=green,bold';;
                *"$arg is"*)
                    [[ $arg = 'sudo' ]] && style="fg=red,bold" || style="fg=blue,bold";;
                *)                   style='none,bold';;
            esac
        #if [ "$color" ] ; then    
        #    region_highlight+=("$offset $((${#cmd}+offset)) fg=${color},bold")
        #else
        #    region_highlight+=("$offset $((${#cmd}+offset)) fg=blue,bold")
        #fi
        #else
        #    case "$arg" in
        #       --*)
        #           style="fg=magenta,bold";;
        #       -*)style="fg=yellow,bold";;
        #       *)style="fg=red,bold";;
        #    esac
        fi
        region_highlight+=("$offset "$((${#cmd}+offset))" $style")
        offset=$((offset+${#cmd}+1))
        [[ ${${TOKENS_FOLLOWED_BY_COMMANDS[(r)${arg//|/\|}]}:+yes} = 'yes' ]] && state=1
        #start_pos=$[end_pos+1]
    done
}
fi

if [ '' ] ; then
recolor-cmd() {
    #region_highlight=()
    colorize=true
    start_pos=0
    for arg in ${(z)BUFFER}; do
        ((start_pos+=${#BUFFER[$start_pos+1,-1]}-${#${BUFFER[$start_pos+1,-1]## #}}))
        ((end_pos=$start_pos+${#arg}))
        if $colorize; then
            colorize=false
            res=$(LC_ALL=C builtin type $arg 2>/dev/null)
            case $res in
                *'reserved word'*)   style="fg=magenta,bold";;
                *'alias for'*)       style="fg=cyan,bold";;
                *'shell builtin'*)   style="fg=yellow,bold";;
                *'shell function'*)  style='fg=green,bold';;
                *"$arg is"*)         
                    [[ $arg = 'sudo' ]] && style="fg=red,bold" || style="fg=blue,bold";;
                *)                   style='none,bold';;
            esac
            region_highlight+=("$start_pos $end_pos $style")
        fi
        [[ ${${TOKENS_FOLLOWED_BY_COMMANDS[(r)${arg//|/\|}]}:+yes} = 'yes' ]] && colorize=true
        start_pos=$[end_pos+]
    done
}
fi

# 语法高亮。
check-cmd-self-insert() { zle .self-insert && recolor-cmd }
zle -N self-insert check-cmd-self-insert
check-cmd-backward-delete-char() { zle .backward-delete-char && recolor-cmd; }
zle -N backward-delete-char check-cmd-backward-delete-char
check-cmd-delete-char() { RBUFFER="${RBUFFER#?}" && recolor-cmd; } 
zle -N delete-char check-cmd-delete-char                       
check-up-line-or-history() { zle .up-line-or-history && recolor-cmd ; }
zle -N up-line-or-history check-up-line-or-history
check-down-line-or-history() { zle .down-line-or-history && recolor-cmd; }
zle -N down-line-or-history check-down-line-or-history
fi

# Ctrl+@ 设置标记,标记和光标点之间为 region
colors=(green yellow cyan)
num=$[$RANDOM % ${#colors}]
color=${colors[(num-1) % ${#colors} +2]}
zle_highlight=(
    region:bg=magenta
    special:bold,fg=magenta # 特殊
    isearch:underline # ???
    default:bold,fg=$color # 输入
)
tlcr: 0 庚寅年九月十七日 9:17 ~ 
● 

代码: 全选

] ls -ld //
回复