⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bashrc

📁 Shall高级编程
💻
📖 第 1 页 / 共 2 页
字号:
        case "$filename" in        */*) dirname==${file%/*} ;;        *) dirname=.;;        esac        nf=$(echo $filename | tr A-Z a-z)        newname="${dirname}/${nf}"        if [ "$nf" != "$filename" ]; then            mv "$file" "$newname"            echo "lowercase: $file --> $newname"        else            echo "lowercase: $file not changed."        fi    done}function swap()         # swap 2 filenames around{    local TMPFILE=tmp.$$    mv "$1" $TMPFILE    mv "$2" "$1"    mv $TMPFILE "$2"}#-----------------------------------# Process/system related functions:#-----------------------------------function my_ps(){ ps $@ -u $USER -o pid,%cpu,%mem,bsdtime,command ; }function pp(){ my_ps f | awk '!/awk/ && $0~var' var=${1:-".*"} ; }# This function is roughly the same as 'killall' on linux# but has no equivalent (that I know of) on Solarisfunction killps()   # kill by process name{   local pid pname sig="-TERM"   # default signal   if [ "$#" -lt 1 ] || [ "$#" -gt 2 ]; then       echo "Usage: killps [-SIGNAL] pattern"       return;   fi   if [ $# = 2 ]; then sig=$1 ; fi   for pid in $(my_ps| awk '!/awk/ && $0~pat { print $1 }' pat=${!#} ) ; do       pname=$(my_ps | awk '$1~var { print $5 }' var=$pid )       if ask "Kill process $pid <$pname> with signal $sig?"           then kill $sig $pid       fi   done}function my_ip() # get IP adresses{    MY_IP=$(/sbin/ifconfig ppp0 | awk '/inet/ { print $2 } ' | \sed -e s/addr://)    MY_ISP=$(/sbin/ifconfig ppp0 | awk '/P-t-P/ { print $3 } ' | \sed -e s/P-t-P://)}function ii()   # get current host related info{  echo -e "\nYou are logged on ${RED}$HOST"  echo -e "\nAdditionnal information:$NC " ; uname -a  echo -e "\n${RED}Users logged on:$NC " ; w -h  echo -e "\n${RED}Current date :$NC " ; date  echo -e "\n${RED}Machine stats :$NC " ; uptime  echo -e "\n${RED}Memory stats :$NC " ; free  my_ip 2>&- ;  echo -e "\n${RED}Local IP Address :$NC" ; echo ${MY_IP:-"Not connected"}  echo -e "\n${RED}ISP Address :$NC" ; echo ${MY_ISP:-"Not connected"}  echo}# Misc utilities:function repeat()       # repeat n times command{    local i max    max=$1; shift;    for ((i=1; i <= max ; i++)); do  # --> C-like syntax        eval "$@";    done}function ask(){    echo -n "$@" '[y/n] ' ; read ans    case "$ans" in        y*|Y*) return 0 ;;        *) return 1 ;;    esac}#=======================================================================## PROGRAMMABLE COMPLETION - ONLY SINCE BASH-2.04# Most are taken from the bash 2.05 documentation and from Ian McDonalds# 'Bash completion' package#  (http://www.caliban.org/bash/index.shtml#completion)# You will in fact need bash-2.05a for some features##=======================================================================if [ "${BASH_VERSION%.*}" \< "2.05" ]; then   echo "You will need to upgrade to version 2.05 \for programmable completion"   returnfishopt -s extglob        # necessaryset +o nounset          # otherwise some completions will failcomplete -A hostname   rsh rcp telnet rlogin r ftp ping diskcomplete -A export     printenvcomplete -A variable   export local readonly unsetcomplete -A enabled    builtincomplete -A alias      alias unaliascomplete -A function   functioncomplete -A user       su mail fingercomplete -A helptopic  help     # currently same as builtinscomplete -A shopt      shoptcomplete -A stopped -P '%' bgcomplete -A job -P '%'     fg jobs disowncomplete -A directory  mkdir rmdircomplete -A directory   -o default cd# Compressioncomplete -f -o default -X '*.+(zip|ZIP)'  zipcomplete -f -o default -X '!*.+(zip|ZIP)' unzipcomplete -f -o default -X '*.+(z|Z)'      compresscomplete -f -o default -X '!*.+(z|Z)'     uncompresscomplete -f -o default -X '*.+(gz|GZ)'    gzipcomplete -f -o default -X '!*.+(gz|GZ)'   gunzipcomplete -f -o default -X '*.+(bz2|BZ2)'  bzip2complete -f -o default -X '!*.+(bz2|BZ2)' bunzip2# Postscript,pdf,dvi.....complete -f -o default -X '!*.ps'  gs ghostview ps2pdf ps2asciicomplete -f -o default -X '!*.dvi' dvips dvipdf xdvi dviselect dvitypecomplete -f -o default -X '!*.pdf' acroread pdf2pscomplete -f -o default -X '!*.+(pdf|ps)' gvcomplete -f -o default -X '!*.texi*' makeinfo texi2dvi texi2html texi2pdfcomplete -f -o default -X '!*.tex' tex latex slitexcomplete -f -o default -X '!*.lyx' lyxcomplete -f -o default -X '!*.+(htm*|HTM*)' lynx html2ps# Multimediacomplete -f -o default -X '!*.+(jp*g|gif|xpm|png|bmp)' xv gimpcomplete -f -o default -X '!*.+(mp3|MP3)' mpg123 mpg321complete -f -o default -X '!*.+(ogg|OGG)' ogg123complete -f -o default -X '!*.pl'  perl perl5# This is a 'universal' completion function - it works when commands have# a so-called 'long options' mode , ie: 'ls --all' instead of 'ls -a'_get_longopts () {     $1 --help | sed  -e '/--/!d' -e 's/.*--\([^[:space:].,]*\).*/--\1/'| \grep ^"$2" |sort -u ;}_longopts_func (){    case "${2:-*}" in	-*)	;;	*)	return ;;    esac    case "$1" in	\~*)	eval cmd="$1" ;;	*)	cmd="$1" ;;    esac    COMPREPLY=( $(_get_longopts ${1} ${2} ) )}complete  -o default -F _longopts_func configure bashcomplete  -o default -F _longopts_func wget id info a2ps ls recode_make_targets (){    local mdef makef gcmd cur prev i    COMPREPLY=()    cur=${COMP_WORDS[COMP_CWORD]}    prev=${COMP_WORDS[COMP_CWORD-1]}    # if prev argument is -f, return possible filename completions.    # we could be a little smarter here and return matches against    # `makefile Makefile *.mk', whatever exists    case "$prev" in        -*f)    COMPREPLY=( $(compgen -f $cur ) ); return 0;;    esac    # if we want an option, return the possible posix options    case "$cur" in        -)      COMPREPLY=(-e -f -i -k -n -p -q -r -S -s -t); return 0;;    esac    # make reads `makefile' before `Makefile'    if [ -f makefile ]; then        mdef=makefile    elif [ -f Makefile ]; then        mdef=Makefile    else        mdef=*.mk               # local convention    fi    # before we scan for targets, see if a makefile name was specified    # with -f    for (( i=0; i < ${#COMP_WORDS[@]}; i++ )); do        if [[ ${COMP_WORDS[i]} == -*f ]]; then            eval makef=${COMP_WORDS[i+1]}      # eval for tilde expansion            break        fi    done        [ -z "$makef" ] && makef=$mdef    # if we have a partial word to complete, restrict completions to    # matches of that word    if [ -n "$2" ]; then gcmd='grep "^$2"' ; else gcmd=cat ; fi    # if we don't want to use *.mk, we can take out the cat and use    # test -f $makef and input redirection    COMPREPLY=( $(cat $makef 2>/dev/null | \    awk 'BEGIN {FS=":"} /^[^.#   ][^=]*:/ {print $1}' \    | tr -s ' ' '\012' | sort -u | eval $gcmd ) )}complete -F _make_targets -X '+($*|*.[cho])' make gmake pmake# cvs(1) completion_cvs (){    local cur prev    COMPREPLY=()    cur=${COMP_WORDS[COMP_CWORD]}    prev=${COMP_WORDS[COMP_CWORD-1]}    if [ $COMP_CWORD -eq 1 ] || [ "${prev:0:1}" = "-" ]; then        COMPREPLY=( $( compgen -W 'add admin checkout commit diff \        export history import log rdiff release remove rtag status \        tag update' $cur ))    else        COMPREPLY=( $( compgen -f $cur ))    fi    return 0}complete -F _cvs cvs_killall (){    local cur prev    COMPREPLY=()    cur=${COMP_WORDS[COMP_CWORD]}    # get a list of processes (the first sed evaluation    # takes care of swapped out processes, the second    # takes care of getting the basename of the process)    COMPREPLY=( $( /usr/bin/ps -u $USER -o comm  | \        sed -e '1,1d' -e 's#[]\[]##g' -e 's#^.*/##'| \        awk '{if ($0 ~ /^'$cur'/) print $0}' ))    return 0}complete -F _killall killall killps# A meta-command completion function for commands like sudo(8), which# need to first complete on a command,# then complete according to that command's own# completion definition - currently not quite foolproof# (e.g. mount and umount don't work properly),# but still quite useful --# By Ian McDonald, modified by me._my_command(){    local cur func cline cspec        COMPREPLY=()    cur=${COMP_WORDS[COMP_CWORD]}    if [ $COMP_CWORD = 1 ]; then	COMPREPLY=( $( compgen -c $cur ) )    elif complete -p ${COMP_WORDS[1]} &>/dev/null; then	cspec=$( complete -p ${COMP_WORDS[1]} )	if [ "${cspec%%-F *}" != "${cspec}" ]; then	    # complete -F &lt;function&gt;	    #	    # COMP_CWORD and COMP_WORDS() are not read-only,	    # so we can set them before handing off to regular	    # completion routine		    # set current token number to 1 less than now	    COMP_CWORD=$(( $COMP_CWORD - 1 ))	    # get function name	    func=${cspec#*-F }	    func=${func%% *}	    # get current command line minus initial command	    cline="${COMP_LINE#$1 }"	    # split current command line tokens into array		COMP_WORDS=( $cline )	    $func $cline	elif [ "${cspec#*-[abcdefgjkvu]}" != "" ]; then          # complete -[abcdefgjkvu]          #func=$( echo $cspec | sed -e 's/^.*\(-[abcdefgjkvu]\).*$/\1/' )          func=$( echo $cspec | sed -e 's/^complete//' -e 's/[^ ]*$//' )	    COMPREPLY=( $( eval compgen $func $cur ) )	elif [ "${cspec#*-A}" != "$cspec" ]; then	    # complete -A &lt;type&gt;	    func=${cspec#*-A }	func=${func%% *}	COMPREPLY=( $( compgen -A $func $cur ) )	fi    else	COMPREPLY=( $( compgen -f $cur ) )    fi}complete -o default -F _my_command nohup exec eval \trace truss strace sotruss gdbcomplete -o default -F _my_command command type which man nice# Local Variables:# mode:shell-script# sh-shell:bash# End:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -