bash-completion: misc-utils

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
Sami Kerola 2013-03-23 17:41:32 +00:00
parent 41e5a92cf1
commit 76dceb10a1
15 changed files with 580 additions and 0 deletions

64
shell-completion/blkid Normal file
View File

@ -0,0 +1,64 @@
_blkid_module()
{
local cur prev OPTS
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
case $prev in
'-c')
compopt -o filenames
COMPREPLY=( $(compgen -f -- $cur) )
return 0
;;
'-o')
COMPREPLY=( $(compgen -W "value device export full" -- $cur) )
return 0
;;
'-s')
COMPREPLY=( $(compgen -W "tag" -- $cur) )
return 0
;;
'-t')
COMPREPLY=( $(compgen -W "token" -- $cur) )
return 0
;;
'-L')
COMPREPLY=( $(compgen -W "$(cd /dev/disk/by-label/ 2>/dev/null && echo *)" -- $cur) )
return 0
;;
'-U')
COMPREPLY=( $(compgen -W "$(cd /dev/disk/by-uuid/ 2>/dev/null && echo *)" -- $cur) )
return 0
;;
'-s')
COMPREPLY=( $(compgen -W "size" -- $cur) )
return 0
;;
'-O')
COMPREPLY=( $(compgen -W "offset" -- $cur) )
return 0
;;
'-u')
COMPREPLY=( $(compgen -W "filesystem raid crypto other nofilesystem noraid nocrypto noother" -- $cur) )
return 0
;;
'-n')
COMPREPLY=( $(compgen -W "$(awk '{print $NF}' /proc/filesystems)" -- $cur) )
return 0
;;
esac
case $cur in
-*)
OPTS="-c -d -h -g -o -k -s -t -l -L -U -V -p -i -S -O -u -n"
COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
return 0
;;
esac
local DEV TYPE DEVICES=''
while read DEV TYPE; do
[ $TYPE = 'part' ] && DEVICES+="$DEV "
done < <(lsblk -pnro name,type)
COMPREPLY=( $(compgen -W "$DEVICES" -- $cur) )
return 0
}
complete -F _blkid_module blkid

15
shell-completion/cal Normal file
View File

@ -0,0 +1,15 @@
_cal_module()
{
local cur OPTS
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
case $cur in
-*)
OPTS="-1 --one -3 --three -s --sunday -m --monday -j --julian -y --year -V --version -h --help"
COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
return 0
;;
esac
return 0
}
complete -F _cal_module cal

121
shell-completion/findmnt Normal file
View File

@ -0,0 +1,121 @@
_findmnt_module()
{
local cur prev OPTS
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
case $prev in
'-p'|'--poll')
COMPREPLY=( $(compgen -W "=list" -- $cur) )
return 0
;;
'-w'|'--timeout')
COMPREPLY=( $(compgen -W "timeout" -- $cur) )
return 0
;;
'-d'|'--direction')
COMPREPLY=( $(compgen -W "forward backward" -- $cur) )
return 0
;;
'-F'|'--tab-file')
compopt -o filenames
COMPREPLY=( $(compgen -f -- $cur) )
return 0
;;
'-N'|'--task')
local TID='' I ARR
for I in /proc/*/mountinfo; do IFS=/ read -ra ARR <<< "$I"; TID+="${ARR[2]} "; done
COMPREPLY=( $(compgen -W "$TID" -- $cur) )
return 0
;;
'-O'|'--options')
local MTAB_3RD I
declare -a TMP_ARR
declare -A MNT_OPTS
while read MTAB_3RD; do
IFS=',' read -ra TMP_ARR <<<"$MTAB_3RD"
for I in ${TMP_ARR[@]}; do
MNT_OPTS[$I]='1'
done
done < <(findmnt -rno OPTIONS)
COMPREPLY=( $(compgen -W "$(echo ${!MNT_OPTS[@]})" -- $cur) )
return 0
;;
'-o'|'--output')
# FIXME: how to append to a string with compgen?
local OUTPUT
OUTPUT="SOURCE TARGET FSTYPE OPTIONS VFS-OPTIONS
FS-OPTIONS LABEL UUID PARTLABEL PARTUUID
MAJ\:MIN ACTION OLD-TARGET OLD-OPTIONS
SIZE AVAIL USED USE% FSROOT TID ID
OPT-FIELDS PROPAGATION FREQ PASSNO"
compopt -o nospace
COMPREPLY=( $(compgen -W "$OUTPUT" -S ',' -- $cur) )
return 0
;;
'-t'|'--types')
local TYPES
TYPES="adfs affs autofs cifs coda coherent cramfs
debugfs devpts efs ext ext2 ext3 ext4 hfs
hfsplus hpfs iso9660 jfs minix msdos
ncpfs nfs nfs4 ntfs proc qnx4 ramfs
reiserfs romfs squashfs smbfs sysv tmpfs
ubifs udf ufs umsdos usbfs vfat xenix xfs
xiafs"
COMPREPLY=( $(compgen -W "$TYPES" -- $cur) )
return 0
;;
'-S'|'--source')
local DEV_MPOINT
DEV_MPOINT=$(findmnt -rno SOURCE | grep ^/dev)
COMPREPLY=( $(compgen -W "$DEV_MPOINT" -- $cur) )
return 0
;;
'-T'|'--target')
local DEV_MPOINT
DEV_MPOINT=$(findmnt -rno TARGET)
COMPREPLY=( $(compgen -W "$DEV_MPOINT" -- $cur) )
return 0
;;
esac
case $cur in
-*)
OPTS="-s --fstab
-m --mtab
-k --kernel
-p --poll
-w --timeout
-A --all
-a --ascii
-c --canonicalize
-D --df
-d --direction
-e --evaluate
-F --tab-file
-f --first-only
-i --invert
-l --list
-N --task
-n --noheadings
-u --notruncate
-O --options
-o --output
-P --pairs
-r --raw
-t --types
-v --nofsroot
-R --submounts
-S --source
-T --target
-h --help
-V --version"
COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
return 0
;;
esac
local DEV_MPOINT
DEV_MPOINT=$(findmnt -rno TARGET,SOURCE)
COMPREPLY=( $(compgen -W "$DEV_MPOINT" -- $cur) )
return 0
}
complete -F _findmnt_module findmnt

34
shell-completion/getopt Normal file
View File

@ -0,0 +1,34 @@
_getopt_module()
{
local cur prev OPTS
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
case $prev in
'-l'|'--longoptions')
COMPREPLY=( $(compgen -W "longopts" -- $cur) )
return 0
;;
'-n'|'--name')
COMPREPLY=( $(compgen -W "name" -- $cur) )
return 0
;;
'-o'|'--options')
COMPREPLY=( $(compgen -W "optstring" -- $cur) )
return 0
;;
'-s'|'--shell')
COMPREPLY=( $(compgen -W "sh bash csh tcsh" -- $cur) )
return 0
;;
esac
case $cur in
-*)
OPTS="-a --alternative -h --help -l --longoptions -n --name -o --options -q --quiet -Q --quiet-output -s --shell -T --test -u --unquote -V --version"
COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
return 0
;;
esac
return 0
}
complete -F _getopt_module getopt

43
shell-completion/logger Normal file
View File

@ -0,0 +1,43 @@
_logger_module()
{
local cur prev OPTS
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
case $prev in
'-f'|'--file')
compopt -o filenames
COMPREPLY=( $(compgen -f -- $cur) )
return 0
;;
'-n'|'--server')
COMPREPLY=( $(compgen -A hostname -- $cur) )
return 0
;;
'-P'|'--port')
COMPREPLY=( $(compgen -W "$(awk '$1 ~ /^syslog$/ {split($2, a, "/"); print a[1]}' /etc/services)" -- $cur) )
return 0
;;
'-p'|'--priority')
COMPREPLY=( $(compgen -W "$(echo {auth,authpriv,cron,daemon,ftp,lpr,mail,news,security}.{alert,crit,debug,emerg,err,error})" -- $cur) )
return 0
;;
'-t'|'--tag')
COMPREPLY=( $(compgen -W "tag" -- $cur) )
return 0
;;
'-u'|'--socket')
COMPREPLY=( $(compgen -W "$(awk '$NF ~ /^\// {print $NF}' /proc/net/unix)" -- $cur) )
return 0
;;
esac
case $cur in
-*)
OPTS="-d --udp -i --id -f --file -h --help -n --server -P --port -p --priority -s --stderr -t --tag -u --socket -V --version"
COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
return 0
;;
esac
return 0
}
complete -F _logger_module logger

24
shell-completion/look Normal file
View File

@ -0,0 +1,24 @@
_look_module()
{
local cur prev OPTS
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
case $prev in
'-t'|'--terminate')
COMPREPLY=( $(compgen -W "char" -- $cur) )
return 0
;;
esac
case $cur in
-*)
OPTS="-a --alternative -d --alphanum -f --ignore-case -t --terminate -V --version -h --help"
COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
return 0
;;
esac
compopt -o filenames
COMPREPLY=( $(compgen -f -- $cur) )
return 0
}
complete -F _look_module look

65
shell-completion/lsblk Normal file
View File

@ -0,0 +1,65 @@
_lsblk_module()
{
local cur prev OPTS
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
case $prev in
'-e'|'--exclude'|'-I'|'--include')
local MAJOR I J
MAJOR=''
for I in /sys/dev/block/*; do
J=${I##*/}
MAJOR="$MAJOR ${J%%:*}"
done
# FIXME: how to append to a string with compgen?
compopt -o nospace
COMPREPLY=( $(compgen -W "$MAJOR" -S ',' -- $cur) )
return 0
;;
'-o'|'--output')
# FIXME: how to append to a string with compgen?
OUTPUT="NAME KNAME MAJ:MIN FSTYPE MOUNTPOINT
LABEL UUID PARTLABEL PARTUUID RA RO RM
MODEL SIZE STATE OWNER GROUP MODE
ALIGNMENT MIN-IO OPT-IO PHY-SEC LOG-SEC
ROTA SCHED RQ-SIZE TYPE DISC-ALN
DISC-GRAN DISC-MAX DISC-ZERO WSAME WWN
RAND PKNAME HCTL TRAN REV VENDOR"
compopt -o nospace
COMPREPLY=( $(compgen -W "$OUTPUT" -S ',' -- $cur) )
return 0
;;
esac
case $cur in
-*)
OPTS="-a --all
-b --bytes
-d --nodeps
-D --discard
-e --exclude
-I --include
-f --fs
-h --help
-i --ascii
-m --perms
-l --list
-n --noheadings
-o --output
-P --pairs
-r --raw
-s --inverse
-t --topology
-S --scsi
-h --help
-V --version"
COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
return 0
;;
esac
local DEVS
DEVS=''; while read dev; do DEVS+="$dev " ; done < <(lsblk -pnro name)
COMPREPLY=( $(compgen -W "$DEVS" -- $cur) )
return 0
}
complete -F _lsblk_module lsblk

43
shell-completion/lslocks Normal file
View File

@ -0,0 +1,43 @@
_lslocks_module()
{
local cur prev OPTS
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
case $prev in
'-p'|'--pid')
local PIDS
# /proc/locks can have 8 to 9 fields, see commit
# 55c0d16bab8cc84b72bf11cb2fdd8aa6205ac608
PIDS="$(awk '{print $(NF-3)}' /proc/locks)"
COMPREPLY=( $(compgen -W "$PIDS" -- $cur) )
return 0
;;
'-o'|'--output')
# FIXME: how to append to a string with compgen?
local OUTPUT
OUTPUT="COMMAND PID TYPE SIZE MODE M START END PATH BLOCKER"
compopt -o nospace
COMPREPLY=( $(compgen -W "$OUTPUT" -S ',' -- $cur) )
return 0
;;
esac
case $cur in
-*)
OPTS="-p --pid
-o --output
-n --noheadings
-r --raw
-u --notruncate
-h --help
-V --version"
COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
return 0
;;
esac
compopt -o filenames
COMPREPLY=( $(compgen -f -- $cur) )
return 0
}
complete -F _lslocks_module lslocks

23
shell-completion/mcookie Normal file
View File

@ -0,0 +1,23 @@
_mcookie_module()
{
local cur prev OPTS
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
case $prev in
'-f'|'--file')
compopt -o filenames
COMPREPLY=( $(compgen -f -- $cur) )
return 0
;;
esac
case $cur in
-*)
OPTS="-f --file -v --verbose -V --version -h --help"
COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
return 0
;;
esac
return 0
}
complete -F _mcookie_module mcookie

