📄 bash_completion
字号:
mode=log ;; @(rdiff|patch)) mode=rdiff ;; @(remove|rm|delete)) mode=remove ;; @(rtag|rfreeze)) mode=rtag ;; st?(at?(us))) mode=status ;; @(tag|freeze)) mode=tag ;; up?(d?(ate))) mode=update ;; *) ;; esac elif [[ "$i" = -* ]]; then flags=( "${flags[@]}" $i ) fi count=$((++count)) done case "$mode" in add) if [[ "$cur" != -* ]]; then set_prefix if [ $COMP_CWORD -gt 1 -a -r ${prefix:-}CVS/Entries ]; then get_entries [ -z "$cur" ] && \ files=$( command ls -Ad !(CVS) ) || \ files=$( command ls -d ${cur}* 2>/dev/null ) for i in "${entries[@]}"; do files=( ${files[@]/#$i//} ) done COMPREPLY=( $( compgen -W '${files[@]}' -- \ $cur ) ) fi else COMPREPLY=( $( compgen -W '-k -m' -- $cur ) ) fi ;; admin) if [[ "$cur" = -* ]]; then COMPREPLY=( $( compgen -W '-i -a -A -e -b -c -k -l -u \ -L -U -m -M -n -N -o -q -I \ -s -t -t- -T -V -x -z' -- \ $cur ) ) fi ;; annotate) if [[ "$cur" = -* ]]; then COMPREPLY=( $( compgen -W '-D -F -f -l -R -r' -- $cur ) ) else get_entries COMPREPLY=( $( compgen -W '${entries[@]}' -- $cur ) ) fi ;; checkout) if [[ "$cur" != -* ]]; then [ -z "$cvsroot" ] && cvsroot=$CVSROOT COMPREPLY=( $( cvs -d "$cvsroot" co -c 2> /dev/null | \ awk '{print $1}' ) ) COMPREPLY=( $( compgen -W '${COMPREPLY[@]}' -- $cur ) ) else COMPREPLY=( $( compgen -W '-A -N -P -R -c -f -l -n -p \ -s -r -D -d -k -j' -- $cur ) ) fi ;; commit) set_prefix if [[ "$cur" != -* ]] && [ -r ${prefix:-}CVS/Entries ]; then # if $COMP_CVS_REMOTE is not null, 'cvs commit' will # complete on remotely checked-out files (requires # passwordless access to the remote repository if [ -n "${COMP_CVS_REMOTE:-}" ]; then # this is the least computationally intensive # way found so far, but other changes # (something other than changed/removed/new) # may be missing changed=( $( cvs -q diff --brief 2>&1 | \ sed -ne 's/^Files [^ ]* and \([^ ]*\) differ$/\1/p' ) ) newremoved=( $( cvs -q diff --brief 2>&1 | \ sed -ne 's/^cvs diff: \([^ ]*\) .*, no comparison available$/\1/p' ) ) COMPREPLY=( $( compgen -W '${changed[@]:-} \ ${newremoved[@]:-}' -- $cur ) ) else _filedir fi else COMPREPLY=( $( compgen -W '-n -R -l -f -F -m -r' -- \ $cur ) ) fi ;; cvsroot) if [ -r ~/.cvspass ]; then # Ugly escaping because of bash treating ':' specially cvsroots=$( sed 's/^[^ ]* //; s/:/\\:/g' ~/.cvspass ) COMPREPLY=( $( compgen -W '$cvsroots' -- $cur ) ) fi ;; export) if [[ "$cur" != -* ]]; then [ -z "$cvsroot" ] && cvsroot=$CVSROOT COMPREPLY=( $( cvs -d "$cvsroot" co -c | awk '{print $1}' ) ) COMPREPLY=( $( compgen -W '${COMPREPLY[@]}' -- $cur ) ) else COMPREPLY=( $( compgen -W '-N -f -l -R -n \ -r -D -d -k' -- $cur ) ) fi ;; diff) if [[ "$cur" == -* ]]; then _longopt diff else get_entries COMPREPLY=( $( compgen -W '${entries[@]:-}' -- $cur ) ) fi ;; remove) if [[ "$cur" != -* ]]; then set_prefix if [ $COMP_CWORD -gt 1 -a -r ${prefix:-}CVS/Entries ]; then get_entries # find out what files are missing for i in "${entries[@]}"; do [ ! -r "$i" ] && miss=( "${miss[@]}" $i ) done COMPREPLY=( $(compgen -W '${miss[@]:-}' -- $cur) ) fi else COMPREPLY=( $( compgen -W '-f -l -R' -- $cur ) ) fi ;; import) if [[ "$cur" != -* ]]; then # starts with same algorithm as checkout [ -z "$cvsroot" ] && cvsroot=$CVSROOT prefix=${cur%/*} if [ -r ${cvsroot}/${prefix} ]; then get_modules COMPREPLY=( ${COMPREPLY[@]#$cvsroot} ) COMPREPLY=( ${COMPREPLY[@]#\/} ) fi pwd=$( pwd ) pwd=${pwd##*/} COMPREPLY=( $( compgen -W '${COMPREPLY[@]} $pwd' -- \ $cur ) ) else COMPREPLY=( $( compgen -W '-d -k -I -b -m -W' -- $cur )) fi ;; update) if [[ "$cur" = -* ]]; then COMPREPLY=( $( compgen -W '-A -P -C -d -f -l -R -p \ -k -r -D -j -I -W' -- \ $cur ) ) fi ;; "") COMPREPLY=( $( compgen -W 'add admin annotate checkout ci co \ commit diff delete edit export \ freeze get history import log new \ patch rcs rdiff release remove \ rfreeze rlog rm rtag stat status \ tag unedit up update -H -Q -q -b \ -d -e -f -l -n -t -r -v -w -x -z \ --help --version' -- $cur ) ) ;; *) ;; esac return 0}complete -F _cvs $default cvs}have rpm && {# helper functions for rpm completion#_rpm_installed_packages(){ local ver nodig nosig if [ -r /var/log/rpmpkgs -a \ /var/log/rpmpkgs -nt /var/lib/rpm/Packages ]; then # using RHL 7.2 or later - this is quicker than querying the DB COMPREPLY=( $( sed -ne \ 's|^\('$cur'.*\)-[0-9a-zA-Z._]\+-[0-9a-z.@]\+.*\.rpm$|\1|p' \ /var/log/rpmpkgs ) ) else nodig="" nosig="" ver=$(rpm --version) ver=${ver##* } if [[ "$ver" > "4.0.4" ]]; then nodig="--nodigest" fi if [[ "$ver" > "4.0.99" ]]; then nosig="--nosignature" fi COMPREPLY=( $( rpm -qa $nodig $nosig | sed -ne \ 's|^\('$cur'.*\)-[0-9a-zA-Z._]\+-[0-9a-z.@]\+$|\1|p' ) ) fi}_rpm_groups(){ local IFS=$'\t' # remove trailing backslash, or grep will complain cur=${cur%"\\"} COMPREPLY=( $( rpm -qa $nodig $nosig --queryformat '%{group}\n' | \ grep "^$cur" ) ) # backslash escape spaces and translate newlines to tabs COMPREPLY=( $( echo "${COMPREPLY[@]}" | sed 's/ /\\ /g' | tr '\n' '\t' ) )}# rpm(8) completion# _rpm(){ local cur prev ver nodig nosig COMPREPLY=() cur=`_get_cword` prev=${COMP_WORDS[COMP_CWORD-1]} nodig="" nosig="" ver=$(rpm --version); ver=${ver##* } if [[ "$ver" > "4.0.4" ]]; then nodig="--nodigest" fi if [[ "$ver" > "4.0.99" ]]; then nosig="--nosignature" fi if [ $COMP_CWORD -eq 1 ]; then # first parameter on line case "$cur" in -b*) COMPREPLY=( $( compgen -W '-ba -bb -bc -bi -bl -bp -bs'\ -- $cur ) ) ;; -t*) COMPREPLY=( $( compgen -W '-ta -tb -tc -ti -tl -tp -ts'\ -- $cur ) ) ;; --*) COMPREPLY=( $( compgen -W '--help --version --initdb \ --checksig --recompile --rebuild --resign --addsign \ --rebuilddb --showrc --setperms --setugids --tarbuild \ --eval --install --upgrade --query --freshen --erase \ --verify --querytags --rmsource --rmspec --clean \ --import' -- $cur ) ) ;; *) COMPREPLY=( $( compgen -W '-b -e -F -i -q -t -U -V' \ -- $cur ) ) ;; esac return 0 fi case "$prev" in --@(@(db|exclude)path|prefix|relocate|root)) _filedir -d return 0 ;; --eval) # get a list of macros COMPREPLY=( $( sed -ne 's|^\(%'${cur#\%}'[^ '$'\t'']*\).*$|\1|p' \ /usr/lib/rpm/macros ) ) return 0 ;; --pipe) COMPREPLY=( $( compgen -c -- $cur ) ) return 0 ;; --rcfile) _filedir return 0 ;; --specfile) # complete on .spec files _filedir spec return 0 ;; --whatprovides) if [[ "$cur" == */* ]]; then _filedir else # complete on capabilities COMPREPLY=( $( rpm -qa $nodig $nosig --queryformat \ '%{providename}\n' | grep "^$cur" ) ) fi return 0 ;; --whatrequires) # complete on capabilities COMPREPLY=( $( rpm -qa $nodig $nosig --queryformat \ '%{requirename}\n' | grep "^$cur" ) ) return 0 ;; esac case "${COMP_WORDS[1]}" in -@([iFU]*|-install|-freshen|-upgrade)) if [[ "$cur" == -* ]]; then COMPREPLY=( $( compgen -W '--percent --force --test \ --replacepkgs --replacefiles --root --excludedocs \ --includedocs --noscripts --rcfile --ignorearch \ --dbpath --prefix --ignoreos --nodeps --allfiles \ --ftpproxy --ftpport --justdb --httpproxy --httpport \ --noorder --relocate --badreloc --notriggers \ --excludepath --ignoresize --oldpackage --define \ --eval --pipe --queryformat --repackage --nosuggests \ --nodigest --nosignature' -- $cur ) ) else _filedir 'rpm' fi ;; -@(e|-erase)) if [[ "$cur" == -* ]]; then COMPREPLY=( $( compgen -W '--allmatches --noscripts \ --notriggers --nodeps --test --repackage' -- $cur ) ) else _rpm_installed_packages fi ;; -@(q*|-query)) # check whether we're doing file completion if [ "${COMP_LINE#* -*([^ -])f}" != "$COMP_LINE" ]; then if [[ "$cur" == -* ]]; then COMPREPLY=( $( compgen -W '--scripts --root \ --rcfile --requires --ftpport --ftpproxy \ --httpproxy --httpport --provides --triggers \ --dump --changelog --dbpath \ --last --filesbypkg \ --info --list --state \ --docfiles --configfiles --queryformat \ --conflicts --obsoletes \ --nodigest --nosignature \ --triggerscripts' -- $cur ) ) else _filedir fi elif [ "${COMP_LINE#* -*([^ -])g}" != "$COMP_LINE" ]; then _rpm_groups elif [ "${COMP_LINE#* -*([^ -])p}" != "$COMP_LINE" ]; then # uninstalled package completion if [[ "$cur" == -* ]]; then COMPREPLY=( $( compgen -W '--scripts --root \ --rcfile --whatprovides --whatrequires \ --requires --triggeredby --ftpport --ftpproxy \ --httpproxy --httpport --provides --triggers \ --dump --changelog --dbpath --filesbypkg \ --define --eval --pipe --showrc --info --list \ --state --docfiles --configfiles --queryformat\ --conflicts --obsoletes --nodigest \ --nosignature' -- $cur ) ) else _filedir 'rpm' fi else # installed package completion if [[ "$cur" == -* ]]; then COMPREPLY=( $( compgen -W '--scripts --root \ --rcfile --whatprovides --whatrequires \ --requires --triggeredby --ftpport --ftpproxy \ --httpproxy --httpport --provides --triggers \ --dump --changelog --dbpath --specfile \ --querybynumber --last --filesbypkg --define \ --eval --pipe --showrc --info --list --state \ --docfiles --configfiles --queryformat \ --conflicts --obsoletes --pkgid --hdrid \ --fileid --tid --nodigest --nosignature \ --triggerscripts' -- $cur ) ) elif [ "${COMP_LINE#* -*([^ -])a}" == "$COMP_LINE" ]; then _rpm_installed_packages fi fi ;; -@(K*|-checksig)) if [[ "$cur" == -* ]]; then COMPREPLY=( $( compgen -W '--nopgp --nogpg --nomd5 \ --nodigest --nosignature' -- $cur ) ) else _filedir 'rpm' fi ;; -@([Vy]*|-verify)) if [[ "$cur" == -* ]]; then COMPREPLY=( $( compgen -W '--root --rcfile --dbpath \ --nodeps --nogroup --nolinkto --nomode --nomtime \ --nordev --nouser --nofiles --noscripts --nomd5 \ --querytags --specfile --whatrequires --whatprovides \ --nodigest --nosignature' -- $cur ) ) # check whether we're doing file completion elif [ "${COMP_LINE#* -*([^ -])f}" != "$COMP_LINE" ]; then _filedir elif [ "${COMP_LINE#* -*([^ -])g}" != "$COMP_LINE" ]; then _rpm_groups elif [ "${COMP_LINE#* -*([^ -])p}" != "$COMP_LINE" ]; then _filedir 'rpm' else _rpm_installed_packages fi ;; -[bt]*) if [[ "$cur" == -* ]]; then COMPREPLY=( $( compgen -W '--short-circuit --timecheck \ --clean --rmsource --rmspec --test --sign --buildroot \ --target -- buildarch --buildos --nobuild --nodeps \ --nodirtokens' -- $cur ) ) elif [[ ${COMP_WORDS[1]} == -b* ]]; then _filedir 'spec' else _filedir '@(tgz|tar.@(gz|bz2))' fi ;; --re@(build|compile)) if [[ "$cur" == -* ]]; then COMPREPLY=( $( compgen -W '--nodeps --rmsource \ --rmspec --sign --nodirtokens --target' -- $cur ) ) else _filedir '?(no)src.rpm' fi ;; --tarbuild) _filedir '@(tgz|tar.@(gz|bz2))' ;; --@(re|add)sign) _filedir 'rpm' ;; --set@(perms|gids)) _rpm_installed_packages ;; --@(clean|rms@(ource|pec))) if [[ "$cur" == -* ]]; then COMPREPLY=( $( compgen -W '--clean --rmsource \ --rmspec' -- $cur ) ) else _filedir 'spec' fi ;; --@(import|dbpath|root)) if [[ "$cur" == -* ]]; then COMPREPLY=( $( compgen -W '--import --dbpath --root' \ -- $cur ) ) else _filedir fi ;; esac return 0}complete -F _rpm $filenames rpm rpmbuild}# Debian apt-get(8) completion.#have apt-get &&_apt_get(){ local cur prev special i COMPREPLY=() cur=`_get_cword` prev=${COMP_WORDS[COMP_CWORD-1]} for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do if [[ ${COMP_WORDS[i]} == @(install|remove|purge|source|build-dep) ]]; then special=${COMP_WORDS[i]} fi done if [ -n "$special" ]; then case $special in remove|purge) if [ -f /etc/debian_version ]; then # Debian system COMPREPLY=( $( _comp_dpkg_installed_packages \ $cur ) ) else # assume RPM based _rpm_installed_packages fi return 0 ;; *) COMPREPLY=( $( apt-cache pkgnames $cur 2> /dev/null ) ) return 0 ;; esac fi case "$prev" in -@(c|-config-file)) _filedir return 0 ;; -@(t|-target-release|-default-release)) COMPREPLY=( $( apt-cache policy | \ grep "release.o=Debian,a=$cur" | \ sed -e "s/.*a=\(\w*\).*/\1/" | uniq 2> /dev/null) ) return 0 ;; esac if [[ "$cur" == -* ]]; then COMPREPLY=( $( compgen -W '-d -f -h -v -m -q -s -y \ -u -t -b -c -o --download-only --fix-broken \ --help --version --ignore-missing \ --fix-missing --no-download --quiet --simulate \ --just-print --dry-run --recon --no-act --yes \ --assume-yes --show-upgraded --only-source \ --compile --build --ignore-hold \ --target-release --no-upgrade --force-yes \ --print-uris --purge --reinstall \ --list-cleanup --default-release \ --trivial-only --no-remove --diff-only \
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -