For commands which support operating on files (i.e. disk images), it is
desirable for bash-completion to complete matching file names. It is
also desirable to complete on block device symlinks (e.g. under
/dev/disk). To complete common use cases, often on canonical device
names, continue to try completion using canonical device names, then
fall back to matching any file incrementally as Bash does by default.[1]
[1]: https://github.com/karelzak/util-linux/issues/842#issuecomment-523450243
Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
Some of the fsck and mkfs commands complete differently than the others,
and differently than the desired behavior.[1] Standardize on completing
with $(lsblk -pnro name):
* fsck: Don't complete completes on all block devices and device links
under /dev immediately (which is excessive and prone to search
problems).
* mkfs, mkfs.bfs: Don't complete "/path/to/file" literally. I assume
this was copy/pasted from example code, since it does not appear to be
a valid argument unless it is a valid path, which is rare.
* fsck.cramfs, mkfs, mkfs.bfs, mkfs.cramfs, mkswap: Don't complete on
all filenames initially. The desired behavior is to complete
filenames only if there are no canonical matches.[1]
Note: A subsequent commit will add the desired fallback behavior.
[1]: https://github.com/karelzak/util-linux/issues/842#issuecomment-523450243
Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
When the bash-completion for fsck runs `find -L /dev/ -type b` it
descends into /dev/fd after opening '.' as file descriptor 3. This
causes find to search through /dev/fd/3/ which includes everything below
the current directory, which can take a very long time.
To avoid this, prune /dev/fd in the find expression.
Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
Various commands such as blkid, cfdisk, fdisk, delpart, and so on listed
only partitions and missed for example disks and volume groups. The
right thing to do is to list all block devices in all for all commands
performing operations with them. This might occasionally list unexpected
devices that I think is lesser bad than missing some.
Addresses: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=764488
Signed-off-by: Sami Kerola <kerolasa@iki.fi>