Blame | Last modification | View Log | RSS feed
# Completions for tools included in util-linux (not necessarily Linux specific)# renice(8) completion#have renice &&_renice(){local command cur curopt iCOMPREPLY=()_get_comp_words_by_ref curcommand=$1i=0# walk back through command line and find last optionwhile [[ $i -le $COMP_CWORD && ${#COMPREPLY[@]} -eq 0 ]]; docuropt=${COMP_WORDS[COMP_CWORD-$i]}case "$curopt" in-u)_allowed_users;;-g)_pgids;;-p|$command)_pids;;esaci=$(( ++i ))done} &&complete -F _renice renice# kill(1) completion#have kill &&_kill(){local curCOMPREPLY=()_get_comp_words_by_ref curif [[ $COMP_CWORD -eq 1 && "$cur" == -* ]]; then# return list of available signals_signalselse# return list of available PIDs_pidsfi} &&complete -F _kill kill# look(1) completion#have look &&_look(){local curCOMPREPLY=()_get_comp_words_by_ref curif [ $COMP_CWORD = 1 ]; thenCOMPREPLY=( $( compgen -W '$(look "$cur" 2>/dev/null)' -- "$cur" ) )fi} &&complete -F _look -o default look# Local variables:# mode: shell-script# sh-basic-offset: 4# sh-indent-comment: t# indent-tabs-mode: nil# End:# ex: ts=4 sw=4 et filetype=sh# chsh(1) completion_chsh(){local cur prevCOMPREPLY=()_get_comp_words_by_ref cur prevcase $prev in--list-shells|--help|-v|--version)return 0;;-s|--shell)_shellsreturn 0;;esacif [[ "$cur" == -* && "$( uname -s )" == @(Linux|GNU|GNU/*) ]]; thenCOMPREPLY=( $( compgen -W '--shell --list-shells --help --version' \-- "$cur" ) )elseCOMPREPLY=( $( compgen -u -- "$cur" ) )fireturn 0}complete -F _chsh chsh# Local variables:# mode: shell-script# sh-basic-offset: 4# sh-indent-comment: t# indent-tabs-mode: nil# End:# ex: ts=4 sw=4 et filetype=sh# 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.#have mount &&{# Just like COMPREPLY=(`compgen -W "${COMPREPLY[*]}" -- "$cur"`), only better!## This will correctly escape special characters in COMPREPLY._reply_compgen_array(){# Create the argument for compgen -W by escaping twice.## One round of escape is because we want to reply with escaped arguments. A# second round is required because compgen -W will helpfully expand it's# argument.local i wlistfor i in ${!COMPREPLY[*]}; dolocal q=$(quote "$(printf %q "${COMPREPLY[$i]}")")wlist+=$q$'\n'done# We also have to add another round of escaping to $cur.local ecur="$cur"ecur="${ecur//\\/\\\\}"ecur="${ecur//\'/\'}"# Actually generate completions.local oldifs=$IFSIFS=$'\n' eval 'COMPREPLY=(`compgen -W "$wlist" -- "${ecur}"`)'IFS=$oldifs}# Unescape strings in the linux fstab(5) format (with octal escapes).__linux_fstab_unescape() {eval $1="'${!1//\'/\047}'"eval $1="'${!1/%\\/\\\\}'"eval "$1=$'${!1}'"}# Complete linux fstab entries.## Reads a file from stdin in the linux fstab(5) format; as used by /etc/fstab# and /proc/mounts._linux_fstab(){COMPREPLY=()# Read and unescape values into COMPREPLYlocal fs_spec fs_file fs_otherlocal oldifs="$IFS"while read -r fs_spec fs_file fs_other; doif [[ $fs_spec = [#]* ]]; then continue; fiif [[ $1 == -L ]]; thenlocal fs_label=${fs_spec/#LABEL=}if [[ $fs_label != "$fs_spec" ]]; then__linux_fstab_unescape fs_labelIFS=$'\0'COMPREPLY+=("$fs_label")IFS=$oldifsfielse__linux_fstab_unescape fs_spec__linux_fstab_unescape fs_fileIFS=$'\0'[[ $fs_spec = */* ]] && COMPREPLY+=("$fs_spec")[[ $fs_file = */* ]] && COMPREPLY+=("$fs_file")IFS=$oldifsfidone_reply_compgen_array}_mount(){local cur sm host prevCOMPREPLY=()_get_comp_words_by_ref -n : cur prevcase $prev in-t|--types)_fstypesreturn 0;;esac[[ "$cur" == \\ ]] && cur="/"if [[ "$cur" == *:* ]]; thenfor sm in "$(type -P showmount)" {,/usr}/{,s}bin/showmount; do[ -x "$sm" ] || continueCOMPREPLY=( $( compgen -W "$( "$sm" -e ${cur%%:*} | \awk 'NR>1 {print $1}' )" -- "${cur#*:}" ) )return 0donefiif [[ "$cur" == //* ]]; thenhost=${cur#//}host=${host%%/*}if [ -n "$host" ]; thenCOMPREPLY=( $( compgen -P "//$host" -W \"$( smbclient -d 0 -NL $host 2>/dev/null |sed -ne '/^['"$'\t '"']*Sharename/,/^$/p' |sed -ne '3,$s|^[^A-Za-z]*\([^'"$'\t '"']*\).*$|/\1|p' )" \-- "${cur#//$host}" ) )fielif [ -r /etc/vfstab ]; then# SolarisCOMPREPLY=( $( compgen -W "$( awk '! /^[ \t]*#/ {if ($3 ~ /\//) print $3}' /etc/vfstab )" -- "$cur" ) )elif [ ! -e /etc/fstab ]; then# probably CygwinCOMPREPLY=( $( compgen -W "$( mount | awk '! /^[ \t]*#/ {if ($3 ~ /\//) print $3}' )" -- "$cur" ) )else# probably Linuxif [ "$prev" = -L ]; then_linux_fstab -L < /etc/fstabelif [ "$prev" = -U ]; thenCOMPREPLY=( $( compgen -W '$(sed -ne "s/^[[:space:]]*UUID=\([^[:space:]]*\).*/\1/p" /etc/fstab )' -- "$cur" ) )else_linux_fstab < /etc/fstabfifireturn 0} &&complete -F _mount -o default -o dirnames mount# umount(8) completion. This relies on the mount point being the third# space-delimited field in the output of mount(8)#have umount &&_umount(){local cur_get_comp_words_by_ref curCOMPREPLY=()if [[ $(uname -s) = Linux && -r /proc/mounts ]]; then# Linux /proc/mounts is properly quoted. This is important when# unmounting usb devices with pretty names._linux_fstab < /proc/mountselselocal IFS=$'\n'COMPREPLY=( $( compgen -W '$( mount | cut -d" " -f 3 )' -- "$cur" ) )fireturn 0} &&complete -F _umount -o dirnames umount}# Local variables:# mode: shell-script# sh-basic-offset: 4# sh-indent-comment: t# indent-tabs-mode: nil# End:# ex: ts=4 sw=4 et filetype=sh# bash completion for rtcwakehave rtcwake &&_rtcwake(){COMPREPLY=()local cur prev split=false_get_comp_words_by_ref cur prev_split_longopt && split=truecase "$prev" in--help|-h|--version|-V|--seconds|-s|--time|-t)return 0;;--mode|-m)COMPREPLY=( $( compgen -W 'standby mem disk on no off' -- "$cur" ) )return 0;;--device|-d)COMPREPLY=( $( command ls -d /dev/rtc?* 2>/dev/null ) )COMPREPLY=( $( compgen -W '${COMPREPLY[@]#/dev/}' -- "$cur" ) )return 0;;esac$split && return 0COMPREPLY=( $( compgen -W '--device --local --mode --seconds --time --utc \--verbose --version --help' -- "$cur" ) )} &&complete -F _rtcwake rtcwake# Local variables:# mode: shell-script# sh-basic-offset: 4# sh-indent-comment: t# indent-tabs-mode: nil# End:# ex: ts=4 sw=4 et filetype=sh