2013-03-23 12:41:32 -05:00
|
|
|
_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')
|
2013-09-30 08:49:00 -05:00
|
|
|
local IFS=$'\n'
|
2013-03-23 12:41:32 -05:00
|
|
|
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
|
2014-11-15 14:36:04 -06:00
|
|
|
done < <($1 -rno OPTIONS)
|
2013-04-07 03:12:05 -05:00
|
|
|
COMPREPLY=( $(compgen -W "${!MNT_OPTS[@]}" -- $cur) )
|
2013-03-23 12:41:32 -05:00
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
'-o'|'--output')
|
bash-completion: handle comma-separated options
This solution can become messy when you have too many options listed,
because it repeats all of them. For example, after invoking completion
with this input:
$ partx --output END,SECTORS,SCHEME,START,
You got these completions:
END,SECTORS,SCHEME,START,FLAGS, END,SECTORS,SCHEME,START,NR,
END,SECTORS,SCHEME,START,TYPE,
END,SECTORS,SCHEME,START,NAME, END,SECTORS,SCHEME,START,SIZE,
END,SECTORS,SCHEME,START,UUID,
Nevertheless, it works even with numbers (listed options properly
excluded from completion). Try to invoke completion after
'chcpu --disable ' or 'lsblk --exclude ' to see it in action.
Few issues remained:
* completion interrupts after encountering ':' in listed option,
like in 'MAJ:MIN' in lsblk, losetup.
* lscpu completion is broken: it inserts space after '--extended',
but lscpu assumes there is no space after this option. It also
doesn't complete '--parse' option.
* some completion options are outdated (for example, lscpu MMHZ). We
need to sync them with code. Fix for lscpu follows.
Signed-off-by: Boris Egorov <egorov@linux.com>
2015-06-02 12:59:01 -05:00
|
|
|
local prefix realcur OUTPUT_ALL OUTPUT
|
|
|
|
realcur="${cur##*,}"
|
|
|
|
prefix="${cur%$realcur}"
|
|
|
|
|
|
|
|
OUTPUT_ALL="SOURCE TARGET FSTYPE OPTIONS VFS-OPTIONS
|
2013-03-23 12:41:32 -05:00
|
|
|
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"
|
bash-completion: handle comma-separated options
This solution can become messy when you have too many options listed,
because it repeats all of them. For example, after invoking completion
with this input:
$ partx --output END,SECTORS,SCHEME,START,
You got these completions:
END,SECTORS,SCHEME,START,FLAGS, END,SECTORS,SCHEME,START,NR,
END,SECTORS,SCHEME,START,TYPE,
END,SECTORS,SCHEME,START,NAME, END,SECTORS,SCHEME,START,SIZE,
END,SECTORS,SCHEME,START,UUID,
Nevertheless, it works even with numbers (listed options properly
excluded from completion). Try to invoke completion after
'chcpu --disable ' or 'lsblk --exclude ' to see it in action.
Few issues remained:
* completion interrupts after encountering ':' in listed option,
like in 'MAJ:MIN' in lsblk, losetup.
* lscpu completion is broken: it inserts space after '--extended',
but lscpu assumes there is no space after this option. It also
doesn't complete '--parse' option.
* some completion options are outdated (for example, lscpu MMHZ). We
need to sync them with code. Fix for lscpu follows.
Signed-off-by: Boris Egorov <egorov@linux.com>
2015-06-02 12:59:01 -05:00
|
|
|
|
|
|
|
for WORD in $OUTPUT_ALL; do
|
|
|
|
if ! [[ $prefix == *"$WORD"* ]]; then
|
2017-06-30 17:13:58 -05:00
|
|
|
OUTPUT="$WORD ${OUTPUT:-""}"
|
bash-completion: handle comma-separated options
This solution can become messy when you have too many options listed,
because it repeats all of them. For example, after invoking completion
with this input:
$ partx --output END,SECTORS,SCHEME,START,
You got these completions:
END,SECTORS,SCHEME,START,FLAGS, END,SECTORS,SCHEME,START,NR,
END,SECTORS,SCHEME,START,TYPE,
END,SECTORS,SCHEME,START,NAME, END,SECTORS,SCHEME,START,SIZE,
END,SECTORS,SCHEME,START,UUID,
Nevertheless, it works even with numbers (listed options properly
excluded from completion). Try to invoke completion after
'chcpu --disable ' or 'lsblk --exclude ' to see it in action.
Few issues remained:
* completion interrupts after encountering ':' in listed option,
like in 'MAJ:MIN' in lsblk, losetup.
* lscpu completion is broken: it inserts space after '--extended',
but lscpu assumes there is no space after this option. It also
doesn't complete '--parse' option.
* some completion options are outdated (for example, lscpu MMHZ). We
need to sync them with code. Fix for lscpu follows.
Signed-off-by: Boris Egorov <egorov@linux.com>
2015-06-02 12:59:01 -05:00
|
|
|
fi
|
|
|
|
done
|
2013-03-23 12:41:32 -05:00
|
|
|
compopt -o nospace
|
bash-completion: handle comma-separated options
This solution can become messy when you have too many options listed,
because it repeats all of them. For example, after invoking completion
with this input:
$ partx --output END,SECTORS,SCHEME,START,
You got these completions:
END,SECTORS,SCHEME,START,FLAGS, END,SECTORS,SCHEME,START,NR,
END,SECTORS,SCHEME,START,TYPE,
END,SECTORS,SCHEME,START,NAME, END,SECTORS,SCHEME,START,SIZE,
END,SECTORS,SCHEME,START,UUID,
Nevertheless, it works even with numbers (listed options properly
excluded from completion). Try to invoke completion after
'chcpu --disable ' or 'lsblk --exclude ' to see it in action.
Few issues remained:
* completion interrupts after encountering ':' in listed option,
like in 'MAJ:MIN' in lsblk, losetup.
* lscpu completion is broken: it inserts space after '--extended',
but lscpu assumes there is no space after this option. It also
doesn't complete '--parse' option.
* some completion options are outdated (for example, lscpu MMHZ). We
need to sync them with code. Fix for lscpu follows.
Signed-off-by: Boris Egorov <egorov@linux.com>
2015-06-02 12:59:01 -05:00
|
|
|
COMPREPLY=( $(compgen -P "$prefix" -W "$OUTPUT" -S ',' -- $realcur) )
|
2013-03-23 12:41:32 -05:00
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
'-t'|'--types')
|
|
|
|
local TYPES
|
|
|
|
TYPES="adfs affs autofs cifs coda coherent cramfs
|
2014-07-25 07:55:04 -05:00
|
|
|
debugfs devpts efs ext2 ext3 ext4 hfs
|
2013-03-23 12:41:32 -05:00
|
|
|
hfsplus hpfs iso9660 jfs minix msdos
|
|
|
|
ncpfs nfs nfs4 ntfs proc qnx4 ramfs
|
|
|
|
reiserfs romfs squashfs smbfs sysv tmpfs
|
2014-07-25 07:55:03 -05:00
|
|
|
ubifs udf ufs umsdos usbfs vfat xenix xfs"
|
2013-03-23 12:41:32 -05:00
|
|
|
COMPREPLY=( $(compgen -W "$TYPES" -- $cur) )
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
'-S'|'--source')
|
|
|
|
local DEV_MPOINT
|
2014-11-15 14:36:04 -06:00
|
|
|
DEV_MPOINT=$($1 -rno SOURCE | grep ^/dev)
|
2013-03-23 12:41:32 -05:00
|
|
|
COMPREPLY=( $(compgen -W "$DEV_MPOINT" -- $cur) )
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
'-T'|'--target')
|
|
|
|
local DEV_MPOINT
|
2014-11-15 14:36:04 -06:00
|
|
|
DEV_MPOINT=$($1 -rno TARGET)
|
2013-03-23 12:41:32 -05:00
|
|
|
COMPREPLY=( $(compgen -W "$DEV_MPOINT" -- $cur) )
|
|
|
|
return 0
|
|
|
|
;;
|
2015-08-02 15:24:08 -05:00
|
|
|
'-M'|'--mountpoint')
|
|
|
|
local IFS=$'\n'
|
|
|
|
compopt -o filenames
|
2015-10-02 04:38:56 -05:00
|
|
|
COMPREPLY=( $(compgen -o dirnames -- ${cur:-"/"}) )
|
2015-08-02 15:24:08 -05:00
|
|
|
return 0
|
|
|
|
;;
|
2013-04-07 03:12:04 -05:00
|
|
|
'-h'|'--help'|'-V'|'--version')
|
|
|
|
return 0
|
|
|
|
;;
|
2013-03-23 12:41:32 -05:00
|
|
|
esac
|
|
|
|
case $cur in
|
|
|
|
-*)
|
2013-04-07 03:12:08 -05:00
|
|
|
OPTS="--fstab
|
|
|
|
--mtab
|
|
|
|
--kernel
|
|
|
|
--poll
|
|
|
|
--timeout
|
|
|
|
--all
|
|
|
|
--ascii
|
|
|
|
--canonicalize
|
|
|
|
--df
|
|
|
|
--direction
|
|
|
|
--evaluate
|
|
|
|
--tab-file
|
|
|
|
--first-only
|
|
|
|
--invert
|
2015-08-02 15:24:08 -05:00
|
|
|
--json
|
2013-04-07 03:12:08 -05:00
|
|
|
--list
|
|
|
|
--task
|
|
|
|
--noheadings
|
|
|
|
--notruncate
|
|
|
|
--options
|
|
|
|
--output
|
2018-04-23 15:02:44 -05:00
|
|
|
--output-all
|
2013-04-07 03:12:08 -05:00
|
|
|
--pairs
|
|
|
|
--raw
|
|
|
|
--types
|
|
|
|
--nofsroot
|
|
|
|
--submounts
|
|
|
|
--source
|
|
|
|
--target
|
2015-08-02 15:24:08 -05:00
|
|
|
--mountpoint
|
2013-04-07 03:12:08 -05:00
|
|
|
--help
|
2016-12-08 07:24:41 -06:00
|
|
|
--tree
|
2018-05-11 03:50:19 -05:00
|
|
|
--real
|
|
|
|
--pseudo
|
2013-04-07 03:12:08 -05:00
|
|
|
--version"
|
2013-03-23 12:41:32 -05:00
|
|
|
COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
local DEV_MPOINT
|
2014-11-15 14:36:04 -06:00
|
|
|
DEV_MPOINT=$($1 -rno TARGET,SOURCE)
|
2013-03-23 12:41:32 -05:00
|
|
|
COMPREPLY=( $(compgen -W "$DEV_MPOINT" -- $cur) )
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
complete -F _findmnt_module findmnt
|