Commit graph

87 commits

Author SHA1 Message Date
Ronan Pigott 2cbda74862 zsh: reintroduce pattern argument to uncached verbs
The systemctl completion previously made use of PREFIX as a pattern
argument to list-unit-files and list-units. This had the problem of
erroneously filtering the results that were stored in the cache, and
erroneously filtering results that might have been requested according
to the users configuration (e.g. _correct completer, certain
matcher-lists or tag-orders, etc.).

Unfortunately, the runtime of list-unit-files increases when no pattern
argument is provided, and systemctl show, used to filter those units,
can become unacceptably slow when provided with too many units to
describe.

Let's re-introduce the pattern argument to list-unit-files and
list-units where necessary in order to alleviate these bottlenecks
without poisining the cache. A 'use-pattern' style is introduced that
may be used to disable this behavior if it is undesired. We can still
expect that certain completions, like `systemctl start <TAB>` will be
slow, like before. To fix this we will need systemd to learn a more
efficient way of filtering the units than parsing systemctl show.
2023-08-08 01:57:45 -07:00
Ronan Pigott c8e2cd79c1 zsh: use sys_really_all_units for non-template names
The systemctl invocations used for these completions match the ones used
for the _sys_really_all_units parameter, so we should really just use
the cached parameter rather than recomputing the result.
2023-08-07 18:00:04 -07:00
Luca Boccassi b0d3095fd6 Drop split-usr and unmerged-usr support
As previously announced, execute order 66:

https://lists.freedesktop.org/archives/systemd-devel/2022-September/048352.html

The meson options split-usr, rootlibdir and rootprefix become no-ops
that print a warning if they are set to anything other than the
default values. We can remove them in a future release.
2023-07-28 19:34:03 +01:00
Ronan Pigott 9ec0808370 zsh: use glob matching for template names
Template names can be learned from the filesystem, so there isn't a need
to parse the output of systemctl list-unit-files in this case. This
should accelerate the completion of some verbs like enable.
2023-07-19 15:07:39 -07:00
Ronan Pigott ae6fb82cd9 zsh: remove unit property caching
The existing caching policy isn't very sensible for this cache. We could
write a different policy, but I don't think there is much value in
caching these values, as in my experience the command used to generate
them is quick.
2023-07-19 14:27:45 -07:00
Ronan Pigott 110ba0ccf9 zsh: update default caching policy for units
The existing caching policy was completely bogus.

In the first stanza, despite the comment, the pattern given would
consider the cache invalid if it was more than 1 hour old.

The second stanza was also incorrect, since the output of `systemctl
--all` is not unit file paths, but unit names. When they were being
tested against the cachefile mtime, the test would always fail becuase
of the nonexistant file (hopefully).

In fact it's not very useful to test if the unit files have newer mtime
in this case anyway, since we are only caching their names. Also,
`systemctl --all` is an unfortunately slow operation to be used in
testing for the cache validity — we want this operation to at least be
faster than rebuilding the cache.

I've rewritten this stanza with my best guess at its original intent. It
now checks against the mtime of the parent directories in the search
path, which should be updated and cause the cache to rebuild when we
add, remove, or rename any unit files.
2023-07-19 14:27:45 -07:00
Ronan Pigott 8a8caeccb2 zsh: stop forcing unit file cache rebuilds
Rebuilding whenever the cached parameter is not set forces each new
shell to rebuild the cache, which often defeates the purpose of caching
in the first place.
2023-07-17 16:38:25 -07:00
Ronan Pigott 087f777a1c zsh: default to system manager when not specified
This used to work correctly, before the change was reverted in
e09d0d46c2. In fact it is important to specify the manager explicity
in the completion because the argument is reused in the caching
policies. An empty argument here caused the completion to create
separate caches with and without the --system parameter. We can simplify
the given pattern a little here too.
2023-07-17 16:35:29 -07:00
Ronan Pigott d0fc94a192 zsh: suppress aliases and shell functions when calling systemctl
This prevents any errors in case the user had aliased some arguments
following systemctl.
2023-07-17 16:20:03 -07:00
Ronan Pigott 3b4c6009c0 zsh: typo in systemctl completions 2023-07-17 16:08:58 -07:00
Christian Hesse 6864f9b9e9 shell-completion/zsh/systemctl: add whoami
Make zsh shell-completion aware of whoami.
2023-07-07 14:02:41 +02:00
Christian Hesse 050d6d711a shell-completion/zsh/systemctl: add soft-reboot
Make zsh shell-completion aware of soft-reboot.
2023-07-07 13:57:03 +02:00
Ronan Pigott b3d12ac0da zsh: add service-log-{level,target} completions for systemctl 2023-05-08 01:08:36 +01:00
Ronan Pigott 8139407ec1 zsh: remove usage of PREFIX in _systemctl
The usage of PREFIX in this completion is mostly counter to the intended
usage of compsys in zsh. It is generally expected that completion code
provide the available completions and tags in that word position so that
compsys, with user configuration, can filter them to the appropriate set.

