?? bash_completion
字號:
_complete(){ local cur prev options COMPREPLY=() cur=`_get_cword` prev=${COMP_WORDS[COMP_CWORD-1]} case $prev in -o) options="default dirnames filenames" [ -n "$bash205b" ] && options="$options nospace" [ -n "$bash3" ] && options="$options bashdefault plusdirs" COMPREPLY=( $( compgen -W "$options" -- $cur ) ) return 0 ;; -A) COMPREPLY=( $( compgen -W 'alias arrayvar binding \ builtin command directory disabled enabled \ export file function group helptopic hostname \ job keyword running service setopt shopt \ signal stopped user variable' -- $cur ) ) return 0 ;; -C) COMPREPLY=( $( compgen -A command -- $cur ) ) return 0 ;; -F) COMPREPLY=( $( compgen -A function -- $cur ) ) return 0 ;; -@(p|r)) COMPREPLY=( $( complete -p | sed -e 's|.* ||' | \ grep "^$cur" ) ) return 0 ;; esac if [[ "$cur" == -* ]]; then # relevant options completion options="-a -b -c -d -e -f -g -j -k -s -v -u -A -G -W -P -S -X -F -C" [ -n "$bash205" ] && options="$options -o" COMPREPLY=( $( compgen -W "$options" -- $cur ) ) else COMPREPLY=( $( compgen -A command -- $cur ) ) fi}complete -F _complete complete# start of section containing completion functions for external programs# a little help for FreeBSD ports users[ $UNAME = FreeBSD ] && complete -W 'index search fetch fetch-list \ extract patch configure build install reinstall \ deinstall clean clean-depends kernel buildworld' make# This completes on a list of all available service scripts for the# 'service' command and/or the SysV init.d directory, followed by# that script's available commands#{ have service || [ -d /etc/init.d/ ]; } &&_service(){ local cur sysvdir COMPREPLY=() prev=${COMP_WORDS[COMP_CWORD-1]} cur=`_get_cword` # don't complete for things like killall, ssh and mysql if it's # the standalone command, rather than the init script [[ ${COMP_WORDS[0]} != @(*init.d/!(functions|~)|service) ]] && return 0 # don't complete past 2nd token [ $COMP_CWORD -gt 2 ] && return 0 [ -d /etc/rc.d/init.d ] && sysvdir=/etc/rc.d/init.d \ || sysvdir=/etc/init.d if [[ $COMP_CWORD -eq 1 ]] && [[ $prev == "service" ]]; then _services else COMPREPLY=( $( compgen -W '`sed -ne "y/|/ /; \ s/^.*Usage.*{\(.*\)}.*$/\1/p" \ $sysvdir/${prev##*/} 2>/dev/null`' -- $cur ) ) fi return 0} &&complete -F _service service[ -d /etc/init.d/ ] && complete -F _service $default \ $(for i in /etc/init.d/*; do echo ${i##*/}; done)# chown(1) completion#_chown(){ local cur cur=`_get_cword` # options completion if [[ "$cur" == -* ]]; then COMPREPLY=( $( compgen -W '-c -h -f -R -v --changes \ --dereference --no-dereference --from= --silent --quiet \ --reference= --recursive --verbose --help --version' -- $cur ) ) else _count_args case $args in 1) _usergroup ;; *) _filedir ;; esac fi}complete -F _chown $filenames chown# chgrp(1) completion#_chgrp(){ local cur prev COMPREPLY=() cur=`_get_cword` cur=${cur//\\\\/} prev=${COMP_WORDS[COMP_CWORD-1]} # options completion if [[ "$cur" == -* ]]; then COMPREPLY=( $( compgen -W '-c -h -f -R -v --changes \ --dereference --no-dereference --silent --quiet \ --reference= --recursive --verbose --help --version' -- $cur ) ) return 0 fi # first parameter on line or first since an option? if [ $COMP_CWORD -eq 1 ] && [[ "$cur" != -* ]] || \ [[ "$prev" == -* ]] && [ -n "$bash205" ]; then local IFS=$'\n' COMPREPLY=( $( compgen -g $cur 2>/dev/null ) ) else _filedir || return 0 fi return 0}complete -F _chgrp $filenames chgrp# umount(8) completion. This relies on the mount point being the third# space-delimited field in the output of mount(8)#_umount(){ local cur COMPREPLY=() cur=`_get_cword` OLDIFS="$IFS" IFS="\n" COMPREPLY=( $( compgen -W '$( mount | cut -d" " -f 3 )' -- $cur ) ) IFS="$OLDIFS" return 0}complete -F _umount $dirnames umount# mount(8) completion. This will pull a list of possible mounts out of# /etc/{,v}fstab, unless the word being completed contains a ':', which# would indicate the specification of an NFS server. In that case, we# query the server for a list of all available exports and complete on# that instead.#_mount(){ local cur i sm host COMPREPLY=() cur=`_get_cword` [[ "$cur" == \\ ]] && cur="/" for i in {,/usr}/{,s}bin/showmount; do [ -x $i ] && sm=$i && break; done if [ -n "$sm" ] && [[ "$cur" == *:* ]]; then COMPREPLY=( $( $sm -e ${cur%%:*} | sed 1d | \ grep ^${cur#*:} | awk '{print $1}' ) ) elif [[ "$cur" == //* ]]; then host=${cur#//} host=${host%%/*} if [ -n "$host" ]; then COMPREPLY=( $( compgen -W "$( echo $( smbclient -d 0 -NL $host 2>/dev/null| sed -ne '/^['"$'\t '"']*Sharename/,/^$/p' | sed -ne '3,$s|^[^A-Za-z]*\([^'"$'\t '"']*\).*$|//'$host'/\1|p' ) )" -- "$cur" ) ) fi elif [ -r /etc/vfstab ]; then # Solaris COMPREPLY=( $( awk '! /^[ \t]*#/ {if ($3 ~ /\//) print $3}' \ /etc/vfstab | grep "^$cur" ) ) elif [ ! -e /etc/fstab ]; then # probably Cygwin COMPREPLY=( $( mount | awk '! /^[ \t]*#/ {if ($3 ~ /\//) print $3}' \ | grep "^$cur" ) ) else # probably Linux COMPREPLY=( $( awk '! /^[ \t]*#/ {if ($2 ~ /\//) print $2}' \ /etc/fstab | grep "^$cur" ) ) fi return 0}complete -F _mount $default $filenames mount# Linux rmmod(8) completion. This completes on a list of all currently# installed kernel modules.#have rmmod && {_rmmod(){ local cur COMPREPLY=() cur=`_get_cword` COMPREPLY=( $( /sbin/lsmod | \ awk '{if (NR != 1 && $1 ~ /^'$cur'/) print $1}' 2>/dev/null )) return 0}complete -F _rmmod rmmod# Linux insmod(8), modprobe(8) and modinfo(8) completion. This completes on a# list of all available modules for the version of the kernel currently# running.#_insmod(){ local cur prev modpath COMPREPLY=() cur=`_get_cword` prev=${COMP_WORDS[COMP_CWORD-1]} # behave like lsmod for modprobe -r if [ $1 = "modprobe" ] && [ "${COMP_WORDS[1]}" = "-r" ]; then COMPREPLY=( $( /sbin/lsmod | \ awk '{if (NR != 1 && $1 ~ /^'$cur'/) print $1}' ) ) return 0 fi # do filename completion if we're giving a path to a module if [[ "$cur" == */* ]]; then _filedir '@(?(k)o?(.gz))' return 0 fi if [ $COMP_CWORD -gt 1 ] && [[ "${COMP_WORDS[COMP_CWORD-1]}" != -* ]]; then # do module parameter completion COMPREPLY=( $( /sbin/modinfo -p ${COMP_WORDS[1]} 2>/dev/null | \ awk '{if ($1 ~ /^parm:/ && $2 ~ /^'$cur'/) { print $2 } \ else if ($1 !~ /:/ && $1 ~ /^'$cur'/) { print $1 }}' ) ) else _modules $(uname -r) fi return 0}complete -F _insmod $filenames insmod modprobe modinfo}# man(1) completion#[ $UNAME = GNU -o $UNAME = Linux -o $UNAME = Darwin \ -o $UNAME = FreeBSD -o $UNAME = SunOS -o $UNAME = Cygwin \ -o $UNAME = OpenBSD ] &&_man(){ local cur prev sect manpath UNAME COMPREPLY=() cur=`_get_cword` prev=${COMP_WORDS[COMP_CWORD-1]} _expand || return 0 # default completion if parameter contains / if [[ "$cur" == */* ]]; then _filedir return 0 fi UNAME=$( uname -s ) # strip OS type and version under Cygwin UNAME=${UNAME/CYGWIN_*/Cygwin} if [ $UNAME = GNU -o $UNAME = Linux -o $UNAME = FreeBSD \ -o $UNAME = Cygwin ]; then manpath=$( manpath 2>/dev/null || command man --path ) else manpath=$MANPATH fi if [ -z "$manpath" ]; then COMPREPLY=( $( compgen -c -- $cur ) ) return 0 fi # determine manual section to search [[ "$prev" == [0-9ln] ]] && sect=$prev || sect='*' manpath=$manpath: if [ -n "$cur" ]; then manpath="${manpath//://*man$sect/$cur* } ${manpath//://*cat$sect/$cur* }" else manpath="${manpath//://*man$sect/ } ${manpath//://*cat$sect/ }" fi # redirect stderr for when path doesn't exist COMPREPLY=( $( eval command ls "$manpath" 2>/dev/null ) ) # weed out directory path names and paths to man pages COMPREPLY=( ${COMPREPLY[@]##*/?(:)} ) # strip suffix from man pages COMPREPLY=( ${COMPREPLY[@]%.@(gz|bz2)} ) COMPREPLY=( $( compgen -W '${COMPREPLY[@]%.*}' -- "${cur//\\\\/}" ) ) [[ "$prev" != [0-9ln] ]] && _filedir '[0-9ln]' return 0}[ $UNAME = GNU -o $UNAME = Linux -o $UNAME = Darwin \ -o $UNAME = FreeBSD -o $UNAME = SunOS -o $UNAME = Cygwin \ -o $UNAME = OpenBSD ] && \complete -F _man $filenames man apropos whatis# renice(8) completion#_renice(){ local command cur curopt i COMPREPLY=() cur=`_get_cword` command=$1 i=0 # walk back through command line and find last option while [ $i -le $COMP_CWORD -a ${#COMPREPLY[@]} -eq 0 ]; do curopt=${COMP_WORDS[COMP_CWORD-$i]} case "$curopt" in -u) COMPREPLY=( $( compgen -u -- $cur ) ) ;; -g) _pgids ;; -p|$command) _pids ;; esac i=$(( ++i )) done}complete -F _renice renice# kill(1) completion#_kill(){ local cur COMPREPLY=() cur=`_get_cword` if [ $COMP_CWORD -eq 1 ] && [[ "$cur" == -* ]]; then # return list of available signals _signals else # return list of available PIDs _pids fi}complete -F _kill kill# Linux and FreeBSD killall(1) completion.#[ $UNAME = Linux -o $UNAME = FreeBSD ] &&_killall(){ local cur COMPREPLY=() cur=`_get_cword` if [ $COMP_CWORD -eq 1 ] && [[ "$cur" == -* ]]; then _signals else COMPREPLY=( $( compgen -W '$( command ps axo command | \ sed -ne "1d; s/^\[\?\([^-][^] ]*\).*$/\1/p" | \ sed -e "s/.*\///" )' -- $cur ) ) fi return 0}[ $UNAME = Linux -o $UNAME = FreeBSD ] && complete -F _killall killall pkill# Linux and FreeBSD pgrep(1) completion.#[ $UNAME = Linux -o $UNAME = FreeBSD ] &&_pgrep(){ local cur COMPREPLY=() cur=`_get_cword` COMPREPLY=( $( compgen -W '$( command ps axo command | \ sed -ne "1d; s/^\[\?\([^-][^] ]*\).*$/\1/p" | \ sed -e "s/.*\///" )' -- $cur ) ) return 0}[ $UNAME = Linux -o $UNAME = FreeBSD ] && complete -F _pgrep pgrep# Linux pidof(8) completion.[ $UNAME = Linux ] && complete -F _pgrep pidof# GNU find(1) completion. This makes heavy use of ksh style extended# globs and contains Linux specific code for completing the parameter# to the -fstype option.#_find(){ local cur prev i exprfound onlyonce COMPREPLY=() cur=`_get_cword` prev=${COMP_WORDS[COMP_CWORD-1]} case "$prev" in -@(max|min)depth) COMPREPLY=( $( compgen -W '0 1 2 3 4 5 6 7 8 9' -- $cur ) ) return 0 ;; -?(a|c)newer|-fls|-fprint?(0|f)|-?(i)?(l)name|-?(i)wholename) _filedir return 0 ;; -fstype) # this is highly non-portable [ -e /proc/filesystems ] && COMPREPLY=( $( cut -d$'\t' -f 2 /proc/filesystems | \ grep "^$cur" ) ) return 0 ;; -gid) _gids return 0 ;; -group) if [ -n "$bash205" ]; then COMPREPLY=( $( compgen -g -- $cur 2>/dev/null) ) fi return 0 ;; -?(x)type) COMPREPLY=( $( compgen -W 'b c d p f l s' -- $cur ) ) return 0 ;; -uid) _uids return 0 ;; -user) COMPREPLY=( $( compgen -u -- $cur ) ) return 0 ;; -exec|-ok) COMP_WORDS=(COMP_WORDS[0] $cur) COMP_CWORD=1 _command return 0 ;; -[acm]min|-[acm]time|-?(i)?(l)name|-inum|-?(i)path|-?(i)regex| \ -links|-perm|-size|-used|-printf) # do nothing, just wait for a parameter to be given return 0 ;; esac _expand || return 0 # set exprfound to 1 if there is already an expression present for i in ${COMP_WORDS[@]}; do [[ "$i" = [-\(\),\!]* ]] && exprfound=1 && break done # handle case where first parameter is not a dash option if [ "$exprfound" != 1 ] && [[ "$cur" != [-\(\),\!]* ]]; then _filedir -d return 0 fi # complete using basic options COMPREPLY=( $( compgen -W '-daystart -depth -follow -help -maxdepth \ -mindepth -mount -noleaf -version -xdev -amin -anewer \ -atime -cmin -cnewer -ctime -empty -false -fstype \ -gid -group -ilname -iname -inum -ipath -iregex \ -wholename \ -links -lname -mmin -mtime -name -newer -nouser \ -nogroup -perm -regex -size -true -type -uid -used \ -user -xtype -exec -fls -fprint -fprint0 -fprintf -ok \ -print -print0 -printf -prune -ls' -- $cur ) ) # this removes any options from the list of completions that have # already been specified somewhere on the command line, as long as # these options can only be used once (in a word, "options", in # opposition to "tests" and "actions", as in the find(1) manpage). onlyonce=' -daystart -depth -follow -help -maxdepth -mindepth -mount \ -noleaf -version -xdev ' COMPREPLY=( $( echo "${COMP_WORDS[@]}" | \ (while read -d ' ' i; do [ "$i" == "" ] || [ "${onlyonce/ ${i%% *} / }" == "$onlyonce" ] && continue # flatten array with spaces on either side, # otherwise we cannot grep on word boundaries of # first and last word COMPREPLY=" ${COMPREPLY[@]} " # remove word from list of completions COMPREPLY=( ${COMPREPLY/ ${i%% *} / } ) done echo "${COMPREPLY[@]}") ) )
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -