📄 sample-bashrc.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><HTML><HEAD><TITLE>A Sample .bashrc File</TITLE><METANAME="GENERATOR"CONTENT="Modular DocBook HTML Stylesheet Version 1.57"><LINKREL="HOME"TITLE="Advanced Bash-Scripting Guide"HREF="index.html"><LINKREL="PREVIOUS"TITLE="History Commands"HREF="histcommands.html"><LINKREL="NEXT"TITLE="Converting DOS Batch Files to Shell Scripts"HREF="dosbatch.html"><METAHTTP-EQUIV="Content-Style-Type"CONTENT="text/css"><LINKREL="stylesheet"HREF="common/kde-common.css"TYPE="text/css"><METAHTTP-EQUIV="Content-Type"CONTENT="text/html; charset=iso-8859-1"><METAHTTP-EQUIV="Content-Language"CONTENT="en"><LINKREL="stylesheet"HREF="common/kde-localised.css"TYPE="text/css"TITLE="KDE-English"><LINKREL="stylesheet"HREF="common/kde-default.css"TYPE="text/css"TITLE="KDE-Default"></HEAD><BODYCLASS="APPENDIX"BGCOLOR="#FFFFFF"TEXT="#000000"LINK="#AA0000"VLINK="#AA0055"ALINK="#AA0000"STYLE="font-family: sans-serif;"><DIVCLASS="NAVHEADER"><TABLEWIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><THCOLSPAN="3"ALIGN="center">Advanced Bash-Scripting Guide: An in-depth exploration of the art of shell scripting</TH></TR><TR><TDWIDTH="10%"ALIGN="left"VALIGN="bottom"><AHREF="histcommands.html">Prev</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom"></TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="dosbatch.html">Next</A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><DIVCLASS="APPENDIX"><H1><ANAME="SAMPLE-BASHRC">Appendix K. A Sample <TTCLASS="FILENAME">.bashrc</TT> File</A></H1><P>The <TTCLASS="FILENAME">~/.bashrc</TT> file determines the behavior of interactive shells. A good look at this file can lead to a better understanding of Bash.</P><P><AHREF="mailto:emmanuel.rouat@wanadoo.fr"TARGET="_top">Emmanuel Rouat</A> contributed the following very elaborate <TTCLASS="FILENAME">.bashrc</TT> file, written for a Linux system. He welcomes reader feedback on it.</P><P>Study the file carefully, and feel free to reuse code snippets and functions from it in your own <TTCLASS="FILENAME">.bashrc</TT> file or even in your scripts.</P><DIVCLASS="EXAMPLE"><HR><ANAME="BASHRC"></A><P><B>Example K-1. Sample <TTCLASS="FILENAME">.bashrc</TT> file</B></P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING"> 1 #=============================================================== 2 # 3 # PERSONAL $HOME/.bashrc FILE for bash-2.05a (or later) 4 # 5 # Last modified: Tue Apr 15 20:32:34 CEST 2003 6 # 7 # This file is read (normally) by interactive shells only. 8 # Here is the place to define your aliases, functions and 9 # other interactive features like your prompt. 10 # 11 # This file was designed (originally) for Solaris but based 12 # on Redhat's default .bashrc file 13 # --> Modified for Linux. 14 # The majority of the code you'll find here is based on code found 15 # on Usenet (or internet). 16 # This bashrc file is a bit overcrowded - remember it is just 17 # just an example. Tailor it to your needs 18 # 19 # 20 #=============================================================== 21 22 # --> Comments added by HOWTO author. 23 # --> And then edited again by ER :-) 24 25 #----------------------------------- 26 # Source global definitions (if any) 27 #----------------------------------- 28 29 if [ -f /etc/bashrc ]; then 30 . /etc/bashrc # --> Read /etc/bashrc, if present. 31 fi 32 33 #------------------------------------------------------------- 34 # Automatic setting of $DISPLAY (if not set already) 35 # This works for linux - your mileage may vary.... 36 # The problem is that different types of terminals give 37 # different answers to 'who am i'...... 38 # I have not found a 'universal' method yet 39 #------------------------------------------------------------- 40 41 function get_xserver () 42 { 43 case $TERM in 44 xterm ) 45 XSERVER=$(who am i | awk '{print $NF}' | tr -d ')''(' ) 46 # Ane-Pieter Wieringa suggests the following alternative: 47 # I_AM=$(who am i) 48 # SERVER=${I_AM#*(} 49 # SERVER=${SERVER%*)} 50 51 XSERVER=${XSERVER%%:*} 52 ;; 53 aterm | rxvt) 54 # find some code that works here..... 55 ;; 56 esac 57 } 58 59 if [ -z ${DISPLAY:=""} ]; then 60 get_xserver 61 if [[ -z ${XSERVER} || ${XSERVER} == $(hostname) || ${XSERVER} == "unix" ]]; then 62 DISPLAY=":0.0" # Display on local host 63 else 64 DISPLAY=${XSERVER}:0.0 # Display on remote host 65 fi 66 fi 67 68 export DISPLAY 69 70 #--------------- 71 # Some settings 72 #--------------- 73 74 ulimit -S -c 0 # Don't want any coredumps 75 set -o notify 76 set -o noclobber 77 set -o ignoreeof 78 set -o nounset 79 #set -o xtrace # useful for debuging 80 81 # Enable options: 82 shopt -s cdspell 83 shopt -s cdable_vars 84 shopt -s checkhash 85 shopt -s checkwinsize 86 shopt -s mailwarn 87 shopt -s sourcepath 88 shopt -s no_empty_cmd_completion # bash>=2.04 only 89 shopt -s cmdhist 90 shopt -s histappend histreedit histverify 91 shopt -s extglob # necessary for programmable completion 92 93 # Disable options: 94 shopt -u mailwarn 95 unset MAILCHECK # I don't want my shell to warn me of incoming mail 96 97 98 export TIMEFORMAT=$'\nreal %3R\tuser %3U\tsys %3S\tpcpu %P\n' 99 export HISTIGNORE="&:bg:fg:ll:h" 100 export HOSTFILE=$HOME/.hosts # Put a list of remote hosts in ~/.hosts 101 102 103 104 #----------------------- 105 # Greeting, motd etc... 106 #----------------------- 107 108 # Define some colors first: 109 red='\e[0;31m' 110 RED='\e[1;31m' 111 blue='\e[0;34m' 112 BLUE='\e[1;34m' 113 cyan='\e[0;36m' 114 CYAN='\e[1;36m' 115 NC='\e[0m' # No Color 116 # --> Nice. Has the same effect as using "ansi.sys" in DOS. 117 118 # Looks best on a black background..... 119 echo -e "${CYAN}This is BASH ${RED}${BASH_VERSION%.*}${CYAN} - DISPLAY on ${RED}$DISPLAY${NC}\n" 120 date 121 if [ -x /usr/games/fortune ]; then 122 /usr/games/fortune -s # makes our day a bit more fun.... :-) 123 fi 124 125 function _exit() # function to run upon exit of shell 126 { 127 echo -e "${RED}Hasta la vista, baby${NC}" 128 } 129 trap _exit EXIT 130 131 #--------------- 132 # Shell Prompt 133 #--------------- 134 135 if [[ "${DISPLAY#$HOST}" != ":0.0" && "${DISPLAY}" != ":0" ]]; then 136 HILIT=${red} # remote machine: prompt will be partly red 137 else 138 HILIT=${cyan} # local machine: prompt will be partly cyan 139 fi 140 141 # --> Replace instances of \W with \w in prompt functions below 142 #+ --> to get display of full path name. 143 144 function fastprompt() 145 { 146 unset PROMPT_COMMAND 147 case $TERM in 148 *term | rxvt ) 149 PS1="${HILIT}[\h]$NC \W > \[\033]0;\${TERM} [\u@\h] \w\007\]" ;; 150 linux ) 151 PS1="${HILIT}[\h]$NC \W > " ;; 152 *) 153 PS1="[\h] \W > " ;; 154 esac 155 } 156 157 function powerprompt() 158 { 159 _powerprompt() 160 { 161 LOAD=$(uptime|sed -e "s/.*: \([^,]*\).*/\1/" -e "s/ //g") 162 } 163 164 PROMPT_COMMAND=_powerprompt 165 case $TERM in 166 *term | rxvt ) 167 PS1="${HILIT}[\A \$LOAD]$NC\n[\h \#] \W > \[\033]0;\${TERM} [\u@\h] \w\007\]" ;; 168 linux ) 169 PS1="${HILIT}[\A - \$LOAD]$NC\n[\h \#] \w > " ;; 170 * ) 171 PS1="[\A - \$LOAD]\n[\h \#] \w > " ;; 172 esac 173 } 174 175 powerprompt # this is the default prompt - might be slow 176 # If too slow, use fastprompt instead.... 177 178 #=============================================================== 179 # 180 # ALIASES AND FUNCTIONS 181 # 182 # Arguably, some functions defined here are quite big 183 # (ie 'lowercase') but my workstation has 512Meg of RAM, so ..... 184 # If you want to make this file smaller, these functions can 185 # be converted into scripts. 186 # 187 # Many functions were taken (almost) straight from the bash-2.04 188 # examples. 189 # 190 #=============================================================== 191 192 #------------------- 193 # Personnal Aliases 194 #------------------- 195 196 alias rm='rm -i' 197 alias cp='cp -i' 198 alias mv='mv -i' 199 # -> Prevents accidentally clobbering files. 200 alias mkdir='mkdir -p' 201 202 alias h='history' 203 alias j='jobs -l' 204 alias r='rlogin' 205 alias which='type -all' 206 alias ..='cd ..' 207 alias path='echo -e ${PATH//:/\\n}' 208 alias print='/usr/bin/lp -o nobanner -d $LPDEST' # Assumes LPDEST is defined 209 alias pjet='enscript -h -G -fCourier9 -d $LPDEST' # Pretty-print using enscript 210 alias background='xv -root -quit -max -rmode 5' # Put a picture in the background 211 alias du='du -kh' 212 alias df='df -kTh' 213 214 # The 'ls' family (this assumes you use the GNU ls) 215 alias la='ls -Al' # show hidden files 216 alias ls='ls -hF --color' # add colors for filetype recognition 217 alias lx='ls -lXB' # sort by extension 218 alias lk='ls -lSr' # sort by size 219 alias lc='ls -lcr' # sort by change time 220 alias lu='ls -lur' # sort by access time 221 alias lr='ls -lR' # recursive ls 222 alias lt='ls -ltr' # sort by date 223 alias lm='ls -al |more' # pipe through 'more' 224 alias tree='tree -Csu' # nice alternative to 'ls' 225 226 # tailoring 'less' 227 alias more='less' 228 export PAGER=less 229 export LESSCHARSET='latin1' 230 export LESSOPEN='|/usr/bin/lesspipe.sh %s 2>&-' # Use this if lesspipe.sh exists 231 export LESS='-i -N -w -z-4 -g -e -M -X -F -R -P%t?f%f \ 232 :stdin .?pb%pb\%:?lbLine %lb:?bbByte %bb:-...' 233 234 # spelling typos - highly personnal :-) 235 alias xs='cd' 236 alias vf='cd' 237 alias moer='more' 238 alias moew='more' 239 alias kk='ll' 240 241 #---------------- 242 # a few fun ones 243 #---------------- 244 245 function xtitle () 246 { 247 case "$TERM" in 248 *term | rxvt) 249 echo -n -e "\033]0;$*\007" ;; 250 *) 251 ;; 252 esac 253 } 254 255 # aliases... 256 alias top='xtitle Processes on $HOST && top' 257 alias make='xtitle Making $(basename $PWD) ; make' 258 alias ncftp="xtitle ncFTP ; ncftp" 259 260 # .. and functions 261 function man () 262 { 263 for i ; do 264 xtitle The $(basename $1|tr -d .[:digit:]) manual 265 command man -F -a "$i" 266 done 267 } 268 269 function ll(){ ls -l "$@"| egrep "^d" ; ls -lXB "$@" 2>&-| egrep -v "^d|total "; } 270 function te() # wrapper around xemacs/gnuserv 271 { 272 if [ "$(gnuclient -batch -eval t 2>&-)" == "t" ]; then 273 gnuclient -q "$@"; 274 else 275 ( xemacs "$@" &); 276 fi 277 } 278 279 #----------------------------------- 280 # File & strings related functions: 281 #----------------------------------- 282 283 # Find a file with a pattern in name: 284 function ff() { find . -type f -iname '*'$*'*' -ls ; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -