# umount(8) completion -*- shell-script -*- # Just like COMPREPLY=(`compgen -W "${COMPREPLY[*]}" -- "$cur"`), only better! # # This will correctly escape special characters in COMPREPLY. proc _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. var i = '', wlist = '' for i in [$(!COMPREPLY[*])] { var q = $[quote $[printf %q $(COMPREPLY[$i])]] set wlist = "$q$'\n"' } # We also have to add another round of escaping to $cur. var ecur = $cur set ecur = $(ecur//\\/\\\\) set ecur = $(ecur//\'/\\\') # Actually generate completions. var oldifs = $IFS env IFS=$'\n' eval 'COMPREPLY=(`compgen -W "$wlist" -- "${ecur}"`)' setglobal IFS = $oldifs } # Unescape strings in the linux fstab(5) format (with octal escapes). proc __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. proc _linux_fstab { setglobal COMPREPLY = ''() # Read and unescape values into COMPREPLY var fs_spec = '', fs_file = '', fs_other = '' var oldifs = $IFS while read -r fs_spec fs_file fs_other { if [[ $fs_spec == [#]* ]] { continue; } if [[ $1 == -L ]] { var fs_label = $(fs_spec/#LABEL=) if [[ $fs_label != "$fs_spec" ]] { __linux_fstab_unescape fs_label setglobal IFS = '$'\0'' setglobal COMPREPLY = '('"$fs_label") setglobal IFS = $oldifs } } else { __linux_fstab_unescape fs_spec __linux_fstab_unescape fs_file setglobal IFS = '$'\0'' [[ $fs_spec == */* ]] && setglobal COMPREPLY = '('"$fs_spec") [[ $fs_file == */* ]] && setglobal COMPREPLY = '('"$fs_file") setglobal IFS = $oldifs } } # Add relative paths to COMPREPLY if [[ $cur && $cur != /* ]] { var realcur = '' [[ $cur == */ ]] && # don't let readlink drop last / from path set realcur = ""$[ readlink -f "$cur." !2 > /dev/null]/"" || set realcur = $[ readlink -f $cur !2 > /dev/null] if [[ $realcur ]] { var dirrealcur = '', dircur = '', basecur = '' if [[ $cur == */* ]] { set dirrealcur = ""$(realcur%/*)/"" set dircur = ""$(cur%/*)/"" } set basecur = $(cur#"$dircur") var i = '', n = $(#COMPREPLY[@]) for (( i=0; i < $n; i++ )); do [[ "${COMPREPLY[i]}" == "$realcur"* ]] && COMPREPLY+=( $( cd "$dircur" 2> /dev/null && compgen -f -d -P "$dircur" \ -X "!${COMPREPLY[i]##"$dirrealcur"}" -- "$basecur" ) ) done } } _reply_compgen_array } proc _umount { var cur = '', prev = '', words = '', cword = '' _init_completion || return match $prev { with -t # FIXME: no var split = 'false' if [[ "$cur" == ?*,* ]] { set prev = $(cur%,*) set cur = $(cur##*,) set split = 'true' } setglobal COMPREPLY = '( '$( compgen -W 'adfs affs autofs btrfs cifs coda cramfs debugfs devpts efs ext2 ext3 ext4 fuse hfs hfsplus hpfs iso9660 jfs minix msdos ncpfs nfs nfs4 ntfs ntfs-3g proc qnx4 ramfs reiserfs romfs squashfs smbfs sysv tmpfs ubifs udf ufs umsdos usbfs vfat xfs' -- "$cur" ) ) _fstypes $split && setglobal COMPREPLY = '( '${COMPREPLY[@]/#/$prev,} ) return with -O # argument required but no completions available return } if [[ "$cur" == -* ]] { setglobal COMPREPLY = '( '$( compgen -W '-V -h -v -n -r -d -i -a -t -O -f -l --no-canonicalize --fake' -- "$cur" ) ) [[ $COMPREPLY ]] && return } if [[ -r /proc/mounts ]] { # Linux /proc/mounts is properly quoted. This is important when # unmounting usb devices with pretty names. _linux_fstab < /proc/mounts } else { var IFS = '$'\n'' setglobal COMPREPLY = '( '$( compgen -W '$( mount | cut -d" " -f 3 )' -- "$cur" ) ) } } && complete -F _umount -o dirnames umount # ex: ts=4 sw=4 et filetype=sh