📄 bashrc
字号:
#===============================================================## PERSONAL $HOME/.bashrc FILE for bash-2.05a (or later)## Last modified: Tue Apr 15 20:32:34 CEST 2003## This file is read (normally) by interactive shells only.# Here is the place to define your aliases, functions and# other interactive features like your prompt.## This file was designed (originally) for Solaris but based # on Redhat's default .bashrc file# --> Modified for Linux.# The majority of the code you'll find here is based on code found# on Usenet (or internet).# This bashrc file is a bit overcrowded - remember it is just# just an example. Tailor it to your needs###===============================================================# --> Comments added by HOWTO author.# --> And then edited again by ER :-)#-----------------------------------# Source global definitions (if any)#-----------------------------------if [ -f /etc/bashrc ]; then . /etc/bashrc # --> Read /etc/bashrc, if present.fi#-------------------------------------------------------------# Automatic setting of $DISPLAY (if not set already)# This works for linux - your mileage may vary.... # The problem is that different types of terminals give# different answers to 'who am i'......# I have not found a 'universal' method yet#-------------------------------------------------------------function get_xserver (){ case $TERM in xterm ) XSERVER=$(who am i | awk '{print $NF}' | tr -d ')''(' ) # Ane-Pieter Wieringa suggests the following alternative: # I_AM=$(who am i) # SERVER=${I_AM#*(} # SERVER=${SERVER%*)} XSERVER=${XSERVER%%:*} ;; aterm | rxvt) # find some code that works here..... ;; esac }if [ -z ${DISPLAY:=""} ]; then get_xserver if [[ -z ${XSERVER} || ${XSERVER} == $(hostname) || ${XSERVER} == "unix" ]]; then DISPLAY=":0.0" # Display on local host else DISPLAY=${XSERVER}:0.0 # Display on remote host fifiexport DISPLAY#---------------# Some settings#---------------ulimit -S -c 0 # Don't want any coredumpsset -o notifyset -o noclobberset -o ignoreeofset -o nounset#set -o xtrace # Useful for debuging# Enable options:shopt -s cdspellshopt -s cdable_varsshopt -s checkhashshopt -s checkwinsizeshopt -s mailwarnshopt -s sourcepathshopt -s no_empty_cmd_completion # bash>=2.04 onlyshopt -s cmdhistshopt -s histappend histreedit histverifyshopt -s extglob # Necessary for programmable completion# Disable options:shopt -u mailwarnunset MAILCHECK # I don't want my shell to warn me of incoming mailexport TIMEFORMAT=$'\nreal %3R\tuser %3U\tsys %3S\tpcpu %P\n'export HISTIGNORE="&:bg:fg:ll:h"export HOSTFILE=$HOME/.hosts # Put a list of remote hosts in ~/.hosts#-----------------------# Greeting, motd etc...#-----------------------# Define some colors first:red='\e[0;31m'RED='\e[1;31m'blue='\e[0;34m'BLUE='\e[1;34m'cyan='\e[0;36m'CYAN='\e[1;36m'NC='\e[0m' # No Color# --> Nice. Has the same effect as using "ansi.sys" in DOS.# Looks best on a black background.....echo -e "${CYAN}This is BASH ${RED}${BASH_VERSION%.*}\${CYAN} - DISPLAY on ${RED}$DISPLAY${NC}\n"dateif [ -x /usr/games/fortune ]; then /usr/games/fortune -s # makes our day a bit more fun.... :-)fifunction _exit() # function to run upon exit of shell{ echo -e "${RED}Hasta la vista, baby${NC}"}trap _exit EXIT#---------------# Shell Prompt#---------------if [[ "${DISPLAY#$HOST}" != ":0.0" && "${DISPLAY}" != ":0" ]]; then HILIT=${red} # remote machine: prompt will be partly redelse HILIT=${cyan} # local machine: prompt will be partly cyanfi# --> Replace instances of \W with \w in prompt functions below#+ --> to get display of full path name.function fastprompt(){ unset PROMPT_COMMAND case $TERM in *term | rxvt ) PS1="${HILIT}[\h]$NC \W > \[\033]0;\${TERM} [\u@\h] \w\007\]" ;; linux ) PS1="${HILIT}[\h]$NC \W > " ;; *) PS1="[\h] \W > " ;; esac}function powerprompt(){ _powerprompt() { LOAD=$(uptime|sed -e "s/.*: \([^,]*\).*/\1/" -e "s/ //g") } PROMPT_COMMAND=_powerprompt case $TERM in *term | rxvt ) PS1="${HILIT}[\A \$LOAD]$NC\n[\h \#] \W > \ \[\033]0;\${TERM} [\u@\h] \w\007\]" ;; linux ) PS1="${HILIT}[\A - \$LOAD]$NC\n[\h \#] \w > " ;; * ) PS1="[\A - \$LOAD]\n[\h \#] \w > " ;; esac}powerprompt # This is the default prompt -- might be slow. # If too slow, use fastprompt instead.#===============================================================## ALIASES AND FUNCTIONS## Arguably, some functions defined here are quite big# (ie 'lowercase') but my workstation has 512Meg of RAM, so ...# If you want to make this file smaller, these functions can# be converted into scripts.## Many functions were taken (almost) straight from the bash-2.04# examples.##===============================================================#-------------------# Personnal Aliases#-------------------alias rm='rm -i'alias cp='cp -i'alias mv='mv -i'# -> Prevents accidentally clobbering files.alias mkdir='mkdir -p'alias h='history'alias j='jobs -l'alias r='rlogin'alias which='type -all'alias ..='cd ..'alias path='echo -e ${PATH//:/\\n}'alias print='/usr/bin/lp -o nobanner -d $LPDEST' # Assumes LPDEST is definedalias pjet='enscript -h -G -fCourier9 -d $LPDEST' # Pretty-print using enscriptalias background='xv -root -quit -max -rmode 5' # Put a picture in the backgroundalias du='du -kh'alias df='df -kTh'# The 'ls' family (this assumes you use the GNU ls)alias la='ls -Al' # show hidden filesalias ls='ls -hF --color' # add colors for filetype recognitionalias lx='ls -lXB' # sort by extensionalias lk='ls -lSr' # sort by sizealias lc='ls -lcr' # sort by change time alias lu='ls -lur' # sort by access time alias lr='ls -lR' # recursive lsalias lt='ls -ltr' # sort by datealias lm='ls -al |more' # pipe through 'more'alias tree='tree -Csu' # nice alternative to 'ls'# tailoring 'less'alias more='less'export PAGER=lessexport LESSCHARSET='latin1'export LESSOPEN='|/usr/bin/lesspipe.sh %s 2>&-' # Use this if lesspipe.sh exists.export LESS='-i -N -w -z-4 -g -e -M -X -F -R -P%t?f%f \:stdin .?pb%pb\%:?lbLine %lb:?bbByte %bb:-...'# spelling typos - highly personnal :-)alias xs='cd'alias vf='cd'alias moer='more'alias moew='more'alias kk='ll'#----------------# a few fun ones#----------------function xtitle (){ case "$TERM" in *term | rxvt) echo -n -e "\033]0;$*\007" ;; *) ;; esac}# aliases...alias top='xtitle Processes on $HOST && top'alias make='xtitle Making $(basename $PWD) ; make'alias ncftp="xtitle ncFTP ; ncftp"# .. and functionsfunction man (){ for i ; do xtitle The $(basename $1|tr -d .[:digit:]) manual command man -F -a "$i" done}function ll(){ ls -l "$@"| egrep "^d" ; ls -lXB "$@" 2>&-| egrep -v "^d|total "; }function te() # wrapper around xemacs/gnuserv{ if [ "$(gnuclient -batch -eval t 2>&-)" == "t" ]; then gnuclient -q "$@"; else ( xemacs "$@" &); fi}#-----------------------------------# File & strings related functions:#-----------------------------------# Find a file with a pattern in name:function ff(){ find . -type f -iname '*'$*'*' -ls ; }# Find a file with pattern $1 in name and Execute $2 on it:function fe(){ find . -type f -iname '*'$1'*' -exec "${2:-file}" {} \; ; }# find pattern in a set of filesand highlight them:function fstr(){ OPTIND=1 local case="" local usage="fstr: find string in files.Usage: fstr [-i] \"pattern\" [\"filename pattern\"] " while getopts :it opt do case "$opt" in i) case="-i " ;; *) echo "$usage"; return;; esac done shift $(( $OPTIND - 1 )) if [ "$#" -lt 1 ]; then echo "$usage" return; fi local SMSO=$(tput smso) local RMSO=$(tput rmso) find . -type f -name "${2:-*}" -print0 | xargs -0 grep -sn ${case} "$1" 2>&- | \ sed "s/$1/${SMSO}\0${RMSO}/gI" | more}function cuttail() # Cut last n lines in file, 10 by default.{ nlines=${2:-10} sed -n -e :a -e "1,${nlines}!{P;N;D;};N;ba" $1}function lowercase() # move filenames to lowercase{ for file ; do filename=${file##*/}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -