]> git.ipfire.org Git - thirdparty/util-linux.git/commit
bash-completion: Add non-canonical device fallback
authorKevin Locke <kevin@kevinlocke.name>
Thu, 19 Sep 2019 13:45:54 +0000 (07:45 -0600)
committerKevin Locke <kevin@kevinlocke.name>
Thu, 19 Sep 2019 14:17:09 +0000 (08:17 -0600)
commit0c8865f843c1a9552a13a51bcb4c4c31a4e1242d
treeffa342f06429e8e538f4b297c28de5b0a912980f
parent6ead91ce1e8431bec5b6f10c37b54a82f0be078a
bash-completion: Add non-canonical device fallback

It is desirable for bash-completion to complete block devices via
symlinks (e.g. under /dev/disk) and with non-canonical locations (e.g.
./sda if $PWD is /dev, and /chroot/dev/sda).

Unfortunately, this is a non-trivial task due to how bash-completion
works.  It is necessary to un-escape the last partial argument, search,
then escape the results, ideally handling tilde and variable
expansion/completion.  See [_get_comp_words_by_ref] and [_filedir] in
the bash-completion project for details.

Given the development costs of a complete and correct implementation,
the annoyance/frustration which would result from an incomplete/buggy
implementation, and the trade-offs between under- and over-completion,
this commit adds fallback to bash default completion if the argument
does not match any canonical device names.  This correctly completes in
the cases mentioned above, although it incorrectly completes on
non-block-device files as well.

[_filedir]: https://github.com/scop/bash-completion/blob/2.9/bash_completion#L552
[_get_comp_words_by_ref]: https://github.com/scop/bash-completion/blob/2.9/bash_completion#L365

Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
bash-completion/addpart
bash-completion/blkdiscard
bash-completion/blkid
bash-completion/blkzone
bash-completion/blockdev
bash-completion/delpart
bash-completion/eject
bash-completion/lsblk
bash-completion/resizepart