One egregious error caused by the usage of PREFIX here is the caching of
SYS_ALL_UNITS, which stored only the unit names prematurely filtered by
the completion prefix, affecting all future completions. For example,

  $ systemctl cat nonsense<TAB>

might find no matching units if nonsense* has no matches, but now

  $ systemctl cat <TAB>

will fail in all future completions even though every unit file
is a valid match, because the cached set has been erroneously filtered
by the last prefix.
2023-05-05 22:12:50 +01:00
David Tardon 7336968488 shell-completion: add systemctl list-paths 2023-02-21 19:03:26 +01:00
Yu Watanabe 93b0ec8bc5 shell-completion: systemctl: add --no-warn 2023-01-12 11:51:19 +09:00
Yu Watanabe c4c9714464 shell-completion: drop unused $mode
Fixes #24473.
2022-08-28 08:11:26 +00:00
Zbigniew Jędrzejewski-Szmek 4ccde410a3 tree-wide: change --kill-who to --kill-whom
getopt allows non-ambiguous abbreviations, so backwards-compat is maintained, and
people can use --kill-who (or even shorter abbreviations). English is flexible,
so in common speach people would use both forms, even if "whom" is technically
more correct. The advantage of using the longer form in the code is that we
effectively allow both forms, so we stop punishing people who DTGCT¹, but still
allow people to use the spoken form if they prefer.

1. Do the gramatically correct thing
2022-08-26 11:15:44 +09:00
David Tardon 5edea3b77e shell-completion: add systemctl list-automounts 2022-07-25 13:37:20 +02:00
Eric Cook 682e043c42 shell-completion: revert c1072f6473
fixing https://github.com/systemd/systemd/issues/19689
2021-06-17 14:42:46 +02:00
nerdopolis 3c3335c714 Clarify help information for --global 2021-06-10 07:23:05 +02:00
Zbigniew Jędrzejewski-Szmek 5908656c57 meson: use jinja2 in shell-completion/ 2021-05-19 10:25:26 +09:00
Zbigniew Jędrzejewski-Szmek d60bd2ffb7 shell-completion: complete --legend=no for resolvectl and systemctl
I don't think it makes sense to complete --legend=yes. It is the default, and
it would be only used very rarely (and then it is easy enough to just remove
the '=no' part from the suggested string).
2021-02-17 21:09:14 +01:00
Luca Boccassi 6faecbd353 systemctl: add new option to mount image inside a running service namespace
Use the new DBUS method and follow the same pattern as the
systemctl bind command.
2021-01-21 19:08:40 +00:00
Luca Boccassi 5e8deb94c6 core: add DBUS method to bind mount new nodes without service restart
Allow to setup new bind mounts for a service at runtime (via either
DBUS or a new 'systemctl bind' verb) with a new helper that forks into
the unit's mount namespace.
Add a new integration test to cover this.

Useful for zero-downtime addition to services that are running inside
mount namespaces, especially when using RootImage/RootDirectory.

If a service runs with a read-only root, a tmpfs is added on /run
to ensure we can create the airlock directory for incoming mounts
under /run/host/incoming.
2021-01-18 17:24:05 +00:00
Felix Stupp 4327574fc1 Added option --check-inhibitors for non-tty usage
As described in #2680, systemctl did ignore inhibitors if it is not
attached to a tty to allow scripts to ignore inhibitors automatically.
This pull request preserves this behavior but allows scripts to
explicit check inhibitors if required.

The new parameter '--check-inhibitors=yes' enables this feature.
The old parameter '-i'/'--ignore-inhibitors' was deprecated in favor
of '--check-inhibitors=no', the default behaviour can be specified
with '--check-inhibitors=auto'.
The new parameter is also described in the documentations and shell
completions found here.
2021-01-13 16:07:36 +01:00
Zbigniew Jędrzejewski-Szmek 341992081b shell-completion: fix systemctl set/unset/import-environment
unset-environment is completed with variable names in the environment block.
set-environment the same, but suffixed with "=".
import-environment is completed with variable names in the client environment.
2021-01-08 20:01:40 +01:00
Yu Watanabe db9ecf0501 license: LGPL-2.1+ -> LGPL-2.1-or-later 2020-11-09 13:23:58 +09:00
Luca Boccassi 46ad9c5378 systemctl: add --timestamp to change timestamp print format
Timestamps for unit start/stop are recorded with microsecond granularity,
but status and show truncate to second granularity by default.
Add a --timestamp=pretty|us|utc option to allow including the microseconds
or to use the UTC TZ to all timestamps printed by systemctl.
2020-08-19 15:30:13 +01:00
Haochen Tong f5b3be308d zsh: fix disable/enable completion
The "preset" column introduced in
b01c1f305c breaks zsh completion for
systemctl disable/enable. Fix by ignoring everything after the last
space in a line.
2020-04-27 08:12:27 +02:00
Jouke Witteveen 1cabd2d0c5 systemctl: hide first column with --plain instead of --no-legend
Hiding the first column, which may contain bullet circles, with --no-legend
is undocumented and potentially unexpected. On the other hand, not printing
bullet circles with --plain is documented so hiding the column with that
switch is sensible.

The combination "--full --no-legend --no-pager --plain" is appropriate for
automated processing of systemctl output.
2020-04-17 19:15:49 +02:00
Daniel Shahaf 356873ddec zsh: Complete systemctl subcommands in separate tags
Fixes #14422
2020-01-08 09:43:01 +01:00
Daniel Shahaf fa7ea86510 zsh: Prepare for classifying systemctl commands (#14422) 2019-12-23 17:17:31 +00:00
Daniel Shahaf 1d8385b415 zsh: Complete more systemctl commands
The completion is now synced with the manual.
2019-12-23 16:49:51 +00:00
Daniel Shahaf 51a3b72634 zsh: Group systemctl subcommands as in the manual. No functional change. 2019-12-23 16:44:28 +00:00
Zbigniew Jędrzejewski-Szmek c4e7664d24 zsh: add completion for systemctl preset-all 2019-06-12 17:27:19 +02:00
Zbigniew Jędrzejewski-Szmek c1072f6473 shell-completion/zsh: add -*type*- headers
Since there's no file extension, emacs and other editors do not know that this is
supposed to be in shell syntax.
2019-04-12 08:36:18 +02:00
Zbigniew Jędrzejewski-Szmek 843cfcb15c shell-completion: use 4 space indentation too
The same as in other places, indentation levels were all over the place.
2019-04-12 08:34:44 +02:00
dana c501ecd70c zsh completion: Prevent functions from clobbering each other, &c.
- Don't redefine helpers on every call
- Prefix helper names with main function name
- Adjust some helper names for consistency and convention adherance
2019-01-08 15:23:37 +01:00
Xuanwo c4a2deba7e zsh-completion: Add support for set-property (#10322) 2018-11-20 13:17:11 +09:00
Emil Velikov 4ed141166c zsh-completion: systemctl: list template units only as needed
Currently the completion adds template units for commands such as
is-active, is-failed, is-enabled, status, show and others.

At the same time systemctl barfs at us, since an instanced template unit
is needed. Follow the example list from bash-completion as to which
commands should not list template units.

Note: The above is observed regardless of DefaultInstance.

Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
2018-06-11 19:02:36 +01:00
Emil Velikov 9b536b1af2 shell-completion: systemctl: do not list template units in {re,}start
Template units lacking DefaultInstance cannot be enabled/disabled or
started/restarted.

By adding DefaultInstance the unit can be enabled/disabled but it
still cannot be started/restarted.

Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
2018-06-11 17:15:12 +01:00
Emil Velikov 98476dc8b2 shell-completion: systemctl: pass current word to all list_unit*
Earlier patch added the current word to the performance critical paths.
Here we add it to every place, for consistency sake.

Suggested-by: Yu Watanabe (yuwata)
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
2018-06-11 17:09:58 +01:00
Emil Velikov 8a6236e51a zsh-completion: systemctl: tweak --state list for startable units
This effectively ports over b1bdb6496c
from the bash completion to zsh.

Modulo the new function, since it's unrelated perf. improvement.

Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
2018-06-11 17:09:56 +01:00
Emil Velikov ff728637cc zsh-completion: systemctl: pass only $PREFIX* to list-unit*
Using a leading * and $SUFFIX produces misleading results. Let's imagine
that one mistypes nect instead of netc, they will get a rather
misleading completion like:  sys-fs-fuse-connections.mount

Not to mention that the execution time is up by ~1/3.
time systemctl list-unit-files netctl* -> ~12ms
time systemctl list-unit-files *netctl* -> ~17ms

Furthermore more units are matched, leading to greater execution time
of `systemctl show' in _filter_units_by_property

Use only $PREFIX*, removing the leading * and trailing $SUFFIX*.

Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
2018-06-11 17:09:56 +01:00
Zbigniew Jędrzejewski-Szmek dd74faef7a zsh-completion: suggest bus properties instead of configuration items for 'systemctl -p' 2018-05-28 18:14:49 +09:00
Mario Limonciello e68c79db91 Rename suspend-to-hibernate to suspend-then-hibernate
Per some discussion with Gnome folks, they would prefer this name
as it's more descriptive of what's happening.
2018-03-28 15:11:10 -05:00
Mario Limonciello c58493c00a Introduce suspend-to-hibernate (#8274)
Suspend to Hibernate is a new sleep method that invokes suspend
for a predefined period of time before automatically waking up
and hibernating the system.

It's similar to HybridSleep however there isn't a performance
impact on every suspend cycle.

It's intended to use with systems that may have a higher power
drain in their supported suspend states to prevent battery and
data loss over an extended suspend cycle.

Signed-off-by: Mario Limonciello <mario.limonciello@dell.com>
2018-03-08 14:17:33 +01:00
dana 992f51ea42 Slightly improve performance of startable/restartable unit completion (#7839) 2018-01-28 13:29:58 +01:00
Zbigniew Jędrzejewski-Szmek 7059062c2f Add SPDX license headers to shell completion scripts 2017-11-19 19:08:15 +01:00