分享一下我的:
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
MAIN_DEVICE=harvey
if test -f $HOME/.config/.dotfiles_main_device; then
MAIN_DEVICE=$HOSTNAME
fi
prompt_command() {
local last_ret=$?
history -a
# terminal tab title
local cwd="$PWD"
local title="${cwd/#$HOME/\~}"
if [ "$MAIN_DEVICE"x = "$HOSTNAME"x ] ; then
echo -n -e "\\e]0;$title\\007"
local HOST_FLAG=""
else
echo -n -e "\\e]0;$HOSTNAME > $title\\007"
local HOST_FLAG="${COLOR_YELLOW}\h${COLOR_NOCOLOR} "
fi
export COLOR_NOCOLOR='\[\e[0m\]'
export COLOR_RED='\[\e[0;31m\]'
export COLOR_GREEN='\[\e[0;32m\]'
export COLOR_ORANGE='\[\e[0;33m\]'
export COLOR_BLUE='\[\e[0;34m\]'
export COLOR_PURPLE='\[\e[0;35m\]'
export COLOR_CYAN='\[\e[0;36m\]'
export COLOR_WHITE='\[\e[0;37m\]'
export COLOR_YELLOW='\[\e[0;33m\]'
export COLOR_GRAY='\[\e[0;30m\]'
export COLOR_LIGHT_WHITE='\[\e[1;37m\]'
export COLOR_LIGHT_GRAY='\[\e[0;37m\]'
export COLOR_LIGHT_RED='\[\e[1;31m\]'
export COLOR_LIGHT_GREEN='\[\e[1;32m\]'
export COLOR_LIGHT_BLUE='\[\e[1;34m\]'
export COLOR_LIGHT_PURPLE='\[\e[1;35m\]'
export COLOR_LIGHT_CYAN='\[\e[1;36m\]'
export COLOR_LIGHT_YELLOW='\[\e[1;33m\]'
export COLOR_LIGHT_GRAY='\[\e[1;30m\]'
# PS1
case "$TERM" in
xterm*|gnome*|konsole*|screen*) color_prompt=yes;;
*) color_prompt=no;;
esac
if [ "$color_prompt" == no ]; then
for name in $(env|grep ^COLOR_|cut -d= -f1);do
unset ${name}
done
fi
if [ $UID = 0 ] ; then
local USER_FLAG="#"
else
local USER_FLAG="$"
fi
local SSH_IP=`echo $SSH_CLIENT | awk '{ print $1 }'`
local SSH2_IP=`echo $SSH2_CLIENT | awk '{ print $1 }'`
if [ $SSH2_IP ] || [ $SSH_IP ] ; then
local HOST_FLAG="${COLOR_RESET}${COLOR_LIGHT_YELLOW}\h${COLOR_NOCOLOR} "
fi
if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
local DEBIAN_CHROOT=$(cat /etc/debian_chroot)
fi
local GIT_BRANCH=''
if command -v git >/dev/null ; then
local GIT_BRANCH='$(git branch 2> /dev/null | sed -e '/^[^*]/d' -e "s#* \(.*\)# ($(git config
user.name) @ \1)#")'
fi
# last exit code
PS1=''
# chroot
PS1="${PS1}${COLOR_RESET}${DEBIAN_CHROOT}"
# show hostname if current not main device
PS1="${PS1}${HOST_FLAG}"
# current directory
PS1="${PS1}${COLOR_LIGHT_GRAY}[${COLOR_LIGHT_GREEN}\w${COLOR_NOCOLOR}${COLOR_LIGHT_GRAY}]"
# git repository info
PS1="${PS1}${COLOR_PURPLE}${GIT_BRANCH}${COLOR_NOCOLOR}"
# color by exit code
if [ $last_ret == 0 ] ; then
PS1="${PS1}${COLOR_LIGHT_WHITE} ${USER_FLAG}"
else
PS1="${PS1}${COLOR_LIGHT_RED} ($last_ret)${USER_FLAG}"
fi
# root/user flag
PS1="${PS1}${COLOR_NOCOLOR} "
export PS1
export PS2='> '
export PS3='#? '
export PS4='+'
for name in $(env|grep ^COLOR_|cut -d= -f1);do
unset ${name}
done
}
export HISTFILESIZE=10000
export HISTSIZE=10000
export HISTCONTROL=erasedups:ignoredups:ignorespace # Don't put duplicate lines in the history and do not add lines that start with a space
export HISTIGNORE="pwd:l:la:[bf]g:exit" # ignore such commands
export HISTTIMEFORMAT='%Y%m%d-%H:%M:%S '
export PROMPT_COMMAND='prompt_command'
export PROMPT_DIRTRIM=3
shopt -s cmdhist # combine multiline commands into single history
shopt -s histappend # append history
shopt -s checkwinsize # re-update LINEs and COLUMNs
shopt -s autocd
shopt -s extglob
shopt -s dotglob
shopt -s cdspell
shopt -s dirspell
shopt -s progcomp
shopt -s no_empty_cmd_completion
set -o noclobber
stty -ixon # replace Ctrl-S for forward-search-history
export EDITOR='vim'
# Use bash-completion, if available
if [ -f /usr/share/bash-completion/bash_completion ]; then
. /usr/share/bash-completion/bash_completion
elif [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
bind "set completion-ignore-case on" 2>/dev/null
bind "set bell-style none" 2>/dev/null
bind "set show-all-if-ambiguous on" 2>/dev/null
bind "set show-all-if-unmodified on" 2>/dev/null
# search history with arrow
bind '"\e[A": history-search-backward' 2>/dev/null
bind '"\e[B": history-search-forward' 2>/dev/null
# alias
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l='ls -CF'
alias la='ls -A'
alias ll='ls -alF'
alias ls='ls --color=auto'
alias ..="cd .."
alias ...="cd ../.."
alias ....="cd ../../.."
alias cd..="cd .."
if command -v dircolors > /dev/null 2>&1; then
source <(dircolors)
fi