Commit Graph

137 Commits

Author SHA1 Message Date
Kevin Locke 0c8865f843 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>
2019-09-19 08:17:09 -06:00
Kevin Locke 6ead91ce1e bash-completion: Add fallback for symlinks/images
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>
2019-09-19 08:16:32 -06:00
Kevin Locke 559888c873 bash-completion: Standardize fsck/mkfs file/device
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>
2019-09-19 07:27:31 -06:00
Sami Kerola e79f20f57d
bash-completion: update options
unshare: cef4decf04 --keep-caps
dmesg:   646bba41fd --noescape

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2019-09-12 19:49:51 +01:00
Karel Zak a1790d265d bash-completion: (unshare) add --map-current-user
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-09-09 12:58:03 +02:00
Karel Zak 646bba41fd dmesg: add --noescape
We have no way how to print the kernel message buffer in really raw
way. The new option --noescape disables all \x<hex> translations.

Addresses: https://github.com/karelzak/util-linux/issues/858
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-09-09 12:56:53 +02:00
Sami Kerola 6d56251220
mountpoint: add --nofollow option
The no follow option will allow user to distinct mount points from symbolic
links pointing to them.  Arguably this is pretty pedantic option, mounting a
device or bind mount to a directory via symlink does not have or cause any
issues.

Addresses: https://github.com/karelzak/util-linux/issues/832
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2019-08-02 19:39:05 +01:00
Sami Kerola 2e56aa3c3b
bash-completion: add hardlink completion
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2019-05-20 19:56:19 +01:00
Sami Kerola ba5e7b7e52
bash-completion: update options before release
blkid: 5e91d5dd71 --no-part-details
lsblk: dc4662f0e7 --dedup
lsblk: 0bd05f5ee4 --merge
lscpu: 0e86bc8406 --caches
lscpu: 2011528bce --bytes

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2019-05-20 19:43:59 +01:00
Karel Zak 0d71a25998 bash-completion: add fstrim --quiet
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-09 13:16:03 +02:00
Sami Kerola 3ebfc8d370
bash-completion: umount support relative path and ~ as home shorthands
Addresses: https://github.com/karelzak/util-linux/issues/703
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2019-01-12 19:29:37 +00:00
Laurent Vivier f0af42b517 unshare: allow to set user ID and group ID
This patch introduces two new parameters to set the
user ID and the group ID of the program to be executed.
Setting group ID also drops supplementary groups.

The option names used are the same as for nsenter,
-S, --setuid and -G, --setgid.

Signed-off-by: Laurent Vivier <laurent@vivier.eu>
2018-11-12 11:52:15 +01:00
Laurent Vivier bf8834d4f4 unshare: allow to set a new root
This patch instroduces two new parameters to set the new
root and the new working directory in this new root.

This allows to combine "unshare chroot" in one command,
and doing like this the /proc filesystem is correctly
mounted in the new root with "--mount-proc".

The new parameters are -R, --root and -w, --wd. The names
are the same as for nsenter, except for "-r" that is already
used by "--map-root-user" and replaced by "-R".

Signed-off-by: Laurent Vivier <laurent@vivier.eu>
2018-11-12 11:52:14 +01:00
Karel Zak d482a0bd5c bash-completion: cleanup mount and umount --namespace
* use only PATHs rather than PIDs to namespaces

* add --namespace to umount too

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-10-05 11:48:04 +02:00
Sami Kerola 5feae697b0
bash-completion: catch up with option changes
Check what has changed in usage functions in between v2.32..a77bd80d5 and
update bash-completion files accordingly.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2018-10-04 21:36:22 +01:00
Karel Zak 82bbc77bfc bash-completion: update column
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-08-23 14:14:29 +02:00
Sami Kerola faa44b6d9a bash-completion: add swapon specifiers to completion
No space after device name is not entirely right, but that's better than
missing argument completions.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2018-05-28 13:36:38 +02:00
Fred Mora aefe989338 script: add the -o/--output-limit option. Fix race test.
When script is used on a host with a relatively small free disk space, it
is sometimes desirable to limit the size of the captured output. This
can now be enforced with the --output-limit option.

The --output-limit option lets the user specify a maximum size. The program
uses the size parsing from strutils and thus supports the usual
multiplicative suffixes (kiB, KB, MiB, MB, etc.). After the specified
number of bytes have been written to the output file, the script program
will terminate the child process.

Due to buffering, the size of the output file might exceed the specified
limit. This limit also does not include the start and done messages.

The race test was throwing an error dur to a variable being "" in some cases.
Quoting the variable in the equal test took care of that test.

[kzak@redhat.com: - use done() to stop script
                  - count also timing file
                  - remove unnamed member initialization in ctl struct
                  - add to bash-completion]

Signed-off-by: Fred Mora <fmora@datto.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-05-14 11:32:23 +02:00
Karel Zak 4c9afd6e53 bash-completion: add findmnt --real --pseudo
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-05-11 10:50:19 +02:00
Sami Kerola 2e7ccec7bb
zramctl: add --output-all option
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2018-05-03 19:56:21 +01:00
Sami Kerola b5b43f276e
swapon: add --output-all option
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2018-05-03 19:56:21 +01:00
Sami Kerola 4dfd172dd8
rfkill: add --output-all option
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2018-05-03 19:56:21 +01:00
Sami Kerola ba1c9075f4
partx: add --output-all option
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2018-05-03 19:56:21 +01:00
Sami Kerola 1f7b62e0b2
lsns: add --output-all option
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2018-05-03 19:56:21 +01:00
Sami Kerola fcd4bbff87
lsmem: add --output-all option
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2018-05-03 19:56:20 +01:00
Sami Kerola 2ab432effb
lslogins: add --output-all option
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2018-05-03 19:56:20 +01:00
Sami Kerola 25d3c40534
lslocks: add --output-all option
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2018-05-03 19:56:20 +01:00
Sami Kerola fbf0619b2b
lscpu: add --output-all option
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2018-05-03 19:56:20 +01:00
Sami Kerola 289673b1c0
losetup: add --output-all option
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2018-05-03 19:56:20 +01:00
Sami Kerola 00147883de
findmnt: add --output-all option
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2018-05-03 19:56:20 +01:00
Karel Zak 8fa223daba choom: new command to adjust OOM-killer score value
Let's provide command line tool, man page with OOM description and
bash-completion. It seems better than force end-users to use "echo"
to /proc.

Addresses: https://github.com/karelzak/util-linux/issues/609
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-04-16 12:53:39 +02:00
Sami Kerola 27ea4deb93 bash-completion: fix typo in blockdev file
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2018-04-06 13:03:38 +02:00
Sami Kerola ecfb5b267c bash-completion: setpriv --securebits argument can be comma separated list
Make the option argument suggestion to match with what is allowed.  In same
go tidy shell code a little bit.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2018-04-06 13:03:38 +02:00
Sami Kerola fda59a8d19 bash-completion: do not print eject --cdspeed error messages
Bash completion is proposing --cdspeed option argument from 'eject
--listspeed /dev/cdrom' output.  Nowadays it is common not to have such
device, and this results to an unwanted error message to stderr merely
messing up command line.  Lets stop that.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2018-04-06 13:03:38 +02:00
Sami Kerola c6f0bdfecc bash-completion: fix few bash set -u issues
This is the same fix as in reference commit, and the same reason.  Just
correct few files missed earlier.

Reference: abbcec4fc9
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2018-04-06 13:03:38 +02:00
Sami Kerola c50ad32410 bash-completion: update zramctl algorithms list
Reference: a3612b81fe.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2018-03-02 09:52:23 +01:00
Karel Zak 75f03badd7 bash-completion: (umount) use findmnt, escape a space in paths
# mount /dev/sdc1 /mnt/test/foo\ bar
 # umount <tab>

has to return "/mnt/test/foo\ bar".

Changes:

 * don't use mount | awk output, we have findmnt
 * force compgen use \n as entries separator