17
shell-completion/namei Normal file
View File

@ -0,0 +1,17 @@
_namei_module()
{
local cur prev OPTS
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
case $cur in
-*)
OPTS="-h --help -V --version -x --mountpoints -m --modes -o --owners -l --long -n --nosymlinks -v --vertical"
COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
return 0
;;
esac
compopt -o filenames
COMPREPLY=( $(compgen -f -- $cur) )
return 0
}
complete -F _namei_module namei

27
shell-completion/rename Normal file
View File

@ -0,0 +1,27 @@
_rename_module()
{
local cur prev OPTS
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
case $cur in
-*)
OPTS="-v --verbose -s --symlink -h --help -V --version"
COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
return 0
;;
esac
case $COMP_CWORD in
1)
COMPREPLY=( $(compgen -W "expression" -- $cur) )
;;
2)
COMPREPLY=( $(compgen -W "replacement" -- $cur) )
;;
*)
compopt -o filenames
COMPREPLY=( $(compgen -f -- $cur) )
;;
esac
return 0
}
complete -F _rename_module rename

33
shell-completion/uuidd Normal file
View File

@ -0,0 +1,33 @@
_uuidd_module()
{
local cur prev OPTS
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
case $prev in
'-p'|'--pid'|'-s'|'--socket')
compopt -o filenames
COMPREPLY=( $(compgen -f -- $cur) )
return 0
;;
'-T'|'--timeout')
compopt -o filenames
COMPREPLY=( $(compgen -W "timeout" -- $cur) )
return 0
;;
'-n'|'--uuids')
compopt -o filenames
COMPREPLY=( $(compgen -W "number" -- $cur) )
return 0
;;
esac
case $cur in
-*)
OPTS="-p --pid -s --socket -T --timeout -k --kill -r --random -t --time -n --uuids -P --no-pid -F --no-fork -S --socket-activation -d --debug -q --quiet -V --version -h --help"
COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
return 0
;;
esac
return 0
}
complete -F _uuidd_module uuidd

15
shell-completion/uuidgen Normal file
View File

@ -0,0 +1,15 @@
_uuidgen_module()
{
local cur OPTS
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
case $cur in
-*)
OPTS="-r --random -t --time -V --version -h --help"
COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
return 0
;;
esac
return 0
}
complete -F _uuidgen_module uuidgen

24
shell-completion/whereis Normal file
View File

@ -0,0 +1,24 @@
_whereis_module()
{
local cur prev OPTS
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
case $prev in
'-B'|'-M'|'-S')
compopt -o filenames
COMPREPLY=( $(compgen -o dirnames -- ${cur:-"/"}) )
return 0
;;
esac
case $cur in
-*)
OPTS="-b -B -m -M -s -S -f -u -l"
COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
return 0
;;
esac
COMPREPLY=( $(compgen -W "file" -- $cur) )
return 0
}
complete -F _whereis_module whereis

32
shell-completion/wipefs Normal file
View File

@ -0,0 +1,32 @@
_wipefs_module()
{
local cur prev OPTS
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
case $prev in
'-o'|'--offset')
COMPREPLY=( $(compgen -W "offset" -- $cur) )
return 0
;;
'-t'|'--types')
local TYPES
TYPES="$(blkid -k)"
COMPREPLY=( $(compgen -W "$TYPES" -- $cur) )
return 0
;;
esac
case $cur in
-*)
OPTS="-a --all -f --force -h --help -n --no-actn -o --offset -p --parsable -q --quiet -t --types -V --version"
COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
return 0
;;
esac
local DEVS
DEVS=''; while read dev; do DEVS+="$dev " ; done < <(lsblk -pnro name)
COMPREPLY=( $(compgen -W "$DEVS" -- $cur) )
return 0
}
complete -F _wipefs_module wipefs