Addresses: https://github.com/karelzak/util-linux/issues/539
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-11-16 16:27:32 +01:00
Kevin Locke d22c1f5332 bash-completion: Exclude /dev/fd from fsck find
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>
2017-10-30 14:12:55 -06:00
Karel Zak c5910c7f27 Merge branch 'kill-child-feature' of https://github.com/nh2/util-linux
* 'kill-child-feature' of https://github.com/nh2/util-linux:
  unshare: Allow passing <signame> to --kill-child
  unshare: Add --kill-child option.
  signames: Make input char buffers const
  kill: Extract signal names into signames.h/signames.c
2017-10-23 12:58:21 +02:00
Andre Wild afee3f2042 lsmem/chmem: add memory zone awareness to bash-completion
This patch extends the valid --output values with ZONES for the
lsmem bash-completion, and adds the --zone option for the chmem
bash-completion.

Signed-off-by: Andre Wild <wild@linux.vnet.ibm.com>
Signed-off-by: Gerald Schaefer <gerald.schaefer@de.ibm.com>
2017-10-20 12:37:04 +02:00
Niklas Hambüchen 8e8f0fa59a unshare: Add --kill-child option.
This allows to conveniently kill the entire process tree
below the forked program, a common problem when scripting
tasks that need to reliably fully terminate without leaving
reparented subprocesses behind.

The example added to the man page shows the most common use.

Implemented using prctl(PR_SET_PDEATHSIG, ...).
2017-10-14 04:46:13 +02:00
Sami Kerola 37a6cc7a14 bash-completion: update uuidgen, wipefs, tunelp, setpriv, and hwclock
uuidgen: Add hash-based UUIDs to bash-completion.  These were added in
commit c6f1ec68a8.

wipefs: Command started to use libsmartcols, and it got some new options.
Commit d9921b2a12.

rename: New option was added in commit fabb90676a.

tunelp: The --trust-irq was removed it being years broken.  Commit
d52eb4bd90.

setpriv: Add --ambient-caps option from commit 0c92194eee.
In same go fix 'bash set -u' issue, that is the same as mentioned commit
abbcec4fc9.

hwclock: For some reason --get has always been missing from this file.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-09-18 11:04:52 +02:00
Sami Kerola 9bf5e08fd3
rfkill: add bash-completion file
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-08-30 20:32:49 +01:00
Sami Kerola 75c5f4a516 bash-completion: simplify pid listing
Changing directory in subshell does not effect parent process, so this is
better and possibly quicker way to list pids.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-08-30 11:21:57 +02:00
Sami Kerola 09ad914e72
bash-completion: look for look completions
The look(1) uses positional arguments, where first one is a word from
dictionary.  It is reasonable to assume most of the time people search from
system word lists so propose completions from there.  The second argument is
a dictionary file, that might invalidate the first input but that only
happens to users who have an idea what the want without bash-completion.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-08-05 09:58:25 +01:00
Sami Kerola abbcec4fc9
bash-completion: make completions to work when bash set -u is in use
User who want to avoid refering to none-existing variables got earlier the
following error.

$ set -u
$ findmnt --output <tab>bash: OUTPUT: unbound variable

Here is short explanation of this setting.

$ help set
 -u  Treat unset variables as an error when substituting.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-07-15 22:05:42 +01:00
Sami Kerola 5d70066c1a
uuidparse: add bash-completion file
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-07-15 22:05:00 +01:00
Sami Kerola 2cdaf94b55
partx: add --list-types option
Use libblkid as the source of truth what partition type names exist, and are
supported.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-05-02 23:22:04 +01:00
Sami Kerola 15a74f755a
blkid: add long options
This change attempts to make tab completion more reasonable by alloging
memorizable option names.  That also has positive impact to manual page, in
which referrals to other options are now easier to understand.

All short options are kept exactly as they were to avoid ABI breakage.  The
only exception is -f option that getopt(3) recognized, but was not found
from anywhere else.  The -f has been part of blkid since the initial commit.

Commit: 51410fc6de
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-05-02 23:22:04 +01:00
Sami Kerola 768f315230
bash-completion: update text-utils
hexdump:

	Add --color option.

	Commit: 098ab0778f

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-04-17 18:40:34 +01:00